# Node-red/node\_modules/xbee-api/lib/xbee-api ERROR

**URL:** <https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039>\
**Category:** General\
**Created:** [22 March 2021 19:53 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039 "2021-03-22T19:53:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [22 March 2021 19:53 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/1 "2021-03-22T19:53:29Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 March 2021 20:09 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/2 "2021-03-22T20:09:36Z")

</div>

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](https://github.com/ramonmata/node-red-contrib-xbee/issues) repo

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [22 March 2021 21:22 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/3 "2021-03-22T21:22:50Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 March 2021 21:32 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/4 "2021-03-22T21:32:11Z")

</div>

> [@Rezcue](#):
>
> Is it possible that node-red autorestart after this crash?

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.

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [22 March 2021 21:36 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/5 "2021-03-22T21:36:25Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 March 2021 21:38 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/6 "2021-03-22T21:38:09Z")

</div>

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

& for future readers - post your solution 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2021 21:53 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/7 "2021-03-22T21:53:44Z")

</div>

If you installed using the [recommended script](https://nodered.org/docs/getting-started/raspberrypi) 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.

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [22 March 2021 21:59 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/8 "2021-03-22T21:59:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [22 March 2021 23:57 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/9 "2021-03-22T23:57:05Z")

</div>

"Hi [@Rezcue](https://github.com/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](https://github.com/ramonmata/node-red-contrib-xbee/issues/7))

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

```auto
#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.

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [23 March 2021 01:47 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/10 "2021-03-23T01:47:01Z")

</div>

Its me again.  
changed the code to.

```auto
#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](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.

---

<div class="post-metadata">

**Author:** ![Rezcue](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rezcue](https://discourse.nodered.org/u/Rezcue)\
**Post date:** [27 March 2021 16:11 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/11 "2021-03-27T16:11:37Z")

</div>

Well well well

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

work around:

> [@Restart flows using Node Red API](https://discourse.nodered.org/t/restart-flows-using-node-red-api/34632):
>
> Hello Please can somebody help with the working example of how to restart flows using API. [Link to Node Red documentation](https://nodered.org/docs/api/admin/methods/post/flows/#headers) I found a similar topic marked as solved, but I cannot really see the solution there. [Link to similar topic](https://discourse.nodered.org/t/solved-restarting-flows-programmatically/9341) I can use GET to retrieve the information about the flows and to get info about the specific flow. I don't know how to structure and use this information to redeploy the flow. My flows [{"id":"38ebc8f0.806f88","type":"tab","label":"My Flow","disabled":false,"in…

 ![Solved](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4abd3ad9a455f036816cde201deaf3c61fbf5148.png)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 April 2021 16:12 UTC](https://discourse.nodered.org/t/node-red-node-modules-xbee-api-lib-xbee-api-error/43039/12 "2021-04-10T16:12:34Z")

</div>

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