new format

This commit is contained in:
James 2024-04-27 11:25:27 +01:00
parent 7a78f3bddb
commit 0991797503
3 changed files with 25 additions and 52 deletions

View File

@ -21,10 +21,10 @@ char currentName[128];
bool gotBasicInfo;
bool gotCellInfo;
void loop() {
Serial.printf("\r\n\r\n===============================\r\n\r\n");
delay(1000);
Serial.println("Scanning...");
BLEScan* pBLEScan = BLEDevice::getScan(); // Create new scan
@ -133,6 +133,10 @@ void loop() {
std::__cxx11::string deviceName = advertisedDevice.getName();
strncpy(currentName, deviceName.c_str(), sizeof(currentName) - 1);
currentName[sizeof(currentName) - 1] = '\0'; // Ensure null-termination
// Convert to lowercase and replace spaces with dots
for (char* p = currentName; *p; ++p) {
*p = *p == ' ' ? '.' : tolower(*p);
}
unsigned long start=millis();
while( millis()-start<10000 && (gotBasicInfo==false || gotCellInfo==false) ){
@ -144,7 +148,6 @@ void loop() {
// DD A5 03 00 FF FD 77
uint8_t a_data[7] = {0xdd, 0xa5, 3, 0x0, 0xff, 0xfd, 0x77};
pRemoteCharacteristic_tx->writeValue(a_data, sizeof(a_data), false);
delay(500);
}
// REQUEST CELL INFO
@ -155,7 +158,6 @@ void loop() {
// DD A5 03 00 FF FD 77
uint8_t b_data[7] = {0xdd, 0xa5, 4, 0x0, 0xff, 0xfc, 0x77};
pRemoteCharacteristic_tx->writeValue(b_data, sizeof(b_data), false);
delay(500);
}
}
pClient->disconnect();
@ -315,23 +317,14 @@ bool processBasicInfo(byte *data, unsigned int dataLen){
uint16_t BalanceCodeHigh = (two_ints_into16(data[14], data[15]));
uint8_t MosfetStatus = ((byte)data[20]);
Serial.printf("%s Voltage: %f\r\n",currentName, (float)Volts / 1000);
Serial.printf("%s Amps: %f\r\n",currentName, (float)Amps / 1000);
Serial.printf("%s Watts: %f\r\n",currentName, (float)Watts);
Serial.printf("%s Capacity Remain Ah: %f\r\n",currentName, (float)CapacityRemainAh / 1000);
Serial.printf("%s Capacity Remain Wh: %f\r\n",currentName, ((float)(CapacityRemainAh) / 1000) * ((float)(Volts) / 1000));
Serial.printf("%s Capacity Remain Percent: %d\r\n",currentName, CapacityRemainPercent);
Serial.printf("%s Temp1: %f\r\n",currentName, (float)Temp1 / 10);
Serial.printf("%s Temp2: %f\r\n",currentName, (float)Temp2 / 10);
Serial.printf(">>>%s.voltage: %f\r\n",currentName, (float)Volts / 1000);
Serial.printf(">>>%s.amps: %f\r\n",currentName, (float)Amps / 1000);
Serial.printf(">>>%s.watts: %f\r\n",currentName, (float)Watts);
Serial.printf(">>>%s.capacity_remain_ah: %f\r\n",currentName, (float)CapacityRemainAh / 1000);
Serial.printf(">>>%s.capacity_remain_wh: %f\r\n",currentName, ((float)(CapacityRemainAh) / 1000) * ((float)(Volts) / 1000));
Serial.printf(">>>%s.capacity_remain_percent: %d\r\n",currentName, CapacityRemainPercent);
Serial.printf(">>>%s.temp1: %f\r\n",currentName, (float)Temp1 / 10);
Serial.printf(">>>%s.temp2: %f\r\n",currentName, (float)Temp2 / 10);
Serial.printf(">>>%s.voltage %f\r\n",currentName, (float)Volts / 1000);
Serial.printf(">>>%s.amps %f\r\n",currentName, (float)Amps / 1000);
Serial.printf(">>>%s.watts %f\r\n",currentName, (float)Watts);
Serial.printf(">>>%s.capacity_remain_ah %f\r\n",currentName, (float)CapacityRemainAh / 1000);
Serial.printf(">>>%s.capacity_remain_wh %f\r\n",currentName, ((float)(CapacityRemainAh) / 1000) * ((float)(Volts) / 1000));
Serial.printf(">>>%s.capacity_remain_percent %d\r\n",currentName, CapacityRemainPercent);
Serial.printf(">>>%s.temp1 %f\r\n",currentName, (float)Temp1 / 10);
Serial.printf(">>>%s.temp2 %f\r\n",currentName, (float)Temp2 / 10);
/*
Serial.printf("%s Balance Code Low: 0x%x\r\n",currentName, BalanceCodeLow);
Serial.printf("%s Balance Code High: 0x%x\r\n",currentName, BalanceCodeHigh);
@ -365,15 +358,9 @@ bool processCellInfo(byte *data, unsigned int dataLen)
_cellMin = CellVolt;
}
Serial.printf(">>>%s.cell.%d.voltage: %f\r\n",currentName, i+1,(float)CellVolt/1000);
Serial.printf("%s Cell %d Voltage: %f\r\n",currentName, i+1,(float)CellVolt/1000);
Serial.printf(">>>%s.cell.%d.voltage %f\r\n",currentName, i+1,(float)CellVolt/1000);
}
Serial.printf("%s Max Cell Voltage: %f\r\n",currentName, (float)_cellMax / 1000);
Serial.printf("%s Min Cell Voltage: %f\r\n",currentName, (float)_cellMin / 1000);
Serial.printf("%s Difference Cell Voltage: %f\r\n",currentName, (float)(_cellMax - _cellMin) / 1000);
Serial.printf("%s Average Cell Voltage: %f\r\n",currentName, (float)(_cellSum / NumOfCells) / 1000);
Serial.printf(">>>%s.max_cell_voltage: %f\r\n",currentName, (float)_cellMax / 1000);
Serial.printf(">>>%s.min_cell_voltage: %f\r\n",currentName, (float)_cellMin / 1000);
Serial.printf(">>>%s.difference_cell_voltage: %f\r\n",currentName, (float)(_cellMax - _cellMin) / 1000);

View File

@ -5,29 +5,15 @@ import serial
import select
from collections import deque
def parse_to_graphite(data, root='rc.bms', timestamp=None):
if not timestamp:
timestamp = int(time.time())
def parse_to_graphite(data):
timestamp = int(time.time())
results = []
lines = data.strip().split('\n')
for line in lines:
if line.startswith('BMS'):
parts = line.split()
bank_battery = parts[1]
metric_name = ' '.join(parts[2:-1]).replace(' ', '_')
metric_value = parts[-1]
# Remove trailing colon in the metric name if present
if metric_name.endswith(':'):
metric_name = metric_name[:-1]
if 'Cell' in metric_name and 'Voltage' in metric_name and 'Cell' in metric_name.split('_')[0]:
cell_number = metric_name.split('_')[1]
metric_name = f"Cell.{cell_number}.Voltage"
metric_path = f"{root}.{bank_battery}.{metric_name}"
results.append(f"{metric_path} {metric_value} {timestamp}")
if line.startswith('>>>'):
metric_path = line[3:].strip() # Remove the ">>>" prefix and any leading/trailing whitespace
results.append(f"{metric_path} {timestamp}")
return results
def send_to_graphite(data, host='10.6.0.1', port=2003):

View File

@ -185,11 +185,11 @@ void decodeVictron(BLEAdvertisedDevice advertisedDevice) {
return;
}
Serial.printf(">>>mppt.battery_volts %f\r\n",batteryVoltage);
Serial.printf(">>>mppt.battery_amps %f\r\n",batteryCurrent);
Serial.printf(">>>mppt.solar_watts %f\r\n",inputPower);
Serial.printf(">>>mppt.output_current %f\r\n",outputCurrent);
Serial.printf(">>>mppt.yield %f\r\n",todayYield);
Serial.printf(">>>mppt.state %d\r\n",deviceState);
Serial.printf(">>>mppt.1.battery_volts %f\r\n",batteryVoltage);
Serial.printf(">>>mppt.1.battery_amps %f\r\n",batteryCurrent);
Serial.printf(">>>mppt.1.solar_watts %f\r\n",inputPower);
Serial.printf(">>>mppt.1.output_current %f\r\n",outputCurrent);
Serial.printf(">>>mppt.1.yield %f\r\n",todayYield);
Serial.printf(">>>mppt.1.state %d\r\n",deviceState);
}
}