Cleanup only

This commit is contained in:
2025-12-29 11:09:33 +11:00
parent 9f0f2ce8fd
commit 2bd6094955
2 changed files with 16 additions and 12 deletions

View File

@@ -143,7 +143,7 @@ MyVictronCallback callback;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
delay(2000); delay(1000);
Serial.println("\n\n================================="); Serial.println("\n\n=================================");
Serial.println("VictronBLE Multi-Device Example"); Serial.println("VictronBLE Multi-Device Example");
@@ -155,14 +155,12 @@ void setup() {
Serial.println(victron.getLastError()); Serial.println(victron.getLastError());
while (1) delay(1000); while (1) delay(1000);
} }
delay(1000);
// Enable debug output (optional) // Enable debug output (optional)
victron.setDebug(true); victron.setDebug(true);
// Set callback for data updates // Set callback for data updates
victron.setCallback(&callback); victron.setCallback(&callback);
delay(1000);
// Add your devices here // Add your devices here
// Replace with your actual MAC addresses and encryption keys // Replace with your actual MAC addresses and encryption keys
@@ -189,7 +187,6 @@ void setup() {
"0ec3adf7433dd61793ff2f3b8ad32ed8", // Encryption key (32 hex chars) "0ec3adf7433dd61793ff2f3b8ad32ed8", // Encryption key (32 hex chars)
DEVICE_TYPE_SOLAR_CHARGER // Device type DEVICE_TYPE_SOLAR_CHARGER // Device type
); );
delay(1000);
/* /*
* *
@@ -209,41 +206,47 @@ void setup() {
*/ */
// Example: Solar Charger #1 // Example: Solar Charger #1
/*
victron.addDevice( victron.addDevice(
"MPPT 100/30", // Device name "MPPT 100/30", // Device name
"E7:48:D4:28:B7:9C", // MAC address "E7:48:D4:28:B7:9C", // MAC address
"0df4d0395b7d1a876c0c33ecb9e70dcd", // Encryption key (32 hex chars) "0df4d0395b7d1a876c0c33ecb9e70dcd", // Encryption key (32 hex chars)
DEVICE_TYPE_SOLAR_CHARGER // Device type DEVICE_TYPE_SOLAR_CHARGER // Device type
); );
*/
// Example: Solar Charger #2 // Example: Solar Charger #2
/*
victron.addDevice( victron.addDevice(
"MPPT 75/15", "MPPT 75/15",
"AA:BB:CC:DD:EE:FF", "AA:BB:CC:DD:EE:FF",
"1234567890abcdef1234567890abcdef", "1234567890abcdef1234567890abcdef",
DEVICE_TYPE_SOLAR_CHARGER DEVICE_TYPE_SOLAR_CHARGER
); );
*/
// Example: Battery Monitor (SmartShunt) // Example: Battery Monitor (SmartShunt)
/*
victron.addDevice( victron.addDevice(
"SmartShunt", "SmartShunt",
"11:22:33:44:55:66", "11:22:33:44:55:66",
"fedcba0987654321fedcba0987654321", "fedcba0987654321fedcba0987654321",
DEVICE_TYPE_BATTERY_MONITOR DEVICE_TYPE_BATTERY_MONITOR
); );
*/
// Example: Inverter/Charger // Example: Inverter/Charger
/*
victron.addDevice( victron.addDevice(
"MultiPlus", "MultiPlus",
"99:88:77:66:55:44", "99:88:77:66:55:44",
"abcdefabcdefabcdefabcdefabcdefab", "abcdefabcdefabcdefabcdefabcdefab",
DEVICE_TYPE_INVERTER DEVICE_TYPE_INVERTER
); );
*/
delay(1000);
Serial.println("Configured " + String(victron.getDeviceCount()) + " devices"); Serial.println("Configured " + String(victron.getDeviceCount()) + " devices");
Serial.println("\nStarting BLE scan...\n"); Serial.println("\nStarting BLE scan...\n");
delay(1000);
} }
void loop() { void loop() {

View File

@@ -471,8 +471,8 @@ bool VictronBLE::parseBatteryMonitor(const uint8_t* data, size_t len, BatteryMon
// Parse battery current (22-bit signed, 1 mA units) // Parse battery current (22-bit signed, 1 mA units)
// Bits 0-7: currentLow, Bits 8-15: currentMid, Bits 16-21: low 6 bits of currentHigh_consumedLow // Bits 0-7: currentLow, Bits 8-15: currentMid, Bits 16-21: low 6 bits of currentHigh_consumedLow
int32_t current = payload->currentLow | int32_t current = payload->currentLow |
(payload->currentMid << 8) | (payload->currentMid << 8) |
((payload->currentHigh_consumedLow & 0x3F) << 16); ((payload->currentHigh_consumedLow & 0x3F) << 16);
// Sign extend from 22 bits to 32 bits // Sign extend from 22 bits to 32 bits
if (current & 0x200000) { if (current & 0x200000) {
@@ -482,8 +482,8 @@ bool VictronBLE::parseBatteryMonitor(const uint8_t* data, size_t len, BatteryMon
// Parse consumed Ah (18-bit signed, 10 mAh units) // Parse consumed Ah (18-bit signed, 10 mAh units)
// Bits 0-1: high 2 bits of currentHigh_consumedLow, Bits 2-9: consumedMid, Bits 10-17: consumedHigh // Bits 0-1: high 2 bits of currentHigh_consumedLow, Bits 2-9: consumedMid, Bits 10-17: consumedHigh
int32_t consumedAh = ((payload->currentHigh_consumedLow & 0xC0) >> 6) | int32_t consumedAh = ((payload->currentHigh_consumedLow & 0xC0) >> 6) |
(payload->consumedMid << 2) | (payload->consumedMid << 2) |
(payload->consumedHigh << 10); (payload->consumedHigh << 10);
// Sign extend from 18 bits to 32 bits // Sign extend from 18 bits to 32 bits
if (consumedAh & 0x20000) { if (consumedAh & 0x20000) {
@@ -520,8 +520,8 @@ bool VictronBLE::parseInverter(const uint8_t* data, size_t len, InverterData& re
result.batteryCurrent = payload->batteryCurrent * 0.01f; result.batteryCurrent = payload->batteryCurrent * 0.01f;
// Parse AC Power (signed 24-bit, 1 W units) // Parse AC Power (signed 24-bit, 1 W units)
int32_t acPower = payload->acPowerLow | int32_t acPower = payload->acPowerLow |
(payload->acPowerMid << 8) | (payload->acPowerMid << 8) |
(payload->acPowerHigh << 16); (payload->acPowerHigh << 16);
// Sign extend from 24 bits to 32 bits // Sign extend from 24 bits to 32 bits
if (acPower & 0x800000) { if (acPower & 0x800000) {
@@ -698,6 +698,7 @@ void VictronBLE::debugPrint(const String& message) {
} }
} }
// XXX Can't we use debugPrintf instead for hex struct etc?
void VictronBLE::debugPrintHex(const char* label, const uint8_t* data, size_t len) { void VictronBLE::debugPrintHex(const char* label, const uint8_t* data, size_t len) {
if (!debugEnabled) return; if (!debugEnabled) return;