LowPowerLab Forum

Software support => Coding questions => Topic started by: Kylix on February 23, 2019, 03:28:42 PM

Title: Pulse meter modified
Post by: Kylix on February 23, 2019, 03:28:42 PM
I need to send a command from the Gateway to the Pulse meter node like this: KW:31587600  (KW: is the command and the rest is a number I need to send to the node to update the kilowatt counter).

I changed the loop part of the default Pulse meter sketch like this:
Code: [Select]
void loop() {
  if (WPReady && radio.receiveDone())
    DEBUG('[');DEBUG(radio.SENDERID);DEBUG("] ");
    for (byte i = 0; i < radio.DATALEN; i++) {
      if (radio.DATA[0]=='K' && radio.DATA[1]=='W' && radio.DATA[2]==':')
unsigned long val1=0;
        char* pos;
        pos = strtok ((char *)radio.DATA, ":");
        pos = strtok (NULL, ":");
        val1 = strtoul(pos, NULL, 10);
        PulseCounterVolatile = PulseCounter = PULSECOUNTLASTMINUTEMARK = val1;

    CheckForWirelessHEX(radio, flash, true);

    if (radio.ACKRequested())
      DEBUG(" - ACK sent.");

Moteino hangs. Though, it seems that only the radio part hangs; restarting Moteino, I noted that the PulseCounter is correctly saved into the flash memory. The LED blinks when interrupt occurs but nothing gets sent after 1-2 days.

I suppose it's a buffer overflow problem. Any idea how to parse the received command without having the radio freezed?

Could it be the sendACK() statement? (although, I didn't send yet any command)
Title: Re: Pulse meter modified
Post by: Kylix on March 01, 2019, 03:48:51 AM
It worked for 7 days and it hanged again.
I used before the old sketch, that included WirelessHEX library, without any issue. I'll try the new sketch,  without any change and see if it still hangs.
Title: Re: Pulse meter modified
Post by: Kylix on March 11, 2019, 06:38:02 PM
I downloaded an old commit of the RFM69 library (commit 2a7b05768c3e5a0111376e1529546a5955f59bd3), which uses the WirelessHEX69 library and Moteino is still working without issues.

Could it be that the new OTA libray uses more RAM?
Title: Re: Pulse meter modified
Post by: Felix on March 11, 2019, 09:04:31 PM
Not sure. But any way you can isolate what is causing the hang?
What about using a watchdog?
Title: Re: Pulse meter modified
Post by: Kylix on March 12, 2019, 06:42:46 AM
I'd rather prefer using the old library than the watchdog to reset the board from time to time, when the transceiver hangs.

I already tested the latest library version with the default PulseMeter sketch, downloaded from Github and after 1-2 days it was hanging.

I only have an IR phototransistor+resistor connected to Moteino, which reads the IR pulses from the electricity meter and it worked fine for almost 2 years with the old library, until I decided to update it. I needed to send KW usage corrections once in a while, to make the counting match the electriciry meter.

Anyway, I'm happy that it still works with the old  RFM69 library.