element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog [Dynamic Living-room Lights] The YUN talks to OpenHAB
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ipv1
  • Date Created: 6 Jan 2015 11:56 AM Date Created
  • Views 3051 views
  • Likes 3 likes
  • Comments 10 comments
  • iot_ip
  • iot_holidaylights
  • holiday_mood
Related
Recommended

[Dynamic Living-room Lights] The YUN talks to OpenHAB

ipv1
ipv1
6 Jan 2015

  • List of previous posts
  • Preface
  • Installing OpenHAB and Mosquittoe
  • Configuring the YUN for MQTT
  • Making OpenHAB talk to the YUN
  • More to DO

 

List of previous posts

  • [Dynamic Living-room Lights] Description
  • [Dynamic Living-room Lights] Simple System Design
  • [Dynamic Living-Room Lights] The YUN review - When the Penguin Met The Arduino.
  • [Dynamic Living-Room Lights] The Infineon RGB LED Shield Review
  • [Dynamic Living-Room Lights] The Infineon RGB LED Shield -Library!
  • [Dynamic Living-Room Lights] The Lights Teaser Video

 

Preface

 

My project for the Internet of Holoday lights was based around our living room which was not very livable. It was a mess and with the upcoming holidays I wanted to set the living room in such a way that it would be suitable for entertaining guests. Additionally I wanted to accomplish the above mentioned in such a way that the holiday lighting becomes part of the living room and I don't need to remove it after the holidays. Hence the concept of Dynamic Living-room Lighting.

 

In the previous posts, I have review the YUN and the infineon shield and have presented an overview of the project system. I also setup the place for the lighting with some homemade arts and crafts.

 

In this post, I will explain the control of the RGB LED strips attached to the arduino YUN and connected to an instance of OpenHAB. This instance of OpenHAB is running a raspberry Pi and an MQTT broker.

 

Installing OpenHAB and Mosquittoe

 

For the Forget Me Not Challenge, I used OpenHAB as the center piece and details can be found at

 

The "Forget_What ?" project - Index

 

I did various tutorials on installing and using OpenHAB and I suggest going through them if interested. Once you have installed it, you can install addons for such as MQTT etc. Additionally, I installed Mosquitto MQTT broker but you can use iot.eclipse.org:1883 . My reason for installing a local MQTT broker was the ability to work in the absence of an internet connection.

 

image

Configuring the YUN for MQTT

 

Benjamine Cabe did an excellent post at Controlling Holiday Lights using MQTT and the Arduino Yún and the code is available on github. For my experiment, I changed the subscribed topic according to my requirement. The rest of the code is more or less the same. The code can be downloaded at https://github.com/kartben/internet-of-holiday-lights

 

Once you have setup the YUN with the code and into your network, you can open up a serial monitor in the Arduino IDE by pressing Ctrl+Shift+M

 

You will also need a program to test MQTT off the bat. I choose MQTT Lens which is a Google Chrome Addon. Point it towards the MQTT Broker and you should be done.

 

image

The screenshot above shows how to control the YUN with the code supplied by Benjamine Cabe as is. Just send RGB values and you are good. If you send 000000 then the LEDs switch off and if you send ffffff then the LEDs turn on full brightness hence the white color.

 

Now you should be able to see the results almost instantaneously and if you don't try and see if the YUN is connected to the internet or not. The serial monitor can help you debug that.

 

Making OpenHAB talk to the YUN

 

It took me a little while to get this up and I am not completely happy with it, but its a goog start for the lazy man. The task is to format the MQTT messages just like Cabe Sir's application reads so we can use the YUN Code directly. Its actually quite easy.

 

The first thing we need to do is create an Item in the .Items file. This just creates a place to house the data for OpenHAB. I created a simple item as follows.

 

Color      Hue                      "IP Hues"                                      <colorwheel>      (All)
String            HueMqtt                  (All)            { mqtt=">[eclipse1:ip-led:command:*:default]"}

 

Note that I have a color wheel object that can store the RGB values and a string object that will store the string to be passed to the YUN. The '{' indicates that a binding has been employed which is mqtt. > specifies that the direction is outwards. eclipse1 is my name for the MQTT connection configuration stored in the openha.cfg file  and ip-led is the topic. You can change this to match your topic such as /IOTLights/LEDs1 etc. Please note these are case sensitive. Next it will send whatever (*) command this object gets. You can specifify conversions here using XLS but I choose to do all that in the rules segment.

 

The second thing we need to do is make it a part of the UI. You can see there is a segment in the above screenshot for the IOT Holiday Lights and is labeled YUN. To make that, we use the following code.

 

sitemap demo label= "Main Menu"
{


// All my other stuff//
// IOT Holiday Lights Frame
Frame label= "IOT Holiday Lights"{
            Text label= "YUN" icon= "yun "{
                  Frame label= "Yun Control"{
                        Colorpicker item= Hue icon="slider"
                  }
            }
      }
}

 

I downloaded the icon from the net and put it in the OpenHAB/webapps/images/yun.png . The resulting sub frame is shown below.

 

image

 

image

So now we have a color wheel. Brilliant!

 

The Third step is creating rules to connect the Color Wheel to the MQTT topic via the String. This is where all the fun stuff happens and for my instance my code is given below.

 

 

import org.openhab.core.library.types.*


// Stuff for the IOT Holiday Lights
var HSBType hsbValue
var int Brightness
var String redValue
var String greenValue
var String blueValue


// ********************* IOT Holiday Lights ****************************
rule "YUN Lights MQTT"
when
      Item Hue changed
then
      hsbValue = Hue.state as HSBType


      val Red1 = hsbValue.red.intValue
      val Green1 = hsbValue.green.intValue
      val Blue1 = hsbValue.blue.intValue

      redValue = Red1. toString(16 )
      greenValue = Green1. toString(16 )
      blueValue = Blue1. toString(16 )

      val Tmp = redValue + greenValue + blueValue

      sendCommand(HueMqtt, Tmp)
end

 

The rule can be named anything and I created some variables globally in case I want to use the values somewhere else as well. When the item Hue changes, we extract the color values after converting the object's state to HSBType. The color values are extracted as integers and I use local variables for some experiments later. Lastly, we convert them to strings but of base 16 since Cabe Sir's code reads hex values only. Club them together and send them across. Thats it!

 

It works as is and I tested it out with the same YUN code.

 

image

 

More to DO

 

At this point I am not very happy with the way messages are sent on MQTT. I am used to writing more lower level protocols but here I need to extend the use of MQTT to send elaborate commands to the YUN which will in turn control some other things. At the time of this writing, I have already made changes to the above code and only documentation remains. This post will complement kartben '  post and will use OpenHAB to control it out of the err.. github.

 

Comment if this helps you.

 

Cheers,

IP

  • Sign in to reply

Top Comments

  • kartben
    kartben over 10 years ago +3
    I would highly encourage you to have a look at Google Protocol Buffers. I believe this would help to structure messages just like what you suggest with a Modbus-like protocol. Also this would allow to…
  • ipv1
    ipv1 over 10 years ago in reply to Jan Cumps +1
    For IOT apps MQTT is perfect and allows for messages to be exchanged with a small network footprint. Its useful for continuous data flow. I use it to propagate commands to the YUN and it becomes extremely…
  • Jan Cumps
    Jan Cumps over 10 years ago in reply to ipv1 +1
    Looking forward to that post. Have fun!
  • ipv1
    ipv1 over 10 years ago in reply to mcb1

    Mark sir,

    Many thanks. I looked at google protocol buffers and I may fork it once this is all over since its a good learning point for me as well.

     

    OpenHAB is really very powerful especially with it;s rules engine. I am redoing some parts of the project which may land me trouble...

     

    Thanks again,

    Cheers,

    IP

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to kartben

    kartben

     

    Very nice link thanks Benjamin

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago

    Inderpreet

    You've provided some very good information in this post.

     

    For anyone not familiar with OpenHAB I suggest you visit the Forget Me Not Challenge

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 10 years ago in reply to kartben

    I'm going to look into that. I'm an xml fanboy (not for the format per se, but for some good libraries and the way you can work with it in java - and yes, because you can hand read and write it)..

     

    If Protocol Buffers work for Google, they should be ok for me too.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 10 years ago

    Nice post.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube