XBee, smartthings, diy-- where to begin?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

Hello adafruit. This is my first post, and hopefully not my last on my journey of DIY home automation and maker stuffs.

I'm not sure how to formulate this post-- but the predicament I seem to fall into is that I just don't know enough to really begin researching my goals and could use some advice on what to read/investigate.

My simple, get my feet wet goal is this: having just purchased a Smartthings hub and installed some commercial z-wave switches, I now want to begin hacking my dumb-devices to integrate with my home automation network. My first idea is to use relays and an XBee radio to co-opt the power button on my media PC so I can send short and long presses from my mobile phone app to power on, off, and force a hard power off on the PC.

I've read the XBee manual, and tried to absorb as many tutorials as I can-- but I can't really follow along with the tutorials because I don't have the hardware yet (which I'm afraid to purchase because I don't know what I'll eventually need or have a clear idea of direction.)

I feel like I could benefit from a mile high description of what my project would look like from someone with knowledge on the matter and then help me by dialing in and pointing me towards the components and strategies.

In the end, I can design and prototype circuits. I can dust off my rusty army-trained electrical engineering skills. I can program in any IDE and API that has documentation. I'm ready to learn and do this. I just find the entry point to be difficult to find.

Please help?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Franklin97355 »

If you are new to this I would recommend an Arduino Uno and accesories, a USB xbee adapter, a regular xbee adapter, Faludi's book and, of course a couple (or more) xbees. For the simplest configuration and use get series 1 xbees and for a more complex mesh network use one of the other series. I'd start with series 1 until you find they won't do what you want. And don't forget learn.adafruit.com

User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

Thank you.

I had just discovered Faludi's book a couple hours ago while scouring google. Ordering that presently.

The link to learn.adafruit.com confuses me... what am I looking at? It looks like chapter headers then exercises, but no actual content. Am I meant to subscribe to something or... what is that? :P

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Franklin97355 »

Sorry, I thought there would be more content. Here is a link to the Digi site with examples and projects http://examples.digi.com/

mullinsyyc
 
Posts: 17
Joined: Fri Aug 29, 2014 10:11 am

Re: XBee, smartthings, diy-- where to begin?

Post by mullinsyyc »

Hello
What you are starting is exactly what I began a few weeks back. SmartThings hub, Arduino Uno, Digi XBee ZB, and an SSR relay, with the goal to make a garage door opener.

Used an adafruit xbee adapter as well.

