TODO and m5stick and debug

This commit is contained in:
2025-12-18 20:43:10 +11:00
parent e827dea4e5
commit 97a71ce34c
4 changed files with 214 additions and 126 deletions

View File

@@ -36,3 +36,24 @@ framework = arduino
monitor_speed = 115200
build_flags =
-DCORE_DEBUG_LEVEL=3
[env:m5stick]
platform = espressif32
board = m5stick-c
framework = arduino
board_build.mcu = esp32
board_build.f_cpu = 240000000L
board_build.partitions = no_ota.csv
#upload_protocol = espota
#upload_port = Button.local
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_flags =
-Os
lib_deps =
M5StickC
elapsedMillis
TaskScheduler
Button2
ArduinoJson
https://github.com/scottp/PsychicHttp.git

View File

@@ -1,13 +1,13 @@
/**
* VictronBLE Example
*
*
* This example demonstrates how to use the VictronBLE library to read data
* from multiple Victron devices simultaneously.
*
*
* Hardware Requirements:
* - ESP32 board
* - Victron devices with BLE (SmartSolar, SmartShunt, etc.)
*
*
* Setup:
* 1. Get your device encryption keys from the VictronConnect app:
* - Open VictronConnect
@@ -16,7 +16,7 @@
* - Enable "Instant readout via Bluetooth"
* - Click "Show" next to "Instant readout details"
* - Copy the encryption key (32 hex characters)
*
*
* 2. Update the device configurations below with your devices' MAC addresses
* and encryption keys
*/
@@ -45,7 +45,7 @@ public:
}
Serial.println("Last Update: " + String((millis() - data.lastUpdate) / 1000) + "s ago");
}
void onBatteryMonitorData(const BatteryMonitorData& data) override {
Serial.println("\n=== Battery Monitor: " + data.deviceName + " ===");
Serial.println("MAC: " + data.macAddress);
@@ -54,20 +54,20 @@ public:
Serial.println("Current: " + String(data.current, 2) + " A");
Serial.println("SOC: " + String(data.soc, 1) + " %");
Serial.println("Consumed: " + String(data.consumedAh, 2) + " Ah");
if (data.remainingMinutes < 65535) {
int hours = data.remainingMinutes / 60;
int mins = data.remainingMinutes % 60;
Serial.println("Time Remaining: " + String(hours) + "h " + String(mins) + "m");
}
if (data.temperature > 0) {
Serial.println("Temperature: " + String(data.temperature, 1) + " °C");
}
if (data.auxVoltage > 0) {
Serial.println("Aux Voltage: " + String(data.auxVoltage, 2) + " V");
}
// Print alarms
if (data.alarmLowVoltage || data.alarmHighVoltage || data.alarmLowSOC ||
data.alarmLowTemperature || data.alarmHighTemperature) {
@@ -79,10 +79,10 @@ public:
if (data.alarmHighTemperature) Serial.print("HIGH-TEMP ");
Serial.println();
}
Serial.println("Last Update: " + String((millis() - data.lastUpdate) / 1000) + "s ago");
}
void onInverterData(const InverterData& data) override {
Serial.println("\n=== Inverter/Charger: " + data.deviceName + " ===");
Serial.println("MAC: " + data.macAddress);
@@ -91,9 +91,9 @@ public:
Serial.println("Current: " + String(data.batteryCurrent, 2) + " A");
Serial.println("AC Power: " + String(data.acPower) + " W");
Serial.println("State: " + String(data.state));
// Print alarms
if (data.alarmLowVoltage || data.alarmHighVoltage ||
if (data.alarmLowVoltage || data.alarmHighVoltage ||
data.alarmHighTemperature || data.alarmOverload) {
Serial.print("ALARMS: ");
if (data.alarmLowVoltage) Serial.print("LOW-V ");
@@ -102,10 +102,10 @@ public:
if (data.alarmOverload) Serial.print("OVERLOAD ");
Serial.println();
}
Serial.println("Last Update: " + String((millis() - data.lastUpdate) / 1000) + "s ago");
}
void onDCDCConverterData(const DCDCConverterData& data) override {
Serial.println("\n=== DC-DC Converter: " + data.deviceName + " ===");
Serial.println("MAC: " + data.macAddress);
@@ -119,7 +119,7 @@ public:
}
Serial.println("Last Update: " + String((millis() - data.lastUpdate) / 1000) + "s ago");
}
private:
String getChargeStateName(SolarChargerState state) {
switch (state) {
@@ -144,27 +144,35 @@ MyVictronCallback callback;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n\n=================================");
Serial.println("VictronBLE Multi-Device Example");
Serial.println("=================================\n");
// Initialize VictronBLE with 5 second scan duration
if (!victron.begin(5)) {
Serial.println("ERROR: Failed to initialize VictronBLE!");
Serial.println(victron.getLastError());
while (1) delay(1000);
}
// Enable debug output (optional)
victron.setDebug(true);
// Set callback for data updates
victron.setCallback(&callback);
// Add your devices here
// Replace with your actual MAC addresses and encryption keys
// Temporary - Scott Example
victron.addDevice(
"Rainbow48V", // Device name
"E4:05:42:34:14:F3", // MAC address
"0ec3adf7433dd61793ff2f3b8ad32ed8", // Encryption key (32 hex chars)
DEVICE_TYPE_SOLAR_CHARGER // Device type
);
// Example: Solar Charger #1
victron.addDevice(
"MPPT 100/30", // Device name
@@ -172,7 +180,7 @@ void setup() {
"0df4d0395b7d1a876c0c33ecb9e70dcd", // Encryption key (32 hex chars)
DEVICE_TYPE_SOLAR_CHARGER // Device type
);
// Example: Solar Charger #2
victron.addDevice(
"MPPT 75/15",
@@ -180,7 +188,7 @@ void setup() {
"1234567890abcdef1234567890abcdef",
DEVICE_TYPE_SOLAR_CHARGER
);
// Example: Battery Monitor (SmartShunt)
victron.addDevice(
"SmartShunt",
@@ -188,7 +196,7 @@ void setup() {
"fedcba0987654321fedcba0987654321",
DEVICE_TYPE_BATTERY_MONITOR
);
// Example: Inverter/Charger
victron.addDevice(
"MultiPlus",
@@ -196,7 +204,7 @@ void setup() {
"abcdefabcdefabcdefabcdefabcdefab",
DEVICE_TYPE_INVERTER
);
Serial.println("Configured " + String(victron.getDeviceCount()) + " devices");
Serial.println("\nStarting BLE scan...\n");
}
@@ -204,7 +212,7 @@ void setup() {
void loop() {
// Process BLE scanning and data updates
victron.loop();
// Optional: You can also manually query device data
// This is useful if you're not using callbacks
/*
@@ -212,13 +220,13 @@ void loop() {
if (victron.getSolarChargerData("E7:48:D4:28:B7:9C", solarData)) {
// Do something with solarData
}
BatteryMonitorData batteryData;
if (victron.getBatteryMonitorData("11:22:33:44:55:66", batteryData)) {
// Do something with batteryData
}
*/
// Add a small delay to avoid overwhelming the serial output
delay(100);
}