Click here to Skip to main content
Click here to Skip to main content

Home Automation Using Smart Connector

, 12 May 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This article explains how to create Smart Home which is controlled by RaspberryPi devices connected via SmartConnector.

Please note

This article is an entry in our Windows Azure Developer Challenge. Articles in this sub-section are not required to be full articles so care should be taken when voting. Create your free Azure Trial Account to Enter the Challenge.

Table of Contents

Introduction 

This article will explain how to use Smart Connector to connect various devices to create connected system. This article will also explain how to make your home a Smart Home by making use of Open Source Hardware and connecting them together by the greatest cloud platform The Azure. In today's world we have many open source hardware platform available eg. Raspberry Pi which are cheap and by making use of this platforms we can build a always connected environment which can make our day to day tasks easy.    

Background 

There are various open source hardware devices which are cheap and if we get this devices connected via simple process which provides real time communication then it will be great system. So this is idea behind SmartConnector which provides simple process to connect various devices together.  

Why Azure

To make the always on connected world which communicates in real time, Azure provides just the things needed, like WebSockets, without having to worry about scalability, performance, infrasturcture etc.

How It Works 

As explained in above diagram we can see that Smart Connector Server is the heart of the system which provides communication between all the devices. Users have to signup on SmartConnector and create apps. Once the app is created click on it to get details related to that app which also includes API key for the app. Once logged in you can click on users link and you will be directored towards user managemenent pages wherein you can add users who will be using your apps. Once all the subusers are added then you can associate users to apps which you want them to be accessible. When any subuser will log in to the SmartConnector then he will provided with the list of apps to which he has access and once he clicks on any of the app he will be provided with the list of devices which are connected to this app. Now user can send & receive data from the device if he have been given right to do so.

All the raspberry pi devices are configured to connect to perticular application by using its API key and once it is connected to app then it can be controlled by anyone who have access to it.

Below image describes brifely about the how a user will interact with Smart Connector.

Below image describes brifely about the how a sub-user will interact with Smart Connector.

Now lets understand how the user is going to use the client application to make use of Smart Connector.

1. Log In: User logs into the system by using his/her username and password.
2. List of Devices: User will be provided with the list of devices for which he have access.
3. List of Operation: When user clicks on any device he will be provided list of operation he can perform on device.
Eg. Turn the bulb connected to GPIO pin 16 on or off is one operation provided by the device.
4. Details of The Operation: When user selects any operation he will be provided with details UI for that operation.
Eg. Current state of bulb connected to GPIO pin 16 and button to toggle the state of this bulb.
5. Charts for Operation: User can also see the status of any sensor connected to raspberry pi.
Eg. If thermostate is connected to Raspbery Pi then user can see the status of it in temperatures for whole day/week/month.
6. Dashboard: User can also see the status of all the sensor connected to any perticular device for last one day/week/month.

Components 

The Server:
The server acts as a middle person between all the devices which wants to communicate with each other. The server keeps track of all the registered users, their apps and the devices which are registered to be used with particular app. It provides the communication between all the connected devices via WebSockets if available other wise the connection will fallback to long polling so that maximum number of clients will be able to communicate.

The Clients:
The clients can be the Raspberry pi device which is connected to server or a mobile/laptop/desktop device which wants to control the connected device or get the status of connected device.
The clients can be of two types

1. As a Device:
This role is applicable to Raspberry Pi which connects to server and waits for messages from server. As a device role raspberry pi will be configured to send commands to its GPIO pin when any respective message is received from server. It can also send the status of any GPIO pin back to server to show the current state of any particular GPIO pin.
Eg. When raspberry pi receives a message from server as "PIN16-ON" then is send the high value to it's GPIO pin number 16 and when it receives message as "PIN16-OFF" it will send the low value to it's GPIO pin number 16.

2. As a Controller:
This role is applicable to user who want to control any of the connected device using mobile app or laptop/desktop browser.
Eg. If there are three raspberry pi devices connected to server and user want to send a low command to GPIO pin number 16 of first raspberry pi then he can use mobile or desktop browser to do so by clicking on first raspberry pi device from list and clicking on toggle button for it.

Using The Code

To start using SmartConnector you have to Sign up on SmartConnector website and get your application key. You can add various devices in your application by logging into administrator account and can give a unique device ID to each device so as to use it to send and receive message from this device. Once you have your app-id and device-id with which you want to connect then you can follow below tutorial to get it connected. 

Include the SmartConnector JavaScript library  

<script src="http://smartconnector.azurewebsites.net/scripts/1.0/smartconnector.min.js"></script>    

Open Connection to SmartConnector 

var smartConnector = new SmartConnector('YOUR_APP_KEY');  

Get the list of devices that you have added in your app 

var deviceList = smartConnector.GetDeviceList(); 

 Subscribe to a device using it's ID.  

var raspberryInLobby = smartConnector.subscribe('RASPBERRY-PI-IN-LOBBY'); 

Listen for messages from the device.  

raspberryInLobby.bind('my-message-type', function(data) {
  alert('A message was recieved from the device: ' + data.message);
}); 

Send data to Raspberry Pi in Lobby

raspberryInLobby.send({
    type : "my-message-type",
    message : "PIN16-ON"
}); 

References 

1. Real time communication using WebSockets.

2. Raspberry Pi.

Conclusion

It is very easy to setup a always on connected network using Smart Connector and as explained above the making a Smart Home is the type of example using Smart Connector.

Future Plans

In future support for some more open source hardwares will be provided to take advantage of Smart Connector which includes BeagleBone, pandaboard etc.

History 

May 2 : Updated "How It Works" along with examples.
April 30: Created Initial Draft

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sagar B. shelar
Software Developer
India India
No Biography provided

Comments and Discussions

 
Questionthis link is broken u gave PinmemberTridip Bhattacharjee9-Jul-14 22:13 
Generalgreat idea ... PinmemberSwapnil Shrikhande16-May-13 4:00 
GeneralMy vote of 5 PinmemberSwapnil Shrikhande16-May-13 3:55 
GeneralMy vote of 5 Pinmemberroscler29-Apr-13 2:45 
GeneralRe: My vote of 5 PinmemberSagar B. shelar29-Apr-13 22:28 
GeneralRe: My vote of 5 Pinmemberroscler29-Apr-13 23:03 
GeneralRe: My vote of 5 PinmemberSagar B. shelar29-Apr-13 23:57 
GeneralRe: My vote of 5 Pinmemberroscler30-Apr-13 0:06 
GeneralRe: My vote of 5 PinmemberSagar B. shelar30-Apr-13 0:15 
GeneralRe: My vote of 5 Pinmemberroscler30-Apr-13 1:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 12 May 2013
Article Copyright 2013 by Sagar B. shelar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid