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:
void loop() {
if (WPReady && radio.receiveDone())
{
DEBUG('[');DEBUG(radio.SENDERID);DEBUG("] ");
for (byte i = 0; i < radio.DATALEN; i++) {
DEBUG((char)radio.DATA[i]);
}
DEBUGln();
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;
DEBUGln(val1);
}
CheckForWirelessHEX(radio, flash, true);
if (radio.ACKRequested())
{
radio.sendACK();
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)