Arduino & openHAB

1,586 views
Skip to first unread message

Gonzalo Diaz Hernandez

unread,
May 19, 2014, 9:05:09 PM5/19/14
to ope...@googlegroups.com
Hi everyone! I'm a begginer in everything around openHAB but very excited about it.

I'm interested in making my domotic system based in arduinos, don't know yet if through ethernet or serial&RFs. I've been looking around and found a lot. But I would want a simple piece of code with maybe two or three examples let's say a relay, a pulse, a sensor, something in order to plant the seed and start learning from there.

Has anybody did something like this and have an example sketch and configuration? I need the first few steps in order to lauch!!! :D

Thanks!!!!

Scott K

unread,
May 20, 2014, 12:45:26 AM5/20/14
to ope...@googlegroups.com
Hi Gonzalo,
I'm also attempting a similar thing.  I'll describe what I'm planning.

I want to have Arduino sensor nodes spread out around the house with various sensors on them (temperature, vibration, presence, etc...).  These sensor nodes are equipped with a wireless module (RFM69HW).  The sensor nodes report data to a single Gateway arduino, which is also equiped with a RFM69HW receiver to receive the sensor data.  The Gateway Arduino is equipped with a ethernet shield, and uses the MQTT library to send sensor data to OpenHab using MQTT.

OpenHab and Mosquitto runs on a Raspberry Pi, connected to the same lan as the Gateway Arduino.

If you follow my posts, you'll see some of the hiccups I've ran into.  Mostly trying to get OpenHab running on the Raspberry Pi.

All your sensor node information has to go somewhere - it's easiest to use another Arduino to aggregate this sensor data since they can use the same wireless module.  Once the Gateway Arduino has the data, there seems to be more than one option to sending this data to OpenHab.  You might do it via serial connection between the Openhab Server (Raspberry Pi) and the Gateway Arduino, since the Pi has GPIO pins.

I can share what I have so far if you're interested.  Although as of now I only have bits and pieces working.
Message has been deleted

Gonzalo Diaz Hernandez

unread,
May 20, 2014, 6:41:19 AM5/20/14
to ope...@googlegroups.com
Hi Scott!!! Thanks for the quick response..

When MQTT comes to the scene I'm pretty lost.. its all brand new for me here. Do you have an example sketch and config file to share with me so I can maye learn in the go?

What is MQTT in the first place? I now its a communication protocol alright, but its a network protocol?

Scott K

unread,
May 20, 2014, 9:21:27 AM5/20/14
to ope...@googlegroups.com
Well, they nice people who write OpenHab wants to make it useful for as many people as possible.  But you want to use Arduinos as your sensor, and another guy wants to use it with their refrigerators, and yet another wants to use Openhab with their toasters.  You have to have some kind of common way of transferring information to OpenHab.

MQTT is an open protocol for this type of communication.  OpenHab can be configured to talk in a few different languages to devices, one of which is MQTT.  On the Arduino end, it's easy.  You include the PubSubClient library, and sending data to OpenHab is almost like a print statement - the library does all the dirty work for you.  It looks like this:

client.publish("topic_name", data_array);

The Arduino library's implementation of MQTT uses ethernet to send these messages to the IP address of the "MQTT Broker", in my case it's a program called Mosquitto.

I wish I was farther along to have some good code to show you, but I'm still new to this too.  I haven't been successful in getting the Demo program working with just two of my items, so I'm still working on it.

What wireless transceiver are you planning to use?  OpenHub doesn't care of course, but it effects your gateway hardware, and the general performance of your wireless sensor nodes, especially the range and energy consumption.

Gonzalo Diaz Hernandez

unread,
May 20, 2014, 9:56:06 PM5/20/14
to ope...@googlegroups.com
Scott I was thinking of using NRF24L01 modules (if I spelled them correctly lol).

I found this guy in England that has been playing around with Arduinos, NRF24L01 and MQTT. I didn't have time to test his expermiments yet but it seems promising.


Check it out, he has done a lot of things with this stuff!!!

I've been researching a bit and I think I have an idea of my system basic setup.