Well it took some time, mainly writing the XBee code for the uno. There are a few libraries out there, namely the ANSI C library from Digi (https://github.com/digidotcom/xbee_ansic_library) and a third party called xbee-arduino (https://code.google.com/p/xbee-arduino/) .

The problem I found with both the above libraries is they did not implement Zigbee Cluster Library (ZCL) to parse the communication. Or at least in a way I could understand. This post in another language helped me parse the data: http://forums.parallax.com/showthread.p ... c-profile)

The one thing I found critical to my success is using softserial to write out the hex values that the xbee was receiving. That allow me to know what to parse. To do this I used the FTDI friend found here at adafruit https://www.adafruit.com/products/284 . Once I connected this up, I was able to make better progress.

Plenty of reading the network book and zwave specs.

Finally last weekend I was able to get my prototype to work! Garage door opens and closes using the smartThings App and HUB talking to XBee mounted on an UNO.

Here is what the prototype looks like. The three LEDS on the right were green = receiving data, yellow = processing, red = errors. The lite red was door closed and the green was for open.
2014-09-27 20.58.26-2.jpg
2014-09-27 20.58.26-2.jpg (439 KiB) Viewed 3066 times
Not sure I can help you a whole bunch as I'm learning myself but if you have any specific questions around what I might have done please ask away.

Good Luck!

User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

mullinsyyc, I'm curious if you could offer me that mile high view of what your project is doing. Like, if I just said, "neat, how's that work?" Can you give me the simple run down of what's going on with your project? What's communicating with what? What's processing what? How did you get the XBee to connect to the hub? How much of the API functionality are you actually using? What was the most fascinating thing you learned during the process?

I kind of want a simple roadmap to help focus my goals.

Make sense?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: XBee, smartthings, diy-- where to begin?

Post by adafruit_support_mike »

To give you at least a a toehold:

From a quick skim of the Smartthings documentation, it looks like the hub supports many different communication protocols, but one of them is the ZigBee protocol.

ZigBee is a wireless network and transport protocol built on top of the 802.15.4 standard for low-power wireless signal transmission. If you know your OSI network model, 802.15.4 is down at the physical layer telling devices how to talk to each other. The ZigBee protocol spans the network and transport layers.

A ZigBee network requires a 'controller' device which it the primary source of authority for how the network is arranged. It basically tells the other devices who they are and where they fit into the network. I can't say this with absolute certainty, but it would really make sense for the Smartthings hub to act as the controller for a ZigBee network.

I've chosen ZigBee as a place to focus because the XBee Series 2 devices also speak the ZigBee protocol, and Faludi's book focuses almost entirely on XBee S2 devices.

The XBee 2mW Series 2 module is probably the best one to start with:
https://www.adafruit.com/products/968

It costs less than the higher-power 63mW version, but still has a line-of-sight rating of about 100'. It will give you enough hardware to talk to the network without weighing you down in a thousand additional details.

Start by learning how to make your computer talk to the XBee, then move on to making the XBee talk to your Smartthings network.

mullinsyyc
 
Posts: 17
Joined: Fri Aug 29, 2014 10:11 am

Re: XBee, smartthings, diy-- where to begin?

Post by mullinsyyc »

For whats communicating with what and a mile high view...I have is an xbee Pro S2B, model #XBP24B7WIT-004, enrolled to the SmartThings hub. Once configured correctly on the SmartThings Web with a device type, etc. it creates a button in my SmartThings app. The type of zigbee device I'm creating is an on/off. When I push the button on the SmartThings app, the configuration on the SmartThings Web (device types) determines what to do and in this case, the hub sends a zigbee command to the xbee. The Arduino reads the command from the xbee, parses it, determines what to do (open door = on, close door = off), and sends a Arduino pin command to the relay pin to open the relay for a configured amount of time. The other half of the relay is connected to the terminals on my garage door opener, and the door opens or closes, as expected.

There is a lot of detail in this post: http://forums.parallax.com/showthread.p ... artThings-(communicating-with-the-ZigBee-HA-public-profile
Have a read of this. It's really a step by step how to do it, including the code for the SmartThings web for an on/off. It will also give you all the proper XBee firmware (Router API, is what I used) along with all the XBee settings, baud rates, encryption keys, codes. It's very good and will be a great help. Its just not in Arduino...I have been basically taking this code and 'converting' it to Arduino .

In Faludi's book, page 1, buying a radio, he recommends to by a Series 2. As in the previous post they are harder to use, but my understanding to run in API mode, you need series 2. Have a read through Chapter 5, API and a Sensor Network. It talks about the protocols and API frame types. I am getting a type 0x92 from the smartThings hub. It is a ZigBee Cluster Library (ZCL) Request as per the spec for on/off controls. This will appear like on page 129, ZigBee Receive Packet. They are all read from the xbee by the xbee-arduino library and then I wrote the part to parse the command. I just could not find a xbee library that did the ZCL stuff. From digi, the ansi-c library has a zcl.h and zcl.cpp but they are not completed.

You must also get the x-ctu app from digi. http://www.digi.com/products/wireless-w ... dules/xctu
It will allow you to configure your xbee. It is also very helpful as you will be able to connect to your xbee and see the packets of data being sent and received. For me, I had two xbee enrolled in my smartthings, one connected to x-ctu where I could see the data being received and one connected to Arduino for the project.

To get the Xbee to enrol in the hub:After using the digi supplied x-CTU application to program the xbee with the correct configuration and flash the right firmware, you just have to connect the xbee to a power source and get it broadcasting. I connected mine to my laptop via a FTDI to USB cable bought here on adafruit. My xbee was also mounted on the XBee adapter bought here also. These adapters help control the power down to 3v from 5v and take that problem away. In the picture above you can see the xbee mounted on the adapter. Once you have your xbee powered and broadcasting, SmartThings recommends being within 15 feet of your hub. Go to your app and click the plus sign. After a short wait the app should show something to enroll. Click on it and it will now be visable in the smartthings web. Next is to add in the device type code and make the association to the device...a button will be now in the app.

A simple path is what I was looking for as well. I spent a lot of time trying to figure of the lower level codes to understand what the xbee was doing. For me the break though was getting that softserial connection (previous post) connected so I could echo what the arduino was reading and be able to debug what was going on. For the first few weeks I was blind and getting frustrated. My simple path was a 'hello world' prototype to get a led to light if any data was received. Success, great. Now is it the correct data and then begin to parse it out. It was a happy sight just to see the data light go on the xbee when I pushed the app button...Slowly working from have connection, reading data, it's the correct data, parsing data, acting on parsed data. That was my path.

Fascinating thing I learned...Well being new to electronics but not to technology, I had never heard of xbee, zigbee or 802.15.4 spec. We all have known about 802.11 or wifi, but the capabilities with the mesh networks is very cool (IMO). As this was a DIY project it was more about the learning and the experience. When things got frustrating it was like, why dont I just go buy something for half the price that already done and be done...but it was a good learning eperience that will lead to other DIY projects in home automation, other hubs beside smartthings, other radios beside xbees.

Next I want to send a command back to the hub as well as be able to read the state of my door and tell the hub what it is for when someone opens the door with a remote or pushes the wall button. The hub has no idea right now that these have happened and the smartthings app shows closed when opened by the normal remote.

Not sure I answered all your questions but have a read of the other post it will fill in a bunch of details to get your hello world, smartthings app communicating. Then its all up to your imagination!

User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

Yay. I'm excited to get started. Just waiting for my first two xbees and adapters to arrive. I'll be decommissioning one of my Arduino Nanos from my laser tag prototype.

Been reading Faludi's book.

Thanks for the guidance. I feel I have a much clearer direction and sense about things. Here we go.

I'll drop questions here in the thread if they come up.

Thanks everyone!

User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

Ok! I've got 2 Xbee series 2. I went through a few basic exercises- got them talking to each other.

I went through that propeller post and got one of my xbees configured appropriately.

mullinsyyc, I'm wondering about the enrolling part. Can I just enroll an XBee radio as a simple test? "Once you have your xbee powered and broadcasting..." How do I get it broadcasting? Simply having it plugged in doesn't seem to make it visible to the hub. What did you do at that step?

mullinsyyc
 
Posts: 17
Joined: Fri Aug 29, 2014 10:11 am

Re: XBee, smartthings, diy-- where to begin?

Post by mullinsyyc »

Yes, if you have the xbee configured properly, you can get it added as a device in smartthings.

This is what I did was:
Using the Digi x-ctu program, flashed the router API firmware for the correct model.
Used the x-ctu program to configure the xbee with these settings:
ZS ZigBee Stack Profile: 2=ZigBee-Pro. This is required to communicate with a ZigBee HA network
NJ Node JoinTime: 0x5a This setting allows devices to join a network it must not be at the default or it will allow devices to join at any time causing a security problem.
EE Encryption Enable: enable. Security has to be enabled to join a ZigBee Home Automation network
EO Set Bit 1 = 1. This will force the network security key to be transmitted encrypted.
KY Encryption Key = 0X5A6967426565416C6C69616E63653039 This is the encryption key for all ZigBee Home Automation networks. It is required to join the SmartThings hub and other standard ZigBee Home Automation networks. I will discuss the security keys and joining process in a future post.
BD Baud Rate is set to 115200
D6 is set to RTS flow control. The Propeller ZigBee Home Automation driver uses RS232 hardware flow control to communicate with the xBee. It is possible to get by without flow control but there is a lot going on and it is best to not miss any packets so it is worth the two extra wires on your board.
AP API Enable = true
AO API Output Mode = 3 ZDO pass-through

Once set, write the settings to the xbee.

At this point make sure your xbee is powered up. To do the enrollment SmartThings recommends for the xbee (device) to be withing 15' of the hub. When this is true, use the smartthings mobile app main screen to click on the plus sign at the very bottom. On the next screen select 'connect new device'. This will tell the hub to search for a new device. The hub will find the xbee and you will see on your app that a new device has been found. Some of my enrollments took a few minutes to find. Click on it and follow the prompts to complete enrollment. Once this is done you can go to the SmartThings web and see the new xbee on the device page.

If through this process you have the xbee connected to a computer or laptop running the x-ctu program, connect to the xbee in the program on the serial tab. You will be able to watch real time the communication between the two. As well if your using the adafruit adapter, the red data light will be lighting indicating data has been received.

Hope this helps

User avatar
Sinaz20
 
Posts: 6
Joined: Wed Oct 08, 2014 5:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by Sinaz20 »

Ah! Finally! The XBee needed a reset, and now it's connected as a "Thing" and receiving Many-to-One Route Requests.

I'm in!

mullinsyyc
 
Posts: 17
Joined: Fri Aug 29, 2014 10:11 am

Re: XBee, smartthings, diy-- where to begin?

Post by mullinsyyc »

@Sinaz20

How did you do with your project? Were you able to get it all programmed up?

User avatar
dexterbot
 
Posts: 1
Joined: Mon Apr 25, 2016 3:04 am

Re: XBee, smartthings, diy-- where to begin?

Post by dexterbot »

Hi all.

I am trying to connect an Arduino with 16 relays to the Smartthings Hub, while avoiding the Smartthings shield. Ideally, I would like to see each relay as an individual device (On/Off output) but I am not sure how to proceed. For now, I am trying to set it as a device with multiple EndPoints, but this would imply seeing it as a single device, am I right? So far I have followed George's (http://www.falco.co.nz/electronic-proje ... martthings) and @JohnR instructions from the forums, and got the device to show in the app, near my other Things (although for the last hours there seems to be a glitch even with this).

So, to detail: I send the Device Announcement packet, I receive from the Hub:

ZBExplicitRxResponse:
From: 0xD052A853EE1C0001
From: 0x0000
Receive options: 0x01
Src endpoint: 0x00
Dst endpoint: 0x00
Cluster id: 0x0005
Profile id: 0x0000
Payload: 2A 42 E6 --> all ok, this is a frameId + my xbee address

Next, I report an endPoint (0xBB), and I get back:

ZBExplicitRxResponse:
From: 0xD052A853EE1C0001
From: 0x0000
Receive options: 0x01
Src endpoint: 0x00
Dst endpoint: 0x00
Cluster id: 0x0004
Profile id: 0x0000
Payload: 2B 42 E6 BB --> frameId + my xbee address + endPoint address

All seems fine, it asks for an Endpoint Description, I send a packet similar to George's (ClusterID 0x8004, inClusters 0x0000,0x0003,0x0006), and I get back:

ZBExplicitRxResponse:
From: 0xD052A853EE1C0001
From: 0x0000
Receive options: 0x01
Src endpoint: 0x01
Dst endpoint: 0xBB
Cluster id: 0x0000
Profile id: 0x0104
Payload: 10 25 00 01 00 --> where 0x25 seems to be a frameId, it increases for the next 2 (repeated) packets.

I don't know how to proceed any further. What's with the last packet? (I get the same response, even when I announce multiple EndPoints, and I was expecting it to inquire about all the endPoints). I can provide more details if needed. Thanks for all your help.

edasque
 
Posts: 1
Joined: Thu May 03, 2018 7:11 pm

Re: XBee, smartthings, diy-- where to begin?

Post by edasque »

@dexterbot @JohnR did you guys ever get beyond R&D and got a Arduino and Zigbee based solution going to buy a custom Smartthings sensor?

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”