Wednesday, 4 November 2015

Setup Wireless Sensor Node: Setup Sensor Node Part 2

It is hard to write a template of code that can be use for every sensor, since some sensor using digital input, analog input as well as You can check my source code here at codebender

This is an ongoing project and this list will keep growing but as for now I only done writing code for interfacing WSN with:
  1. DHT22 --- Temperature and Humidity Sensor
  2. BH1750FVI --- Light Intensity Sensor
Algorithm that I use are following the discussion at part 1. 


Tuesday, 3 November 2015

Setup Wireless Sensor Node: Setup Sensor Node Part 1

Basically every sensors that can interface with Arduino can be used as a wireless sensor node with the addition of serial Bluetooth connectivity (HC-05). To push sensor reading to the gateway we need to understand:
  1. Operation that is done by the gateway to collect data. 
  2. Type of data that those sensors produce.
  3. Numbers of sensors that is connected to the single Arduino's Board.
  4. Packet protocol that are used to transmitting sensor reading to the gateway.

Heartbeat method: Operation done by gateway to collect data

What can I share with you here is the best practice that I usually use known as Heartbeat method. You can read more at here and here, which are to my understanding are a method that enable base/leader/master/sink node to know the availability of the other node in its local network cluster by sending a "pulse" signal at a regular interval of time. If a heartbeat signal from targeted node isn't received for a time, the machine that should have sent the heartbeat is assumed to have failed. 


By using this method I modify the "pulse" signal to be a command signal. Commanding the targeted node to send sensor reading as well as monitoring the life of that node. The targeted node will reply back the sensor reading and if it doesn't reply back that node are consider as dead. This is like a master/slave method where, Gateway will become a master and sensor nodes as a slave. This method also allowing the whole system from sensor nodes to the cloud database to be in sync which each others. 



Don't worry, this heartbeat process are monitored by SensorGate apps what important is you know some of the basic algorithm.



String of Character: Type of Data that those Sensors Produce
Always use string of character to represent reading for each sensors, no matter if its float, int, char, double, or Boolean, change it to string of character. If you are using an Arduino, usually for each of the sensor you are using, it will come with the tutorial on how to interface with it and a source code to get that sensor reading. But many of those source code doesn't change the reading to string of character, which is your job to find a method to change your reading value to String of Character. I will show this at the next post. 


Number of Sensors: As long as their is a pin to Interface
As long as their is enough pin to interface with those sensors it can be used. You just need to build the sequence to listen to each of those sensor and change it's reading to a String of Character for that sensor. 


Packet Protocol
Packet protocol that I use for this system are: 

        var1,var2,...,varN:VALUES:'values1','values2',...'valuesN'

For example:

        Temp,Humidity,LightIntensity,Motion:VALUES:'34','20','10','1'

This string packet are made based on SQL format, the idea is to provide a flexible method to store and push data to the Fusion Table database. 

On the second part I will show you the template for Arduino Script for wireless sensor node. 

Monday, 2 November 2015

Setup Wireless Sensor Node: Setup Bluetooth Connectivity

You can follow this TechBitar Guy method or you can read more here.

Step 1: Component and Wiring


Parts:
Wiring:
  • HC-05 GND --- Arduino GND Pin
  • HC-05 VCC (5V) --- Arduino 5V
  • HC-05 TX --- Arduino Pin 10 (soft RX)
  • HC-05 RX --- Arduino Pin 11 (soft TX)
  • HC-05 Key (PIN 34) --- Arduino Pin 9

Step 2: Component and Wiring
This Arduino program (HC_05.ino) does two things. It takes the AT commands you enter from the Arduino IDE Serial Monitor and sends those commands to the HC-05. The program then reads the output of the HC_05 and displays it on the Arduino IDE Serial Monitor. You can also use a terminal emulator such as Tera Term instead of the Arduino Serial Monitor. 

The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via Serial Monitor.


#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10,11); // (RX,TX)

void setup() {
     pinMode(9,OUTPUT);   //this pin will pull the HC-05 pin Key high and switch module to AT mode
     digitalWrite(9,HIGH);
     Serial.begin(9600);
     Serial.println("Enter AT commands:");
     BTSerial.begin(38400);   //HC-05 default baud rate for Bluetooth in AT command
}

void loop(){
     //Continuously reading from HC-05 and send to Arduino Serial Monitor
     if(BTSerial.available())
            Serial.write(BTSerial.read());

     //Continuously reading from Arduino Serial Monitor and send to HC-05
     if(Serial.available())
            BTSerial.write(Serial.read());
}


Step 3: Switch the HC-05 Into Command Mode
For the HC-05 module to switch to AT command mode, the HC-05 Key pin needs to pulled HIGH but in a certain order of events explained below. 

  1. Wire the HC-05 and Arduino Uno per instructions.
  2. BEFORE YOU CONNECT THE ARDUINO TO THE USB remove the VCC(power) wire from HC-05. All other wires are still connected.
  3. Now connect your Arduino Uno with the USB cable extended from your PC.
  4. Make sure the HC-05 module is NOT PAIRED with any other Bluetooth device. 
  5. Re-connect the Arduino Uno 5V wire to the HC-05's VCC (5V power) pin. 
  6. The HC-05 LED will blink on and off at about 2 second intervals. Now its ready to accept ATCommands to change configuration and settings.
  7. To test if everything is wired correctly, open the Serial Monitor from the Aduino IDE and type "AT" (remove the "" just AT) and click SEND. You should see an "OK"
  8. If you don't see an "OK" check your wiring.

Step 4: Example HC-05 AT Commands
You can send AT Commands to the HC-05 from the Arduino IDE Serial Monitor while the Arduino is running the attached Arduino program. 


You cab find a full set of AT commands from the attached HC-05 reference PDF file, or you can test some of the popular AT commands.


(remove double quotes from AT command)

  • To return HC-05 to mfg. default setting: 'AT+ORGL"
  • To get version of your HC-05 enter: "AT+VERSION?"
  • To change device name from the default HC-05 to let's say BLUENODE enter: "AT+NAME=BLUENODE"
  • To change default security code from 1234 to 2232 enter "AT+PSWD=2232"
  • To change HC-05 baud rate from default 38400 to 115200, 1 stop bit, 0 parity enter: "AT+UART=115200,1,0"

Setup Wireless Sensor Node

Wireless sensor node is a kind of sensor that can transmit its sensing data, alphanumeric or multimedia and transmit it to the base station via wireless connection. There can be many kind of wireless connectivity with their own protocol. Some use for Local Area Network like Wi-Fi, others for Personal Area Network like Bluetooth and ZigBee. 

This SensorGate apps are function by receiving sensor data from your sensor node with Bluetooth connectivity and transmit it to your fusion table you just selected. 

To do that you need to setup your own sensor node by:
1. Configure Bluetooth connectivity, 
2. Get sensor reading from sensor, and
3. Send its reading to the phone by following the packet protocol.

Thursday, 29 October 2015

Setup Fusion Table as Database: Customize Your Table by Adding More Column to Store Data

To get more smartphones able to pushing sensor data to the same table, make sure to add more credential API KEY, different phone with different API KEY. 

Query that are use by the Fusion Table are 

INSERT INTO (TABLE ID)(,,...)VALUES(,,...)

The words in CAPS are part of the query's syntax. The words in parentheses are values that need to plug in. First there is a (column names) followed by VALUES followed by a list of (value names). The order of the column names and value must be in the same order so they match up. An example of what this might look like is shown below. Notice that the values must be enclosed in single quotes:

INSERT INTO 191GJakyqWHsan(Name,Date)VALUES('Sam','10/10/2012')

Gateway apps will push this query, and with the help of TABLE ID and API KEY. Those data will arrive to your table, and when arriving, a new ROW will be added to the existing column. Your columns name need to be similar between the name you assign at your query and table. To get that you need to.....

..... customize your table by:

  1. Give a name to your table, by click the current name "New Table" and change table name at it setting
  2. Add more or edit existing columns by going to Edit > Change Columns. You'll rename all the columns and select suitable data type for each of the column. 
  3. Since you using this SensorGate app. You need to add 4 extra columns at the end of your table. Column for Date, Time, Latitude and Longitude. If you don't do that, there will be an error and failure in pushing data to the cloud. So please add it. This is to make your life easy as you know exactly where and when those data are collected and generate. 


Setup Fusion Table as Database: Table ID

To get Fusion Table ID, is by browsing to your table, then select the File > About this table in the menu.

Tuesday, 27 October 2015

Setup Fusion Table as Database: Getting an API Key

For the SensorGate app to work and able to push connected sensor data to your Fusion Table it require 2 things; API KEY and TABLE ID.

First is to get an API key, follow these instructions:
  1. Go to your Google Developers Console and log in with your Google account if necessary.
  2. Click Create Project, and give a name to your project. 
  3. On the left-hand menu, under APIs & auth select the APIs item.
  4. In the list of APIs, scroll down to find the Fusion Tables API and click the toggle button "Enable API" (if it already says "Disable API" and its color is not blue then leave it as is, because API is already enable.)
  5. On the menu on the left of the screen select the Credentials item under "APIs & auth".
  6. Click "Add Credential" and select API key > Android key > Create > OK
  7. Your API key will show up under "Public API Access". You will need this API key for the "API Key" property of the FusiontablesControl component in any app that you make that uses Fusion Tables. (More info on the future post)
  8. If you are using difference or more than one smartphone as a gateway to push data to the same Fusion Table please feel free to add more API keys, to be used at each phone. 

Monday, 26 October 2015

Setup Fusion Table as Database: Creating Your Own Fusion Table

Creating your own Fusion Tables is as easy as creating a Google document in Google Drive, if you are familiar with that process. 
1. On the web, login to Google Drive account or any Google service (e.g., Gmail, Youtube).  
2. Select the New >  More > Connect More Apps menu, on the pop-up page go to the search apps box and type Fusion Table, click connect > OK




3. Again select the New > More > Google Fusion Table, it will open a new tab with show three selection to create Fusion Table, you can explore each of the method later and as for now click Create empty table, another tab open "New Table". 

4. You will see that the new table automatically comes with four columns. Change the column names by going to Edit > Change columns.Based upon the application that you want to create, it can be a table of sensor reading or a table of food order. Make sure their is no space at the name of the column, as well as the type of the data that will be stored. 
5. Click on the Share button (top right) to modify the table;s permissions. For this tutorial, you can specify a few friends who will use the app. Only people who are explicitly given permission will be able to push content into your table. 
NOTE about Sharing Fusion Tables: To share a FusionTable with others, you must share it with each person individually, you can share with a Google Group, or you may share it with a service account the same way you would share a private Google Doc.  There is no way to share write privileges to a FusionTable with the public. Public access is restricted to read-only. Please see the Setting up a Service Account section at the bottom of the page for how to set up a service account to authenticate all end-user access to your Fusion Table.
6. Make sure your android phone account that will be used as a gateway is added, as the list of account that can upload content into your table. 

Setup Fusion Table as Database

A Fusion Table is a Google service to support the gathering, managing, sharing, and visualizing of data. Data are stored in multiple tables on Google's cloud. Individual tables can be merged (or fused) if they contain a common column, and they can be easily visualized on maps and in various kinds of charts and graphs. 

This setup is to create a Fusion Table in Google Drive, and to get the 2 components required by the SensorGate apps that will be used at the next step on "Setup Smartphone as Gateway", which are API KEY, and TABLE ID.


Introduction

This blog is build in conjunction with the research paper on "Repurposing Smartphone as a Gateway for Wireless Sensor Node" that is published at the ACCS 2015 Conference.

This blog is regarding on the setup needed to develop a ready-to-play wireless sensor node with the capability to push their data to the cloud storage via smartphone as a gateway. This method is using Fusion Table from Google company as a storage location to store WSN data, safely and securely in the user Google Drive.  

This setup is divided into 4 parts; which are:

        1. Setup Fusion Table as Database.
        2. Setup Wireless Sensor Node with Bluetooth Connectivity
        3. Establish Connection between Sensor Node and Smartphone
        4. Start pushing data


This whole system is made up for a non-technical people to learn about a method to save their distributed sensor data to the cloud storage using the most simplest method that I know.

The First Step is to download SensorGate apps and install it.


SensorGate

Then you need to create your table, and setup your wireless sensor node with Bluetooth connectivity.