Node-red/node_modules/xbee-api/lib/xbee-api ERROR

Hello,

im using the XBee-Nodes. My Setup is running like it should. Checking Waterlvl and sending it via XBee to Node-RED. But i get this error when my setup is running longer.

22 Mar 20:27:50 - [info] [mqtt-broker:2af3791d.faebd6] Connected to broker: mqtt                                     ://localhost:1883
(node:1131) UnhandledPromiseRejectionWarning: Error: Checksum Mismatch {"buffer":{"type":"Buffer","data":[126,0,13,144,0,253,25,81,128,160,225,65,15,80,206,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"offset":17,"length":13,"total":1382,"checksum":4,"b":4,"escape_next":false,"waiting":false}
    at XBeeAPI.parseRaw (/home/pi/.node-red/node_modules/xbee-api/lib/xbee-api.js:220:19)
    at Transform.XBeeAPI.parser._transform (/home/pi/.node-red/node_modules/xbee-api/lib/xbee-api.js:48:19)
    at Transform._read (_stream_transform.js:191:10)
    at Transform._write (_stream_transform.js:179:12)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Transform.Writable.write (_stream_writable.js:318:11)
    at SerialPort.ondata (_stream_readable.js:718:22)
    at SerialPort.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
(node:1131) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1131) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
D3An/Aus22

Anyone got an idea or knows this problem?

It looks like node-red-contrib-xbee is not handling its errors and is crashing node-red.

You should probably raise this as an issue on the node-red-contrib-xbee repo

Is it possible that node-red autorestart after this crash?

After the Node-Red or Flow restart its working again.

not from node red (once its crashed its crashed, is no more, has ceased to be, bereft of life, it rests in peace, it is an ex-parrot)

What OS does this run on?

Are you running as a service? or in PM2?

PM2 and services can be set to auto-restart a process on crash.

BUT this is a sticky plaster (or a band aid if you are from other parts of the world)! The real solution is for the node author to fix the problem.

I see you have raised an issue. I would personally add to that issue and state (in case the author is not aware) that contrib nodes MUST handle errors to avoid crashing node-red.

Im running Node-Red on PI 4 with the Raspberry PI OS (Raspbian) as service.
I think its the service i used the sudo systemctl enable node-red.service or so (cant remember correctly).

probably is - search web - tons of info on "systemctl auto restart"

& for future readers - post your solution :slight_smile:

1 Like

If you installed using the recommended script then it will have installed the service file, and the systemctl enable command you mentioned will enable auto restart, so if node-red crashes it will automatically be restarted.

Hello Colin,

saw some of ur post just now to this problem. I did use that script.
But after i got this crash it did not restart the right way. I could use Node-Red like turning on an LED via Xbees but i could not recive my data anymore. Only after node-red-stop and node-red-start it worked again.

I now started the Setup and watch the process again.

"Hi @Rezcue Seems problem is with the data frame, because it says to have a "length = 13" for the data, but as we can see (bunch of 0s) in the output you sent, length is actually bigger."
( [amonmata, UnhandledPromiseRejectionWarning: Error: Checksum Mismatch · Issue #7 · ramonmata/node-red-contrib-xbee · GitHub)

Thats the problem here. My arduinocode for the sensor manages only 8 bit. When i reach more then 255 it crashes my Node-Red.

#include <SoftwareSerial.h>
#include <HCSR04.h>
#include <XBee.h>

XBee xbee = XBee();
SoftwareSerial my(4,2); // TX, RX
int triggerPin = 13;
int echoPin = 12;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);


uint8_t payload[] = { 0 }; //<-------------------------------------------------------------
 //SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41C38580);

void setup () {
     Serial.begin(115200);
     my.begin(115200);
     xbee.setSerial(my);
     Serial.println("System Up!");
}


void loop () {
  
    ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
    double distance = distanceSensor.measureDistanceCm();
    Serial.println(distance);
    payload[0]= distance; //<--------------------------------------
    xbee.send(zbTx);
    delay(5000);
       
}

And to bring it back to work i restarted the flow or another moethod is restarting node-red.

Its me again.
changed the code to.

#include <SoftwareSerial.h>
#include <HCSR04.h>
#include <XBee.h>

XBee xbee = XBee();
SoftwareSerial my(4,2); // TX, RX
int triggerPin = 13;
int echoPin = 12;
UltraSonicDistanceSensor distanceSensor(triggerPin, echoPin);


char Buffer[255];
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41C38580);

void setup () {
     Serial.begin(115200);
     my.begin(115200);
     xbee.setSerial(my);
     Serial.println("System Up!");
}


void loop () {
  
    
    int distance = distanceSensor.measureDistanceCm();
    String d = String(distance);
    d.toCharArray(Buffer, 255);
    ZBTxRequest zbTx = ZBTxRequest(addr64, (uint8_t *)Buffer, strlen(Buffer));
    Serial.println(d);
    xbee.send(zbTx);
    delay(2000);      
}

https://www.digi.com/support/knowledge-base/maximum-payload-size-for-digi-rf-products
It sends now the int distance as String via Xbee too Node-Red. It can now go further then 254 cm.

Well well well

i dont get that error so often now but i still get it :smiley:
... so its not solved :smiley:

work around:

Get the log from node-red. Check if UnhandledPromiseRejectionWarning is in it. And trigger the flowrestart.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.