Saturday, August 29, 2015

Snapshot of Sending commands from IoTF to RPI.

This is a snapshot of how one can send some basic commands from the NodeRed ( IoTF ) back to the device. Here I am sending some simple strings to the device ( in my case it is a Raspberry Pi ) The code on RPi, should sit and listen to incoming commands,by using a callback function.

Thursday, August 27, 2015

Simple node js code to receive commands from a Device over mqtt. ( App side )

A traditional publish / subscribe model for an IOT would mean that the Device ( in this case let's say a RPI ) is publishing some sensor data ( say a temperature from a furnace )
and sending it to IoT platform.  This is called the "Client"

At the other side - there is an app" end - where we have a C program, or Java or Python application which is sitting and listening to the PublishEvents from the device(s).


Below is a App end code in node.js - which connects to IoTF ( Internet of Things Foundation )  and prints whatever it received from the devices.




A sample  node.js code to receive events data published from the device (e.g : Raspberry Pi )


References :
http://iotf.readthedocs.org/en/latest/libraries/python_cli_for_apps.html#handling-events-from-devices


Run this on your laptop  ( or on the app end )
( npm install iotf _ if this complains that Iotf libraries are not installed ) 
 
==
var Client = require("ibmiotf").IotfApplication;

//read the config from the application.cfg
var config = Client.parseConfigFile('./iotf.cfg');

var application = new Client(config);

var deviceType = "iotdevice";
var deviceId = "b827eb984666"

application.connect();

application.on("connect", function () {


        setInterval(function function_name (argument) {
                payload = '{ "numOfTimes" : 23 }';

                application.publishDeviceCommand(deviceType, deviceId, "blink", "json",payload);

        }, 2000);

});
 



==
This will connect to IoTF and print data being published from the device(s) which are at remote places.

A sample :

[user@oc0650888602 nodetest]$ node app.js
[2015-08-27 18:24:10.268] [INFO] [default] - Connected to IoTF successfully
Device Event from :: iotdevice : b827eb984666 of event status with payload : {"d" : {"temp" : 16 }}
Device Event from :: iotdevice : b827eb984666 of event status with payload : {"d" : {"temp" : 5 }}


==
A sample  iotf.cfg  that is used is as shown:
org = 8ubmht
id = b827eb984666
auth-method = apikey
auth-key = a-8ubmht-httz8bouy6
auth-token = NNZrVxhQpZa90Jc*5J    







Sunday, August 16, 2015

Temperature and Humidity Sensor using DHT11 connected to Raspberry Pi.

Blog used to refer when building this project:

http://www.rpiblog.com/2012/11/interfacing-temperature-and-humidity.html


Items used in this project:

Raspberry Pi  Model B.

DHT11 Temperature sensor

10K Resistor -

Breadboard-  on which the Sensor was connected and 3 pins from it being used for connecting to Power, GND and the data pins.

Setup:

- Connected the first Pin of the DHT 11 to +5V  ( Pin 2 of RPi) ( seeing from the left of the DHT11 )

- Connected the last pin of the DHT11 to  GND ( Pin 39 of the RPi)

- Connected the 2nd pin i.e data ( from the left of the DHT11) to Pin 7, i.e GPIO4 of the RPi.
How to Compile source code:
-gcc -o sensor temp_rh_sensor.c -L/usr/local/lib -lwiringPi

A reference device - an independent device used to check that the DHT11 was reporting approximately same temperature.


^Cpi@raspberrypi ~/wiringPi $ sudo ./sensor
Interfacing Temperature and Humidity Sensor (DHT11) With Raspberry Pi
Invalid Data!!
Humidity = 58.0 % Temperature = 30.0 *C (86.0 *F)
Humidity = 58.0 % Temperature = 30.0 *C (86.0 *F)
Humidity = 58.0 % Temperature = 30.0 *C (86.0 *F)
Humidity = 58.0 % Temperature = 30.0 *C (86.0 *F)
Humidity = 58.0 % Temperature = 30.0 *C (86.0 *F)
Invalid Data!!
Humidity = 59.0 % Temperature = 30.0 *C (86.0 *F)

How to resolve HTTP Request failed error, when executing a git clone.

There could be instances when we try - to download some code,using 'Git Clone' - we are prompted by a HTTP Request failed message, This happens when there is no user credentials that is missing in the git request.
Below is a sample of the failure and also how to resolve it.
[user@oc0650888602 nodetest]$ git clone https://hub.jazz.net/git/user/iotstartertrial Initialized empty Git repository in /home/user/nodetest/iotstartertrial/.git/ error: The requested URL returned error: 401 Unauthorized while accessing https://hub.jazz.net/git/user/iotstartertrial/info/refs
fatal: HTTP request failed
Fix was to enter the user credentials as shown, and it works.
git clone https://your_alias:your_IBM_ID_password@hub.jazz.net/alias/project_name.
See Sample below:

[user@oc0650888602 ~]$ git clone  https://<user>:<password>@hub.jazz.net/git/<user>/iotstartertrial  Initialized empty Git repository in /home/<user>/iotstartertrial/.git/ remote: Counting objects: 27, done remote: Finding sources: 100% (27/27) remote: Total 27 (delta 0), reused 27 (delta 0) Unpacking objects: 100% (27/27), done.

Tuesday, August 11, 2015

My first Arduino external device as a IoT.

(See attached file: IMG_20150809_141754.jpg)(See attached file: IMG_20150809_141806.jpg)(See attached file: IMG_20150809_141757.jpg)



My first Arduino board and small C Program in the sketch to blink a LED on pin 13.

Sunday, August 9, 2015

Sending Automatic Twitter messages using Node-RED offered by IBM Bluemix

Node-RED is a  IBM flow creator tool, where users can use ready made input nodes, output nodes, write functions, inject and receive events to  and from various external devices ( or Internet of Things) like the Raspberry Pi, Arduino and others IoT devices as well send messages to  social media  portals like Twitter.

One can read more about it in this page http://nodered.org/.

Here I will blog about how to create a simple flow in the Node-RED and inject timely messages to my twitter account (@kiranshashiny) automatically.

To do this, You will need a
- twitter account
- IBM id



First login to IBM Bluemix using your IBM Id, and create an APP.


Open the URL shown- It should open a Node-RED editor page.


Click on "Go to your Node-RED flow editor"

It opens a blank canvas.

Click on Input-> Inject, and drag and drop it into the canvas.




You will see a node called timestamp.




Click on Social -> twitter, drag and drop it into the canvas.


 





Point at the output of timestamp and drag it to the input of Tweet. You will see a line connecting the nodes.


Double click on Timestamp and configure the node to send Twitter message every interval.



Now, double click on Tweet and fill in your twitter credentials.




Authorize and you will be prompted to close the new browser tab.








You will notice that the small red triangle is gone on Tweet node (this means the node is fully configured )

Click on Deploy


You will notice a small 'tweeting'  sign below the tweet node.


This tells that the tweets are going out to your account.
Login to your Twitter account and you will notice some random (time stamps) in your account.

Do not send too many tweets as it might impact your account and the twitter server.

once, done - reword the different options in the Inject node.

e


Some other options are :