I'm thinking of using let's say a "master" arduino with ethernet and NRF24l01 and other several "slaves" arduinos with NRF24l01 and relays, sensors, etc. Now this "master" will send commands out to the "slaves" and request data from the "slaves" also and throw it in openHAB.
Maybe have a couple of this "master" and "slaves" architectures around the house.

Each master should communicate to openHAB through MQTT and Mosquitto in the server (i'm just saying this for now I don't know how this works but eventually I will)

Is this reasonable or even possible?
Message has been deleted

Scott K

unread,
May 21, 2014, 12:01:09 AM5/21/14
to ope...@googlegroups.com
Let me try this again.  FWIW, I wish OpenHAB used a better forum.  Google forum is ugly.

I've tried the nRF24L01's, both the high power $7 and the low power $1.50 ones.  They work, but the range is pretty limited.  Two high power modules can make it across the house ok...but just barely.  At least in my testing.

I'm going with a transceiver call RFM69HW.  They're $4 each, and work very much like the nRF24L01's, but instead of 2.4GHz, it's 915MHz.  Much better wall penetration, and goes much further without issues.  The only downside is the RFM69HW is harder to work with.  It's not 5V tolerant.  And the pins aren't standard breadboard spacing, so you have to solder wires to it.

The link you provided of that English guy - that's pretty useful.  He goes into a lot of detail about his test method.  I'm having MQTT comms issues right now, so I'll try his tips to resolve them.  He uses a library I've never heard of, the pair of "nanode" libraries.  Looks like it's a combination of the standard MQTT library plus the ENJ ethernet module library?  Interesting.

What is your server going to run on?  What kind of Arduino are you using?  Any plans for battery powered Arduino nodes?

peter...@gmail.com

unread,
May 21, 2014, 1:47:49 AM5/21/14
to ope...@googlegroups.com
I'm doing something fairly similar to this, using NRF24L01+ modules and RF24Network.

The RF24Network base node is on an Ethernet-equipped Arduino, and acts as a relay between nodes on the RF24 network and the MQTT bus. It subscribes to the "arduino/in/*/*" topic and publishes to "arduino/out/*/*". When openhab wants to manipulate the first switch (id 0) attached to the arduino at RF24 Network address 03, it publishes to "arduino/in/3/0", with a payload describing the desired switch state. The base node receives that from the MQTT bus and punts the payload to the RFNetwork with the appropriate address. Similarly, when the arduino at network address 021 wants to transmit a reading from its temperature sensor, it will send an RFNetwork message to the base node containing the data, and the base will relay that on to the MQTT bus with a topic of "arduino/out/021/0". Openhab would be able to subscribe to that topic and do something useful with the reading.

This is all still in a fairly early state, and currently I only have a single node working, controlling some light switches. But it does work well, and if there's any interest here I'll be happy to finish polishing my current code and get it online for others to poke at.

Ben Jones

unread,
May 21, 2014, 4:39:59 AM5/21/14
to ope...@googlegroups.com, peter...@gmail.com
Hi Peter,

