You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Gerätedaten und Schlüssel (hier nur für den SmartShunt)
typedef struct {
String address; // MAC-Adresse
String name; // Gerätename
uint8_t key[16]; // AES-Schlüssel (16 Byte)
// SmartShunt-Daten
uint16_t batteryVoltage; // in mV
int16_t batteryCurrent; // in mA (signed)
uint8_t soc; // in %
uint16_t energy; // firmwareabhängig (z. B. Wh)
uint16_t power; // z. B. in W
uint32_t lastUpdate; // Zeitstempel (millis)
} DeviceKey;
#define MAX_DEVICES 1
DeviceKey deviceKeys[MAX_DEVICES];
int numDevices = 0;
// Hilfsfunktion: Gibt den Index eines Geräts anhand der MAC-Adresse zurück
int getDeviceIndex(const String &address) {
for (int i = 0; i < numDevices; i++) {
if (deviceKeys[i].address == address)
return i;
}
return -1;
}
das ist meine Ausgabe:
Daten: [{"address":"xxx","name":"shunt","batteryVoltage":21.913,"batteryCurrent":14.473,"soc":5,"energy":31372,"power":10332,"lastUpdate":1631929}]
was totaler Blödsinn ist, weil ich 26,53V/ -5A und 88% habe
kann mir bitte jemand helfen... ich finde leider keine Daten, wie ich die entschlüsselten Daten interpretieren kann.
Vieeeeeelen Dank
Sven
The text was updated successfully, but these errors were encountered:
svenessar
changed the title
Halle, ich habe kein ESPHome mit HA möchte aber mein Victron Smart Shunt mit ESP dennoch auslesen und bekomme nur Mist ausgegeben
Hallo, ich habe kein ESPHome mit HA möchte aber mein Victron Smart Shunt mit ESP dennoch auslesen und bekomme nur Mist ausgegeben
Feb 17, 2025
ich komme einfach nicht weiter und werd noch bekloppt :-(
das ist mein Code:
`
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <aes/esp_aes.h> // ESP32 AES-Bibliothek
#include <ArduinoJson.h>
#define USE_String
// --- BLE Setup ---
BLEScan *pBLEScan;
// Gerätedaten und Schlüssel (hier nur für den SmartShunt)
typedef struct {
String address; // MAC-Adresse
String name; // Gerätename
uint8_t key[16]; // AES-Schlüssel (16 Byte)
// SmartShunt-Daten
uint16_t batteryVoltage; // in mV
int16_t batteryCurrent; // in mA (signed)
uint8_t soc; // in %
uint16_t energy; // firmwareabhängig (z. B. Wh)
uint16_t power; // z. B. in W
uint32_t lastUpdate; // Zeitstempel (millis)
} DeviceKey;
#define MAX_DEVICES 1
DeviceKey deviceKeys[MAX_DEVICES];
int numDevices = 0;
// Hilfsfunktion: Gibt den Index eines Geräts anhand der MAC-Adresse zurück
int getDeviceIndex(const String &address) {
for (int i = 0; i < numDevices; i++) {
if (deviceKeys[i].address == address)
return i;
}
return -1;
}
// --- Victron SmartShunt Datenstrukturen ---
typedef struct {
uint16_t batteryVoltage;
int16_t batteryCurrent;
uint8_t soc;
uint16_t energy;
uint16_t power;
uint8_t padding[7]; // Padding, nicht ausgewertet
} attribute((packed)) victronSmartShuntData;
void publishData(int index) {
StaticJsonDocument<256> doc;
JsonObject device = doc.createNestedObject();
device["address"] = deviceKeys[index].address;
device["name"] = deviceKeys[index].name;
device["batteryVoltage"] = deviceKeys[index].batteryVoltage / 1000.0; // in V
device["batteryCurrent"] = deviceKeys[index].batteryCurrent / 1000.0; // in A
device["soc"] = deviceKeys[index].soc;
device["energy"] = deviceKeys[index].energy;
device["power"] = deviceKeys[index].power;
device["lastUpdate"] = deviceKeys[index].lastUpdate;
String response;
serializeJson(doc, response);
Serial.println("Daten: " + response);
}
// --- BLE Callback für SmartShunt ---
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) override {
#ifdef USE_String
String manData = advertisedDevice.getManufacturerData();
#else
std::string manData = advertisedDevice.getManufacturerData();
#endif
if (!advertisedDevice.haveManufacturerData())
return;
#ifdef USE_String
manData.toCharArray((char *)manDataBuf, 29);
#else
memcpy(manDataBuf, manData.data(), 29);
#endif
}
};
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Starte Victron SmartShunt BLE-Scan...");
// --- Konfiguriere den SmartShunt (DeviceKey) ---
numDevices = MAX_DEVICES; // Für dieses Beispiel nur ein Gerät
deviceKeys[0].address = "XXXX"; // Bekannte MAC-Adresse des SmartShunt
deviceKeys[0].name = "shunt";
uint8_t key0[16] = {
XXXXX
};
memcpy(deviceKeys[0].key, key0, 16);
// --- BLE initialisieren ---
BLEDevice::init("");
pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->setInterval(100);
pBLEScan->setWindow(99);
Serial.println("Setup abgeschlossen.");
}
void loop() {
// Starte einen Scan (hier 1 Sekunde)
pBLEScan->start(1, false);
pBLEScan->clearResults(); // Ergebnisse löschen, um Speicher freizugeben
delay(2000);
}
`
das ist meine Ausgabe:
Daten: [{"address":"xxx","name":"shunt","batteryVoltage":21.913,"batteryCurrent":14.473,"soc":5,"energy":31372,"power":10332,"lastUpdate":1631929}]
was totaler Blödsinn ist, weil ich 26,53V/ -5A und 88% habe
kann mir bitte jemand helfen... ich finde leider keine Daten, wie ich die entschlüsselten Daten interpretieren kann.
Vieeeeeelen Dank
Sven
The text was updated successfully, but these errors were encountered: