Suggested changes to EmonTX Serial output format

@Robert.Wall @TrystanLea

I have 3 suggestions for modifications to the serial output from the EmonTxV3CM

  1. Make the pulse output dependent on the pulse_enable flag. This will remove the emoncms input when no pulse meter is in use.
  2. Include the NodeID in the serial message. There have been several instances where users wish to connect several EmonTX via USB to one RPi. If the NodeID was included this could be handled by Emonhub to reliably link the serial input to a specific EmonTX as the USB may be reassigned by the OS. This would best added as an option (default false).
  3. Include an option for JSON output. Data could more easily be parsed when received if sent as a JSON String. A flag for json_enable would need to be created in the config (default false).

Untested code.

    if (json_enable) {Serial.print(F("{"));}
    Serial.print(F("NodeID:")); Serial.print(nodeID);
    Serial.print(F(",MSG:")); Serial.print(emontx.Msg);
    Serial.print(F(",Vrms:")); Serial.print(emontx.Vrms*0.01);
    if (CT1) { Serial.print(F(",P1:")); Serial.print(emontx.P1); }
    if (CT2) { Serial.print(F(",P2:")); Serial.print(emontx.P2); }
    if (CT3) { Serial.print(F(",P3:")); Serial.print(emontx.P3); }
    if (CT4) { Serial.print(F(",P4:")); Serial.print(emontx.P4); }
    if (CT1) { Serial.print(F(",E1:")); Serial.print(emontx.E1); }
    if (CT2) { Serial.print(F(",E2:")); Serial.print(emontx.E2); }
    if (CT3) { Serial.print(F(",E3:")); Serial.print(emontx.E3); }
    if (CT4) { Serial.print(F(",E4:")); Serial.print(emontx.E4); }
    if (emontx.T1!=30000) { Serial.print(F(",T1:")); Serial.print(emontx.T1*0.01); }
    if (emontx.T2!=30000) { Serial.print(F(",T2:")); Serial.print(emontx.T2*0.01); }
    if (emontx.T3!=30000) { Serial.print(F(",T3:")); Serial.print(emontx.T3*0.01); }

    if (pulse_enable) {Serial.print(F(",pulse:")); Serial.print(emontx.pulse);}
    if (json_enable) {Serial.print(F("}"));}
1 Like

Thanks @borpin, I will have a think how we could parse the nodeid in the new OEM interfacer emonhub/ at master · openenergymonitor/emonhub · GitHub that’s a good idea. The interfacer supports all three formats: JSON, key:value and binary values, without a preference for JSON over key:value so that would be a consideration for the firmware, I know memory is tight so supporting multiple options may not work.

Does the interfacer ignore all the serial output before real messages?