Project tutorial
HBus Home Automation And Artik

HBus Home Automation And Artik © MIT

DIY home automation with some IoT spice.

  • 2,581 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

Introduction

This project is a follow-up for my home automation project HBus.

As many home automation projects was created for personal use and later expanded with additional features. I want to mantain things as easy as possible because I want to use it in real home for daily use with other people.

Main system is enough stable to be used as autonomous home automation system and Iot sensor network.

Now I want to demostrate how to connect local HBus system with cloud services as Samsung Artik.

As example project I will use 2 HBus nodes one on raspberry and one on Arduino communicating each other through RS485 line.

Each node will have a sensor, (DS18B20 for raspberry and DHT11 for Arduino).

Raspberry node will have also a push button as local input and a led as local output.

Raspberry node will communicate through local network with another computer (Raspberry or Linux/Windows pc) running Node.Server that will act as gateway to external services.

I will not cover os/ambiente installations and security aspects as configuring firewall, router etc. All examples requires normal access to internet for computer running Server part.

Prerequisites

  • One raspberry with debian Wheezy and mono installed.
  • Another raspberry with debian/mono or a normal pc with linux + mono or windows 8/10.
  • Arduino Ide to compile/upload sketeches
  • Visual studio 2015 to compile dot net libraries and executables
  • An artik account to create devices and rules
  • A twitter account to send twit after button press (optional)

1. Set up raspberry node

Raspberry node will read local temperature sensor and input button and will show output through a led, all connected through GPIO. Is possible to use a software only configuration to quickly test architecture without eternal hardware.

1.1 Temperature sensor

Connect DS18B20 as indicated :

This a default configuration for this type of sensor.

1.2 Led and button

Now connect button and led:

Raspberry connections are finished, we can configure HBus node.

1.3 Get HBus software

1.3.1 Download DotNet libraries and executable from my GitHub repository

1.3.2 Compile solution if you have visual studio 2015 and copy executables of HBus.Node.Console project into a local folder of raspberry. eg /home/<user>/hbus

1.4 HBus configuration

Node configuration is defined with node.config.xml file.

Main parts are:

  • info : contains global node information. For this example you can leave values as downloaded or change as you prefer. only warning is maximum name length is 5 characters for arduino compatibility.
  • hal : is the real implementation of Hardware Abstraction Layer, use
   <hal type="HBus.Nodes.Hardware.ConsoleHal, HBus.Node"> 
     <parameters /> 
   </hal> 

If you don't want to use external hardware or use this if you want to use GPIO

   <hal type="HBus.Nodes.Hardware.GpioHal, HBus.Node"> 
     <parameters> 
         <parameter name="pins" type="" value="@pins" /> 
     </parameters> 
   </hal> 

Note parameter value @pins is a metavalue that is recognized from configurator as node pins to be passed into constructor;

  • bus : is the HBus configuration and is defined from a one or more HBus ports implementations. For this example we'll use PortSerial and PortTcp .