I would be interested to hear/see what you have done. I have a couple of Raspberry Pis running MQTT clients which are working very well at monitoring/controlling GPIO pins (https://github.com/sumnerboy12/mqtt-gpio-monitor) but I need another one or two at different locations around my house and I am looking for a more cost effective solution.

I have played around with RPis for over a year and they are great, but I am hoping for a cheaper alternative for just IO monitoring/control using Arduino.

Cheers,
Ben 


Scott K

unread,
May 21, 2014, 12:04:20 PM5/21/14
to ope...@googlegroups.com, peter...@gmail.com
Ben and Peter,
Speaking as an Arduino user new to OpenHAB, I think there are quite a few Arduino users who are looking for an OpenHAB-esque solution.  It comes up fairly often on the Arduino forum.  Before OpenHAB, I did a lot of reading and research on different ways of getting wireless Arduino nodes on a Home Automation System, and tried a couple of them.

But there are quite a few home automation systems out there, a couple of which are actually geared towards Arduino users, but with less flexibility than what OpenHAB can do.  Unless you actually sit down and dig into OpenHAB, it's hard to quickly understand how to use it to integrate Arduinos.  The range of devices that OpenHAB works with means Arduino integration sometimes gets buried, and there's not really a detail tutorial for how to do Arduino specifically.

I was going to write a post once I get a system up and running, hoping other Arduino users would find it in their search.  It would be great to offer sample sketches and wiring examples, and to collect what other Arduino users on this forum have done w/ OpenHAB.  We're probably making a bunch of the same rookie mistakes with OpenHAB, so some words of wisdom would help future newcomers.

Ben Jones

unread,
May 21, 2014, 4:10:17 PM5/21/14
to ope...@googlegroups.com, peter...@gmail.com
Hey Scott - well I am the opposite of you I think - spent 12 months playing around with openHAB and have written 3-4 bindings of my own. But have never touched an Arduino! I have just ordered a few Arduino Uno R3s + ethernet shields which should be here in a few weeks. How difficult is it to get an MQTT client running on an Arduino? I am very impressed with the MQTT protocol and think it is an excellent tool for controlling/monitoring IO on remote devices. I am already doing this with a couple of Raspberry Pis but want to find a cheaper alternative.

Would be very interested to hear if you have any experience with MQTT on Arduino - I believe this could be a very good way to integrate openHAB with these little boards.

Glen Cook

unread,
May 21, 2014, 4:47:12 PM5/21/14
to ope...@googlegroups.com, peter...@gmail.com
I've played with arduino and mqtt and it's really rather simple to get them talking to an mqtt instance on openhab.

There are currently 2 mqtt clients for arduino, depending on the type of network shield you've gone for. Personally I went with the enc24j60 board, as they are generic and cheap (£4 on ebay or thereabouts). Using this network board requires use of the nanode mqtt library. https://github.com/njh/NanodeMQTT, The other library for arduino MQTT can be found here, but this apparently only works with the more expensive shields http://knolleary.net/arduino-client-for-mqtt/

I put together a pcb (iteadstudio) which allows both an enc24j60 board and a NRF24L01, along with various sensors and got them talking over MQTT to openhab.

I am putting together a bunch of purely wireless sensors that talk over the NRF24L01 network to a root node which has both a wireless receiver and network adaptor.

Cheers

Glen.

Ben Jones

unread,
May 21, 2014, 4:56:07 PM5/21/14
to ope...@googlegroups.com, peter...@gmail.com
Thanks Glen. I have just found the library from Knolleary and have been reading up - it does indeed look very simple. I will check out your other suggestion. Is it easy enough to get nodes talking to one another using NRF24L01? I saw library called RF24NETWORK which seems to handle the networking for these types of nodes - is this what you are using?

So in summary you will just have a single Arduino with an ethernet/wifi shield which does all the 'talking' to openHAB - via MQTT. Then each of your remote wireless nodes will just communicate with the root node via NRF24L01s?

Glen Cook

unread,
May 22, 2014, 2:21:58 AM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
Hi Ben,

Yes, thats is pretty much it. I have 12 wireless nodes at present using the RF24Network, As the root node can only talk to a maximum of 5 other wireless modules, I have a few branches in the tree, the leaf nodes are battery powered, and the send data once a minute, and I have 3 mains powered nodes (that don't sleep) which use the higher powered NRF24L01+PA+LNA modules. 

Currently the wireless network sensors are reporting humidity, temperature, battery level and light, but I do intend to add movement detection as separate sensors, as well as some relay based board to control certain items, such as the kids TV's etc.

I plan to look into having the root node use a raspberry pi, for doing the receiving and dispatching to an mqtt server (still in the planning stage at present), but with adding more sensors, I think the root arduino could get a little swamped.

It's a lot of fun playing with embedded hardware, the only frustration is waiting for the custom pcb designs to come back from china, 3 weeks turnaround, but they are so cheap $15 including shipping for 10 pcb's, it would be rude not to put them on pcb ;)

I've attached a picture of the latest pcb design for the latest sensor (based on the bits on a board design), it's 48x15 and can run on a single AA battery. The small size means I can fit it into a smart little case that is wife friendly when sticking on the walls :P

Some useful links

http://programmablehardware.blogspot.de/ <- My new sensors are based on this variant, although I have made a much smaller PCB (around the size of an AA battery for all electronics)


Cheers

Glen.






Jan-Piet Mens

unread,
May 22, 2014, 8:19:10 AM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
Glen,

> I've attached a picture of the latest pcb design for the latest sensor
> (based on the bits on a board design), it's 48x15 and can run on a single
> AA battery. The small size means I can fit it into a smart little case that
> is wife friendly when sticking on the walls :P

wow, that turns me on! I adore little gadgets. :-)

While I have a bit of experience with Arduinos (also running MQTT),
doing things like programming an ATTINY like you've done is way beyond
me.

Any chance you'd feel like writing up a detailed "howto" (with a
shopping list) for us, including how you did the wireless? I'm sure Ben
and others would appreciate that as well!

(And while I'm pleading: have you considered maybe having a few of those
made for sale (or for gifting to openHAB mailing-list members? ;-)

Regards,

-JP

Scott K

unread,
May 22, 2014, 10:57:39 AM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
Glen,
That is really cool!  That's the level of integration I'd like to get to eventually.  To be honest, the cost of using Raspberry Pi sensor nodes isn't that bad, but it's not practical to have battery powered RPi sensor nodes, and battery powered nodes is what makes the microcontroller route so attractive.  RPi also can't do stuff that require tight timing, but those ultrasonic distance sensors that are $2 shipped :)

Why did you go with the ATtiny microcontroller instead of the ATMEGA328P?  Does ATtiny offer better performance for battery nodes?  Or is it just purely a matter of size?  For us newbies, using a regular ATMEGA328P might be a better route in terms of ease of programming.

I mentioned this in an earlier post on this thread, but I'm planning on using RFM69HW wireless transceivers instead of the nRF24L01.  The high power RFM69HW modules are capable of over 500ft through a couple walls, and operate at 915MHz instead of 2.4GHz.  I had thought the nRF24L01 performance might be effected by wifi traffic.  The RFM69HW library isn't as well tested by the Arduino community as the Glen Copeland's library for the nRF24L01, but from the testing I've done it seems to work well.

When I was testing out the nRF24L01's, I couldn't get them to work on the same Arduino as the Wiznet ethernet shield.  I gave up on it after looking into RFM69HW.  But to other people who are contemplating which ethernet module to use with Arduinos, it seems like the enc24j60 module is the way to go.  I've read they offload some of the processing to the Arduino, but if all you're doing is sending MQTT messages, it's probably not bad.


Jan-Piet Mens

unread,
May 22, 2014, 11:55:36 AM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
> But to other people who are contemplating which ethernet
> module to use with Arduinos, it seems like the enc24j60 module is the way
> to go. I've read they offload some of the processing to the Arduino, but
> if all you're doing is sending MQTT messages, it's probably not bad.

Careful; I've heard reports that Knolleary's MQTT PubSub client won't
work with those! They're cheap, but the IP stack is somehow different
and incompatible. (To be honest, I didn't dig in for lack of interest.)

To be fair, I have heard *one* report that it was possible with patch
here, code there, etc. but no thanks. :)

-JP

Scott K

unread,
May 22, 2014, 12:45:28 PM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
Yes, I think that's why Glen and others recommend using that Nanode library - it's like a ENC ethernet library combined with a MQTT library in one.  Maybe others have run into the same issue.  I was initially puzzled by why the Nanode library combines MQTT w/ Ethernet - maybe the incompatibility with Knollerary's MQTT library was the reason the this ethernet-MQTT library was developed specifically for the ENC module.

Ben Jones

unread,
May 22, 2014, 3:59:42 PM5/22/14
to ope...@googlegroups.com, peter...@gmail.com

On Friday, 23 May 2014 00:19:10 UTC+12, Jan-Piet Mens wrote:
Glen,

Any chance you'd feel like writing up a detailed "howto" (with a
shopping list) for us, including how you did the wireless? I'm sure Ben
and others would appreciate that as well!

I would be VERY appreciative! 


(And while I'm pleading: have you considered maybe having a few of those
made for sale (or for gifting to openHAB mailing-list members? ;-)

That was going to be my next question as well...
 

Glen Cook

unread,
May 22, 2014, 4:30:24 PM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
No problem doing a write up.

I'm still waiting for that latest pcb order to come back in from China, but once I've ensured they work as expected, I will make the gerbers available along with a parts list. People will then be able to place a pcb order direct with iteadstudio to make their own, or possibly a group purchase to get a kit of parts together.

Cheers

Glen.

Ben Jones

unread,
May 22, 2014, 4:52:34 PM5/22/14
to ope...@googlegroups.com, peter...@gmail.com
Sounds awesome Glen. Any chance you could post your sketches so we can have a look? I have a couple of Arduino Uno R3s on the way with ethernet shields which I intend to play around with initially. These will be my first Arduinos so any sort of help in getting started would be great! Thanks for your input into this - sounds like you have a great little system planned/running!

Gonzalo Diaz Hernandez

unread,
May 23, 2014, 7:04:11 AM5/23/14
to ope...@googlegroups.com
That's right!!! Thanks Glen!! 

By the way, anyone that has any arduino sketch and oH config working, as simple as it is, can you post it here with a short and simple explanation?? Maybe we can learn a bit from everyone!!! And build this "How to" as a group.

As i'm a newbie at Arduino and programming I'm needing a little seed from which to grow :D

MQTT and this NRF networks seem great, promising and extremely cheap, but also a bit complicated for me. If I can get my hands on a simple example maybe I can adapt it to my needs. Sort of Arduino and its "example" sketches, everyone starts from there I presume or at least myself.. Uploading each different example sketch at a time, then combining them to play a bit more and afterwards writing your own sketches. 

I want to do that (if possible) with oH and Arduino. I might be asking for too much, I don't know.. but its worth the try.

Thanks!!!

Gonzalo Diaz Hernandez

unread,
May 23, 2014, 11:56:48 AM5/23/14
to ope...@googlegroups.com
Another question that striked me is.. let asume that I have got the network going well.. I suddenly want to add a node in the middle or at the back of one of the "branches". This means I have to modify all the node's sketches in the network?


El lunes, 19 de mayo de 2014 22:05:09 UTC-3, Gonzalo Diaz Hernandez escribió:

Peter Hardy

unread,
May 28, 2014, 10:59:25 AM5/28/14
to ope...@googlegroups.com

On Saturday, May 24, 2014 1:56:48 AM UTC+10, Gonzalo Diaz Hernandez wrote:
Another question that striked me is.. let asume that I have got the network going well.. I suddenly want to add a node in the middle or at the back of one of the "branches". This means I have to modify all the node's sketches in the network?

No. The "Addressing in detail" section of the original author's blog post at http://maniacbug.wordpress.com/2012/03/30/rf24network/ explains it in some detail, but adding new nodes doesn't require any modification to existing nodes.

I mentioned last week that I was working on a library on top of RF24Network to handle different sensors and relay traffic in and out of MQTT. It's in a pretty usable state now, and right now I've got a four node network, controlling light switches, a heater, and broadcasting temperature/humidity readings. OpenHAB is talking to all of it with the standard MQTT binding.

I'm still missing full documentation for handling all of the supported sensor types, but there's some example code that is hopefully good enough to get started. Please let me know what you think! https://bitbucket.org/pjhardy/rf24sensornet

-- 
Pete

Glen Cook

unread,
May 28, 2014, 1:22:05 PM5/28/14
to ope...@googlegroups.com
Excellent work Pete, it's going to take me a little while to digest all this lovely code though :P

Cheers

Glen.

Ben Jones

unread,
May 28, 2014, 4:00:50 PM5/28/14
to ope...@googlegroups.com
Thanks for that Pete! I am still waiting for my Arduinos to arrive but I will have a browse of your code, I am sure it will be invaluable in getting me up and running when they do arrive! Thanks for sharing.
Reply all
Reply to author
Forward
0 new messages