SignalK / signalk-server

An implementation of a Signal K central server for boats.
http://signalk.org
Apache License 2.0
307 stars 152 forks source link

SignalK skipping random emit's #1763

Closed pa1pdr closed 2 months ago

pa1pdr commented 3 months ago

I created an ESP32 application which reads the BMS and then submits the data every second to SignalK. This works for a while, but then randomly SignalK is dropping certain values, evidenced by timestamp difference in the data browser and by Grafana, which puts the values using the influxDB 1.8 plugin.

This is the piece of code that is emitting the values to SignalK: ` void BatteryTransmitter::emitBatteryInfo () {

    String SKMetadataprefix = "electrical.batteries." + batteryName + ".";

    if (battery == NULL) return;
    VoltageSensor->emit (battery->getBatteryVoltage());
    CurrentSensor->emit (battery->getCurrent());   
    TemperatureSensor->emit(battery->getCellTemperature(0) + ZERO_CELSIUS);
    CapacitySensor->emit (battery->getFullCapacity() * SECONDSPERHOUR);    // in Joules
    RemainCapSensor->emit (battery->getRemainingCapacity() * SECONDSPERHOUR);   // in Joules
    StateOfChargeSensor->emit (battery->getStateofCharge() / 100.0);                     // in  units (100% = 1)
    CycleSensor->emit (battery->getCycleCount());
    CellMaxV->emit (battery->getMaxCellVoltage());
    CellMinV->emit (battery->getMinCellVoltage());
    CellDeltaV->emit (battery->getDeltaCellVoltage());
    CellAvgV->emit (battery->getAvgCellVoltage());

}`

So Current and Voltage are sent synchronously, yet SignalK seems to not always process them like that. The CPU is not overly busy (10%), nothing odd is happening (on the computer, network or ESP32 in that timeframe). It happens more often at random values.

Screenshot 2024-06-22 at 12 36 08
tkurki commented 3 months ago

Data Browser refreshes every 2 seconds, don’t use it for verifying if all updates are processed.

pa1pdr commented 3 months ago

Correct, but I would expect all values to be updated within approx 2 seconds, not having huge differences as shown by the graphs (or timestamps with sometimes more than 30 seconds difference..)

tkurki commented 3 months ago

Since only some of your data are exhibiting this and others are working ok I would first verify that the source is actually producing all of the data reliably. Since all data is processed along the same pathways I have a hard time coming up with a theory as to why a certain path's data would get gaps like that - and then all of the sudden again it works.

tkurki commented 2 months ago

Closing as no followup

pa1pdr commented 1 month ago

Since only some of your data are exhibiting this and others are working ok I would first verify that the source is actually producing all of the data reliably. Since all data is processed along the same pathways I have a hard time coming up with a theory as to why a certain path's data would get gaps like that - and then all of the sudden again it works.

the source is producing all data consistently: if there is no change, the previous value is used. The problem is not reoccurring, as I have lowered the update frequency to once per 3 secs. I agree with closing the issue.

KEGustafsson commented 1 month ago

How did you verified that ESP32 is sending all the data? What version of SensESP is in use?

I have seen earlier, not too often but often enought, issues with ESP32 not sending all paths and datas. Some paths are coming thru fine but some paths are missing. After SensESP reboot all data are going to SK fine.

Expecting that this could be something similar. Don't know the root cause for the behavior and not seen that for long time now.

pa1pdr commented 1 month ago

Good point Karl-Erik: no I didn't verify. Since all statements are exactly the same (see all 'emit's in the code provided), I assumed the library would not drop any path. But you are right: I have no solid proof that is the case. My ESP is running for weeks an end (as is SignalK) without reboot. The 3s interval solves it, but the root cause may be well connected to your earlier observations