Change PortSerial parameters to match serial port of Rs485/USB (you should find name into /dev/tty/ something with USB in its name

Change PortTcp parameters to match IP address of Server node and change listen/transmit ports if needed

           <parameter name="hostip" type="System.String" value="HBUS.SERVER IP HERE" />           <parameter name="listenport" type="System.Int32" value="5000" /> 
           <parameter name="sendport" type="System.Int32" value="5001" /> 
  • pins: defines input/output pins, for this example we need:
<!-- Inputs --> 
<pin index="0" name="CS201" description="" location="lab" type="Input" subtype="InputHighLow" source="CB3_CN8Pin17" /> 

That is pin GPIO17 configured as input triggered in high to low transition. For led pin:

<!-- Outputs --> 
<pin index="0" name="LS201" description="" location="lab" type="Output" subtype="OutputToggle" source="CB3_CN9Pin04" /> 

That is pin GPIO04 configured as output that toggle value when activated.

  • wires : Now configure virtual wire to connect input trigger to output activation:
<!-- LS201--> 
<wire index="0" input="CS201" command="ACTIVATE" trigger ="OnActivate" data="76,83,50,48,49" /> 

When input CS201 is triggered from High to Low transition a ACTIVATE command will be sent to LS201 output.

  • devices : Now configure devices section with one device:
<device type="HBus.Nodes.Devices.Shutter, HBus.Node"> 
  <parameters> 
    <parameter name="openPin" type="System.String" value="P1Pin27" />
    <parameter name="closePin" type="System.String" value="P1Pin22" /> 
    <parameter name="delay" type="System.Int32" value="10" /> 
    <parameter name="hal" type="" value="@hal" /> 
  </parameters> 
  <info> 
    <name>DS201</name> 
    <index>0</index> 
    <description>Main window</description> 
     <location>LAB</location> 
     <class></class> 
   </info> 
 </device> 

A shutter device with open/close time of 10 seconds connected to pins 27 and 22 is defined.

  • sensors : Last part is sensors section:
<sensor type="HBus.Nodes.Sensors.Ds18B20Sensor, HBus.NodeConsole"> 
  <parameters> 
    <parameter name="iddevice" type="System.String"  value="DS18B20 SERIAL NUMBER" /> 
    ...
    <parameter name="scheduler"    type="" value="@scheduler" /> 
  </parameters> 
</sensor> 

To utilize ds18b20 sensor you need to know its serial number (there are many tools and tutorials out there) .

A important note is parameter interval, if set a number > 0 node will read each n second that sensor and send measure to possible subscribers. In this configuration you don't need auto read because HBus.Server will be read sensors sending commands to nodes.

1.5 Running HBus node

Now that all is configured you can run node with mono runtime:

mono HBus.Node.Console.exe

A n example of execution is this:

Note in the image ConsoleHal is used and you can see that shutter is turned off at reset (pin 0 and 1 = 0).

If you press button (or with ConsoleHal press '1') you will see that led (or output on screen) will be activated:

Press 'E' you should see local sensor reading:

Pressing 'i' you will see available local commands (Note: some commands expects more pins, devices and sensors that in this example)

2. Set up Arduino node (optional)

An arduino board is us used as remote sensor with same HBus protocol, you can skip this section if you want to test with only raspberry node.

2.1 Hardware connections

These are 2 examples of node with RS485 interface:

For the tutorial we need first example with DHT11/22 sensor and MAX485 chip (or a prebuilt rs485 to TTL module)

2.2 Software libraries and sketches

  • Copy them into Arduino ide libraries folder.
  • Open sensor_node_artik.ino from HNode library examples:

2.3 Sensor node configuration

Example sketch is already configured so you have only to upload with Arduino ide.

If all is correct on board led will blink 3 times.

2.4 Nodes connection

Now you can connect arduino node to raspberry node with RS485 line:

Now you can read arduino sensor from raspberry node using command 'Q' to read current temperature value. You should see something like this:

In the picture are shown 2 values because DHT11/22 has 2 types of measures and is managaed as 2 separate sensors

3. Create artik devices and rules

As said before you need an artik account before starting to create devices and rules.

3.1 Create devices types

Let's start Artik section defining devices types needed for this example

3.1.1 HBus sensor type

Create device type for the sensors:

  • Set display name : “hbus temperature sensor”
  • Set unique name “hbus.sensor.temperature”
  • Create manifest with 2 fields value (double) and timestamp (double) and no actions. Value unit is “°C”
  • Activate manifest

3.1.2 Hbus device shutter type

  • Now create Artik device type for HBus shutter device:
  • Define a single status field and 3 actions as in figure.
  • Activate manifest

3.1.3 HBus pin type

  • Last type is a HBus pin (input or output). Define as before these fields and actions:
  • Again, Activate manifest

3.2 Create Artik devices

Now that devices types are defined in the developers section of artik website you can define specific devices.

3.2.1 Raspberry sensor

  • Select HBus temperature sensor
  • Create a new device from 'MyDevices' section, with name 'Raspberry sensor'
  • Connect device and generate token

Copy device id device type id and token for later use

3.2.2 Arduino sensor

Create a new device from 'MyCloud > devices' section, with name 'Arduino sensor' and repeate same steps of Raspberry sensor.

3.2.3 Raspberry button

Repeat same steps of Raspberry sensor but use hbus pin type:

3.2.4 Raspberry shutter

Create a new device with name 'My shutter' and type 'hbus shutter device'

Copy device id device type id and token for later use

3.2.5 Twitter device

To create this component we'll use available twitter device type with a valid twitter account:

All devices are now configured.

3.3 Create Artik rules

Now create 2 rules from "My cloud > Rules" section:

3.3.1 Rule 1: close shutter when temperature raise more than 20

3.3.2 Rule 2: send twit when button is pressed

Define rule 2 as follow:

This concludes Artik section.

4. Configure HBus.Server

Last step is to configure HBus.Server with needed artik id saved from last section.

  • Modify host ip with raspberry node ip
   <add key="processor.hbus.host" value="INSERT REMOTE NODE IP" /> 
  • Modify these lines and put id and tokens from last section.
   <!-- temperature sensor--> 
   <add key="processor.artik.devicetype1.id" value="ARTIK DEVICE TYPE ID" /> 
   <add key="processor.artik.device1.id" value="ARTIK DEVICE ID" /> 
   <add key="processor.artik.device1.token" value="ARTIK DEVICE TOKEN" /> 
   <add key="processor.artik.device1.name" value="HBUS SENSOR NAME /> 
   <!-- shutter --> 
   <add key="processor.artik.devicetype2.id" value="ARTIK DEVICE TYPE ID" /> 
   <add key="processor.artik.device2.id" value="ARTIK DEVICE ID" /> 
   <add key="processor.artik.device2.token" value="ARTIK DEVICE TOKEN" /> 
   <add key="processor.artik.device2.name" value="HBUS SHUTTER NAME /> 
   <!-- button --> 
   <add key="processor.artik.devicetype3.id" value="ARTIK DEVICE TYPE ID" /> 
   <add key="processor.artik.device3.id" value="ARTIK DEVICE ID" /> 
   <add key="processor.artik.device3.token" value="ARTIK DEVICE TOKEN" /> 
   <add key="processor.artik.device3.name" value="HBUS PIN NAME /> 
  • Choose Raspberry sensor or Arduino sensor for temperature sensor as you prefer.

Now all is ready to start.

5. Run system

Now that all pieces are ready you can test that things talks each other.

5.1 Test button from raspberry

  • Press hardware button on raspbery. You should see led toggling on and off at each click. No external connections are needed to work in standalone mode.
  • You should see Log information about connection with Artik for 3 devices
  • Now press again button. In addition to led toggle you'll see a twitter message from your account thanks to rule 2:

This a scheme that show sequence of events:

5.2 Test 2: close shutter if temperature raise

Now is possible to test sensors sending data to Artik cloud.

Open 'My Artik Coud > charts' section and add ' My Raspberry sensor' you should see empty chart:

After 1 minute you should see chart populate with new data:

As long as node and server are running data will be sent to Artik. Now you can test rule 1 raising temperature near the sensor:

Before rule 1 has been activated 20 times:

After raising temperature chart show increment:

Rule 1 is triggered (now show 21 times):

On Node.Console shutter is activated to close:

After about 10 seconds shutter motor (pin 0) stops.

Demo video

Final considerations

HBus is thought to be open to different services while it can work autonomosly as standalone system and can be used as simple home automation system where inputs triggered outputs or in mixed way where sensors act as Iot producers that sends data to cloud aggregators.

As example in processors of HBus.Server there also WebSocketProcessor (to help creation of interactive web applications and ThingSpeakProcessor to show another cloud service that receives real time data.

Thanks for the patience of reading until end!

Code

GitHub reporitory for Arduino libraries
This is the Arduino implementation of HBus protocol and HBus node functions
GitHub reporitory for DotNet libraries
This is the DotNet implementation of HBus protocol, node functions and HBus.Server example

Schematics

Arduino and raspberry connections
This scheme is an example of connection of two nodes (Arduino and Raspberry) through an RS485 interface
Arduino%20%2B%20Raspberry%20RS485.fzz

Comments

Similar projects you might like

Monitor Fire and Temperature Using ARTIK Cloud

Project tutorial by Samsung IoT

  • 2,586 views
  • 0 comments
  • 21 respects

HBus

Project in progress by Vincenzo

  • 1,707 views
  • 0 comments
  • 2 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 24,825 views
  • 17 comments
  • 75 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 297,278 views
  • 98 comments
  • 706 respects

AirLock with Artik Cloud

Project tutorial by Akash Ravichandran and Prabhakaran Senthilnathan

  • 2,830 views
  • 0 comments
  • 9 respects

WARAN - Home Automation

Project tutorial by Arjun Ganesan

  • 30,101 views
  • 13 comments
  • 77 respects
Add projectSign up / Login