XBee and Spark Core


#1

Using Spark Core and XBee for RF Communication, Part #1

Here is one of the project I worked these days, this is a part one that uses Spark Core and XBee for RF Communication. My intention is to use XBee(s) and Spark Core to create very simple Home Automation project. In this part, I just turn on/off a remote LED which can be controlled using a Web Application.

The project is to control a remote light, i.e. turn on/off the light. In this part I am using Spark Core and two XBee’s (either Series 1 or Series 2). If you are using Series 1, then one should be configured to accept API Command, other can be wither API or AT mode. If you are using Series 2, then one should be configured as coordinator API and other can either be a Router AT/API or an End Device.

Introduction

Here in this project the Coordinator API XBee is connected to Spark Core and communicate using Serial. Spark Core is used as Internet Gateway to control XBee. The Core application uses XBee Library ported by @pkourany. For this project I am using XBee Remote AT command to control remote XBee(s). For more about API Mode and Remote AT Commands please refer to this link.

The Router XBee’s D0, D1, D2 and D3 pin are connected to four LEDs which can be remotely turn on/off. Any device can be connected to any pins and send the Remote AT commands to the remote XBee. It can a Rely connected to Electrical Light, or anything else.

To send Remote AT Command, you can either use a Broadcast address or a destination 64-bit (MAC/EUI64) address of the XBee module. Using the 64-bit destination address allows us to send commands to a particular XBee. There is also a 16-bit configurable address which can be used to group multiple XBees and send commands to that group. Since this is a different topic and is not in our scope, for more information refer to the Digi documentation.

The sample JavaScript Web application is used to control the remote light. To use this application you should replace the deviceid and accesstoken with actual values. When the application is opened you will be asked to enter the Name (any name, just for display purpose) and the 64-bit remote address of the XBee that is connected to the Relay Module. Once it is entered you can turn on/off the D0, D1, D2 and D3 pins.

Here you can find a very useful API Frame Generator from Digi International. This is extremely useful for the development and debugging, I used it a lot for this project.

Wiring

Coordinator XBee and Spark Core

  • XBee Vcc to Spark Core 3V3
  • XBee GND to Spark Core GND
  • XBee DOUT to Spark Core Rx
  • XBee DIN to Spark Core Tx

Router XBee and Relay Module

  • XBee Vcc to 3v3
  • XBee GND to GND
  • XBee DIO0 to LED1
  • XBee DIO1 to LED2
  • XBee DIO2 to LED3
  • XBee DIO3 to LED3

Screenshots
enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Demo Video


XBee Radios - Anybody Using Them?
#2

not bad! :smiley: Any interference going on since they are sitting on the same frequency?


#3

@kennethlimcp, I didn’t notice it, but it was apart and only for the demo I placed together.


#4

@krvarma thanks for doing this, not too many people to turn to that are using XBees and spark. Having this gives me hope.

I have Arduino talking to 8 XBees in sleep mode but wanted to go to core with wifi, this will do the trick. Hope to give back someday.


#5

Very cool, thanks for sharing! :slight_smile:


#6

@krvarma, Is it possible to use XBee (series 1 or 2) in a point to multipoint architecture? For example, the master will sit with Electron, while the slaves will be connected to the sensors. The master (or coordinator) will receive data from the slaves (and pass it to the Electron) and and will also send command received from Electron to the slave for execution by the actuators.

Also, if this is used to build a product, how easy can the slaves be paired to the master on the field, without the need to start “coding” on the field during installation?


#7

@Donwhale, yes it is possible. You can use one Coordinator XBee connected to Electron and all others configured as Router/End Node for this purpose. As long as all these moduels use same PAN ID it is possible to create a Mesh Network using Coordinator XBee and Electron.

For pairing an very simple approch is to listen for incoming packets and maintaine a list of XBees attached.


#8

Thanks @krvarma. But how does this work in a commercial product? During factory production, does it mean all products will be set to the same PAN ID? And in that case, what happens in an apartment building where two different people are using my product, will customer A’s end point latch on to customer B’s coordinator since they all have the same PAN ID?


XBEE 868LP API mode communication with Particle Photon SPI mode
#9

I’d assume that you’d need to provide a way for pairing new devices to the Coordinator XBee which either got a unique PAN ID at factory or can be set on first setup.


#10

@Donwhale, you can hardcode PAN ID while setting up the Xbee Modules, take a look at this link and see this is what you need

http://www.digi.com/wiki/developer/index.php/Hardcoding_a_fixed_XBee_PAN_ID


#11

Thanks @krvarma.

In case I have 1 coordinator and 2 endpoints in a network. If Endpoint A has two sensors (i.e. temp and light sensors), using the GetAnalogue command, how do I differentiate between the Temp pin and the Light pin, and how do I differentiate between Endpoint A and B when sending or receiving commands…

Also, If I want to use an app like Blynk to control or read the Xbee pins, how can the pins be addressed on the app? Virtual Pin or Pin number?


#12

@Donwhale you can use API frames to determine which xbee, pin etc… Configure xbees in API Mode, the API frame structure explains these.

Let me know your progress.

Cheers!


#13

Thanks @krvarma, I’m presently reading a book titled “A practical guide to ZigBee Mesh Networking Protocol - Building Wireless Sensor Networks”.

There is a section on API in the book. I’m sure I will have more understanding when i’m through. Thanks for your guidance. If I have any more questions when i’m done, I will let you know.


#14

3 posts were merged into an existing topic: Sudden SOS fault on previously running code