node.jsarduinoxbeenode-xbee

Checksum Mismatch Error when using node-xbee to send a packet


A XBee Series 2 configured as a Coordinator API is trying to send a packet to a XBee Series 2 configured as a Router AT. The Coordinator is connected to a Mac OSX running node.js and the xbee-api library.

var frame_obj = {
    type: 0x10,
    ud: 0x01,
    destination64: "0013a20040b19213",
    data: "1"
}

serialport.write(xbeeAPI.buildFrame(frame_obj))

This causes Node to throw an error:

/Users/me/Dropbox/Projects/test-node/node_modules/xbee-api/lib/xbee-api.js:173
        throw new Error("Checksum Mismatch", S);
              ^
Error: Checksum Mismatch
    at XBeeAPI.parseRaw (/Users/me/Dropbox/Projects/test-node/node_modules/xbee-api/lib/xbee-api.js:173:15)
    at Object.parser (/Users/me/Dropbox/Projects/test-node/node_modules/xbee-api/lib/xbee-api.js:119:10)
    at Object.SerialPort.options.dataCallback (/Users/me/Dropbox/Projects/test-node/node_modules/serialport/serialport.js:136:15)
    at SerialPortFactory.SerialPort._emitData (/Users/me/Dropbox/Projects/test-node/node_modules/serialport/serialport.js:305:20)
    at afterRead (/Users/me/Dropbox/Projects/test-node/node_modules/serialport/serialport.js:283:18)
    at /Users/me/Dropbox/Projects/test-node/node_modules/serialport/serialport.js:297:9
    at Object.wrapper [as oncomplete] (fs.js:454:17)

Using Arduino's Serial Monitor on the AT Router side, we can see that the data being sent by the Coordinator actually reached the Router.

enter image description here

Question: Why is there a checksum error? How can we solve the problem?

Router AT Config

  <data>
    <profile>
      <description_file>XB24-ZB_22A7.xml</description_file>
      <settings>
        <setting command="ID">2001</setting>
        <setting command="SC">FFFF</setting>
        <setting command="SD">3</setting>
        <setting command="ZS">0</setting>
        <setting command="NJ">FF</setting>
        <setting command="NW">0</setting>
        <setting command="JV">1</setting>
        <setting command="JN">0</setting>
        <setting command="DH">13A200</setting>
        <setting command="DL">40A74613</setting>
        <setting command="NI">0x20</setting>
        <setting command="NH">1E</setting>
        <setting command="BH">0</setting>
        <setting command="AR">FF</setting>
        <setting command="DD">30000</setting>
        <setting command="NT">3C</setting>
        <setting command="NO">3</setting>
        <setting command="CR">3</setting>
        <setting command="SE">E8</setting>
        <setting command="DE">E8</setting>
        <setting command="CI">11</setting>
        <setting command="PL">4</setting>
        <setting command="PM">1</setting>
        <setting command="EE">0</setting>
        <setting command="EO">0</setting>
        <setting command="KY"></setting>
        <setting command="BD">3</setting>
        <setting command="NB">0</setting>
        <setting command="SB">0</setting>
        <setting command="RO">3</setting>
        <setting command="D7">1</setting>
        <setting command="D6">0</setting>
        <setting command="CT">64</setting>
        <setting command="GT">3E8</setting>
        <setting command="CC">2B</setting>
        <setting command="SM">0</setting>
        <setting command="SN">1</setting>
        <setting command="SO">0</setting>
        <setting command="SP">20</setting>
        <setting command="ST">1388</setting>
        <setting command="PO">0</setting>
        <setting command="D0">0</setting>
        <setting command="D1">0</setting>
        <setting command="D2">0</setting>
        <setting command="D3">0</setting>
        <setting command="D4">0</setting>
        <setting command="D5">1</setting>
        <setting command="P0">1</setting>
        <setting command="P1">0</setting>
        <setting command="P2">0</setting>
        <setting command="PR">1FFF</setting>
        <setting command="LT">0</setting>
        <setting command="RP">28</setting>
        <setting command="DO">1</setting>
        <setting command="IR">3E8</setting>
        <setting command="IC">0</setting>
        <setting command="V+">0</setting>
      </settings>
    </profile>
  </data>

Coordinator API Config

  <data>
    <profile>
      <description_file>XB24-ZB_21A7.xml</description_file>
      <settings>
        <setting command="ID">2001</setting>
        <setting command="SC">FFFF</setting>
        <setting command="SD">3</setting>
        <setting command="ZS">0</setting>
        <setting command="NJ">FF</setting>
        <setting command="DH">0</setting>
        <setting command="DL">FFFF</setting>
        <setting command="NI">0x20</setting>
        <setting command="NH">1E</setting>
        <setting command="BH">0</setting>
        <setting command="AR">FF</setting>
        <setting command="DD">30000</setting>
        <setting command="NT">3C</setting>
        <setting command="NO">3</setting>
        <setting command="CR">3</setting>
        <setting command="PL">4</setting>
        <setting command="PM">1</setting>
        <setting command="EE">0</setting>
        <setting command="EO">0</setting>
        <setting command="KY"></setting>
        <setting command="NK"></setting>
        <setting command="BD">3</setting>
        <setting command="NB">0</setting>
        <setting command="SB">0</setting>
        <setting command="D7">1</setting>
        <setting command="D6">0</setting>
        <setting command="AP">1</setting>
        <setting command="AO">0</setting>
        <setting command="SP">20</setting>
        <setting command="SN">1</setting>
        <setting command="D0">1</setting>
        <setting command="D1">0</setting>
        <setting command="D2">0</setting>
        <setting command="D3">0</setting>
        <setting command="D4">0</setting>
        <setting command="D5">1</setting>
        <setting command="P0">1</setting>
        <setting command="P1">0</setting>
        <setting command="P2">0</setting>
        <setting command="PR">1FFF</setting>
        <setting command="LT">0</setting>
        <setting command="RP">28</setting>
        <setting command="DO">1</setting>
        <setting command="IR">0</setting>
        <setting command="IC">0</setting>
        <setting command="V+">0</setting>
      </settings>
    </profile>
  </data>

Solution

  • It looks like the error is thrown when parsing a frame received on the Coordinator. If that's the case, can you dump the received frame?

    The stack trace points to fs.js:454:17 -- is that your code? What's there?

    If you try other samples from xbee-api, do they work?

    Somewhat unrelated, but I recommend running your coordinator at 115200 bps, and making sure you've enabled flow control in both your serial library and on the XBee module. That avoids problems with overflowing buffers. Data coming in from the network is delivered to the host before it can pile up on the XBee module.

    To enable hardware flow control, set ATD6 and ATD7 on the XBee module to 1. This requires that the host check the CTS signal from the XBee before sending to it, and assert the RTS signal when it's ready to receive bytes from the XBee.