Skip to content

Instantly share code, notes, and snippets.

@rmit-s3545996-leanne-tran
Last active June 16, 2021 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmit-s3545996-leanne-tran/a10d1cce0344d0cd839e37a35c1291f1 to your computer and use it in GitHub Desktop.
Save rmit-s3545996-leanne-tran/a10d1cce0344d0cd839e37a35c1291f1 to your computer and use it in GitHub Desktop.
xBee transmit and recieve

Send a personalised message through one xBee and get it on the other one!

Remember to configure your Port number before deploying. This can be found in Windows by going to 'Device Manager' and seeing which ports are connected.

[{"id":"aee4e13d.075b7","type":"tab","label":"Send/Recieve xBee","disabled":true,"info":"Send a personalised message to your xBee transmitter and see that message on your xBee reciever"},{"id":"428bdecb.3eef2","type":"xbee-rx","z":"aee4e13d.075b7","name":"xBee rx","xBee":"f466bf11.58b12","x":230,"y":40,"wires":[["be678a3.11bb678"]]},{"id":"be678a3.11bb678","type":"debug","z":"aee4e13d.075b7","name":"xbee recieved","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":480,"y":40,"wires":[]},{"id":"947859d8.5e11c8","type":"xbee-tx","z":"aee4e13d.075b7","name":"","xBee":"662f3166.97e2a","x":500,"y":160,"wires":[]},{"id":"7cc39ec6.350d3","type":"function","z":"aee4e13d.075b7","name":"dataFrame","func":" var myDataFrame1 = {\n type: 0x10,\n id: 0x01,\n destination64: \"0013a200400a0127\",\n destination16: \"fffe\",\n broadcastRadius: 0x00,\n options: 0x00,\n data: flow.get(\"words\")||\"hello\"\n };\n msg.payload=myDataFrame1;\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":160,"wires":[["947859d8.5e11c8","37b8bc95.232c14"]]},{"id":"9df8b4c8.697da8","type":"inject","z":"aee4e13d.075b7","name":"inputLoop","topic":"","payload":"[]","payloadType":"json","repeat":"5","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":160,"wires":[["7cc39ec6.350d3"]]},{"id":"79abc143.509d5","type":"ui_text_input","z":"aee4e13d.075b7","name":"dataIn","label":"DATA INPUT","tooltip":"TYPE HERE","group":"8a213d1c.f3679","order":4,"width":0,"height":0,"passthru":false,"mode":"text","delay":300,"topic":"words","x":250,"y":240,"wires":[["1dd55121.d4815f"]]},{"id":"37b8bc95.232c14","type":"debug","z":"aee4e13d.075b7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":100,"wires":[]},{"id":"1dd55121.d4815f","type":"function","z":"aee4e13d.075b7","name":"save input","func":"flow.set(\"words\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":240,"wires":[[]]},{"id":"f466bf11.58b12","type":"xbee-config","z":"","apiMode":"2","rawFrames":false,"convertAdc":true,"vrefAdc":"1200","serialPort":"COM5","lock":true,"baudRate":"9600","dataBits":"8","stopBits":"1","parity":"none","bufferSize":"65536","rtscts":false,"xon":false,"xoff":false,"xany":false,"vmin":"1","vtime":"0"},{"id":"662f3166.97e2a","type":"xbee-config","z":"","apiMode":"2","rawFrames":false,"convertAdc":true,"vrefAdc":"1200","serialPort":"COM6","lock":true,"baudRate":"9600","dataBits":"8","stopBits":"1","parity":"none","bufferSize":"65536","rtscts":false,"xon":false,"xoff":false,"xany":false,"vmin":"1","vtime":"0"},{"id":"8a213d1c.f3679","type":"ui_group","z":"","name":"DATA INPUT","tab":"11214bd0.b00df4","disp":true,"width":"6","collapse":false},{"id":"11214bd0.b00df4","type":"ui_tab","z":"","name":"XBEE STUFF","icon":"dashboard","disabled":false,"hidden":false}]
@martin9115
Copy link

Hi, Can this project help me build zigbee mesh topology?

@3amWednesday
Copy link

Hello, not directly no.
This is a basic flow for 1-1 communcation, usually used to debug message types or to see if it even works to begin with. If you want a mesh topology, my recommendation is to look at the microcontroller connected to the zigbee, since it would be the individual nodes that would receive packets from their peers to pass onto the destination. If you are looking to use node-red as a controller (in the networking sense), it could work if you used MQTT, or a series of switch nodes, to direct the messages.

@martin9115
Copy link

Any example, please ?

@martin9115
Copy link

I use RPI to connect with zigbee. What do you mean by ''microcontroller connected to the zigbee''? MCU with embedded zigbee module or MCU with special zigbee library?

If i use node-red as a controller, do this MQTT library help me?
https://flows.nodered.org/node/node-red-contrib-zigbee2mqtt
https://flows.nodered.org/node/node-red-contrib-zigbee2mqtt-devices

Can you direct me for some example?

@martin9115
Copy link

Hi, how can we adopt this example to transmit/receive sensor data?

@3amWednesday
Copy link

3amWednesday commented Feb 8, 2021

Ok, I'm going to assume you have a pair of zigbees, a RPI, and a PC, in addition to a bunch of sensors. I'm also, going to assume you know how to transmit a message, and that you've got both xbees/zigbees set up with XCTU. If you don't, this can help, but its best to look at the specific zigbee module and library for details.
https://circuitdigest.com/microcontroller-projects/raspberry-pi-xbee-module-interfacing

First, read the sensor manuals to figure out how to receive the data in a readable format. Set up the pins and inputs and whatnot.

Then, "save" all that information into a JSON data struct or something similar.
For example:
sensordata= { 'sensor1':100, 'sensor2':'UP' }

Now send the data to the controller/the other zigbee. The code should have something like Serial.write(sensordata) in it.

Now, on the Node-Red end, you receive the message. I'm assuming you've already connected your zigbee to the PC and have it set up, but if you don't please look at my setup and try to follow that. Or alternatively configure it in XCTU to send everything serially and use a Serial In node.
If you use the DEBUG node, you can see what the packet it sends is. This should normally be a large JSON with many values, but the important one is data. So run this through a function or a change node to get it and you got it. sensordata = msg.payload.data.sensordata

@martin9115
Copy link

Hi, i try your example, but i can't see the message ''Hello'', that supposed to come up and i've got this in the debug node.
Where can be my mistake?

XBee Send_Receive
XBee Send_Receive  1
XBee Send_Receive 2

@3amWednesday
Copy link

It seems you haven't entered anything into the text input yet. Its been a while, but if I remember properly, I'd set it up so that anything in the input is sent forward after the ENTER button is pressed on the keyboard. Either that or you did send correctly, but everything has been reverted to lowercase, so you are confusing your correct input with the default.

To check if you've managed to 'save' your inout into the flow: Get a input node, inject a flow property of "words", and stick a DEBUG node on the end to see what comes out.

To demo the connection itself, if the whole flow property thing is confusing you, hardcode the data variable yourself in the function window of the last image. Maybe something different in case upper and lower case is ignored, like hell0w0rld, or numb3rs, or so.

On the side, special characters outside the standard english keyboard symbols react strangely when sent. I had fun entering Chinese and Arabic and emojis into the input and seeing the gibberish that came out.

@MartinSokolov15
Copy link

I repeat every step you did.
This is my setups, please can you tell me where are my mistakes?

XBEE TEST 5

@MartinSokolov15
Copy link

Have you try it with XBee 3 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment