Monday, June 30, 2014

Arduino temperature and humidity using DHT11/DHT22 modules

In this tutorial we will measure the surrounding air to get temperature and humidity.

What we need:
After wiring module to arduino, download and install DHT lib. To do so navigate to Sketch/Import Library/Add Library



After installation is complete it will appear in library list.

Upload the sketch using codebender
Alternatively download the sketch and upload it to arduino.


Depending what sensor you use, change the line accordingly.
#define DHTTYPE DHT11 or #define DHTTYPE DHT22

Open serial monitor and type any of these commands ("dhttemp" "dhttempc") to get temperature and ("hum" "humid" "dhthum") for humidity. You can change the sketch to your preferences by changing the lines...

if (readString == "dhttemp" || readString == "dhttempc")
...
else if (readString == "hum" || readString == "humid" || readString == "dhthum")



Interfacing with Jubito
First make sure you have properly configure arduino serial port and then enable it.


From Instruction Sets menu press Add New Launcher. Enter a name (handler) and type the following command...

judo serial send dhttemp


The same way to make a launcher for humidity...

judo serial send hum

You can test the new launchers by typing the command to the terminal tab.


Dashboard Interface
We can now add it to our dashboard. Navigate to Instruction Sets menu press Add New Instruction Set and fill the mandatory fields (name, action, category, header) and some optional if you desire, e.g. Thumbnail URL.


Notice that in action field we add an asterisk in the beginning. It is used to point the gettemp launcher.


Another cool feature is that you can have those notifications in the Home screen. To do so you have to edit index.html file located to /www/ directory. Find the getData function and add the code...

$.get('_.html?cmd=judo serial send dhttemp', function (data) {
    $('div#tempc').html(data.replace('<br /\>', '') + '&deg;C');
}, 'html');
$.get('_.html?cmd=judo sleep 1500; judo serial send hum', function (data) {
    $('div#humid').html(data.replace('<br /\>', '') + '%');
}, 'html');



Make sure that tempc and humid divs exists in the html document.


The result should look like the screenshot below.


You can expand by applying logic with evaluation function.

Thursday, June 26, 2014

Arduino radio remote control [ RF 433MHz/315MHz ]

In this post we will develop an Arduino remote control that will receive and transmit at 433MHz/315MHz. This will allow us to control devices that operates in that frequencies such as plug socket receivers.


What we need:
So, let's get started!

After wiring modules to arduino, download and install rc-switch lib. To do so navigate to Sketch/Import Library/Add Library




After installation is complete it will appear in library list.

Upload the sketch using codebender
Alternatively download the sketch and upload it to arduino.


Open serial monitor and press a button of the remote control. You should receive a binary code.


Of course Jubito and jaNET Framework provide the capability to listen the serial port via judo API.

Syntax: judo serial listen <ms>
milliseconds are optional. By default it is set to listen for 10 seconds (10000ms).



If you successfully complete the above steps, then, scan all the buttons of the remote control and write down the corresponding readings. At this time you are ready to create your virtual remote and accomplish transmissions from Jubito.

First make sure you have properly configured arduino's serial port and then enable it.


From Instruction Sets menu press Add New Launcher. Enter a name (handler) and type the following command...

judo serial send 000111101100000001100001


the binary code is the corresponding key press. For example the button A of the remote control that turns on the plug. To test if the 'plug-A-on' launcher is working, go to terminal tab and type...

plug-A-on


this command should power up the plug!

Dashboard Interface
When you create launchers for all buttons you are ready to create the virtual remote control. Again from Instruction Sets menu press Add New Instruction Set and fill the mandatory fields (name, action, category, header) and some optional if you desire, e.g. Thumbnail URL.


Notice that in action field we add an asterisk in the beginning. It is used to point the plug-A-on launcher. You can write some additional text also if you like, for example...

*plug-A-on Socket A is on

which will cause a response 'Socket A is on' to the button press instead of the 'Operation Completed' system message. After that the new instruction set is accessible from the dashboard.


Now you are able to clone any remote control at 433/315MHz.

Monday, June 23, 2014

Execute commands from android app

A simple java snippet for posting commands to jubito server from an android application.

String jubito_Host = "http://192.168.1.98:8080/www/index.html";
String jubito_Username = "your_jubito_username";
String jubito_Password = "your_jubito_password";
String jubito_Command = "%checkin%"; // Your custom Instruction Set or a simple system function

try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(jubito_Host + "?cmd=" + URLEncoder.encode(jubito_Command.toLowerCase(), "UTF-8"));

    String credentials = jubito_Username + ":" + jubito_Password;
    String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
    httppost.addHeader("Authorization", "Basic " + base64EncodedCredentials);

    HttpResponse httpresponse = httpclient.execute(httppost);
    String result = EntityUtils.toString(httpresponse.getEntity());

    return result;
} catch (UnsupportedEncodingException e) {
    // suppress exception
} catch (Exception e) {
    e.printStackTrace();
}
return null; 

Asynchronous operations triggered by arduino serial data

Another interesting and useful thing to know about Jubito is that its continuously monitor the serial port where arduino is connected. That allows as to control any message that arduino prints out. There is two ways to use that kind of data. One is by creating a new instruction set, which explained in this post, and the other one is by firing events. The second way is very efficient for asynchronous operations such as motion detection.

Let's make an example.


The above screenshot illustrates a MotionDetected message captured from a PIR sensor. In order to trigger an event or a sequence of actions we have to create a handler with the same name.

On Control Panel select Instruction Sets/Add New Event Handler


Then give the corresponding serial message as the name of the event handler


Action's can be vary depending your needs. In this example I will create a simple email notification. In the action field type...

judo mail send me@gmail.com me@gmail.com `Motion Alert` `A motion is detected at %calendardate% %time24%`

This will produce a message that would tell...
A motion is detected at 23/6/2014 14:07

Syntax of judo mail send API call...
judo mail send <from> <to> `<subject>` `<body>`

Read more about functions & judo API

To avoid signaling you every time that motion is detected you can use %whereami% function within evaluation which is explained in this complete example of security system.

The bottom line is that we can produce a variety of asynchronous operations that would be driven by received serial data.