In order to achieve a fully dynamic front end, I started working on a widget factory. The combination of two different Instruction Sets will give us the ability to view additional real time info within a dashboard item in a bubble form.
I will proceed by doing a simple example using framework functions (%greader% or %gmailreader% and %gcount% or %gmailcount%). The first will return the headers of the message(s) and the other one will be the counter.
Go to Control Panel->Add New Launcher and follow the screenshots...
Now we'll create a new dashboard item that includes both of the above.
Navigate to Control Panel->Add New Instruction Set
Scroll down to Add to Dashboard and fill Category, Header, Thumbnail (optional) and Reference field.
Save it and return to the Dashboard. You should be able to see something like that...
When you click Gmail Check you will get the response of gmail launcher.
For older Instruction Sets, edit the AppConfig.xml and add a reference attribute (ref) that points to the Instruction Set ID you want to call. For this example, gmailwidget.
You may notice temperature and humidity values as well in the screenshots. It has the same logic but first you should take a look at arduino tutorials.
Follow the screenshot to wire the photocell and then upload the sketch to arduino.
Alternatively use codebender
By hitting the 'light' command in the serial monitor we will get a print out of what it interprets as the amount of light in a qualitative manner. Thus is 'Dark', 'Dim', 'Light', 'Bright', 'Very_Bright'. You can change thresholds readings with values that suits your conditions.
OK, now we are ready to take advantage of the above example and make an assistive illumination system. As we already know we can capture serial messages from Jubito and trigger corresponding events. To make it happen we need to create one event handler with the name 'Dark' that will execute the 'plug-A-on' launcher of this example.
To do so, navigate to Control Panel/Instruction Sets/Add New Event Handler and enter the name and the action. When sensor submits 'Dark', the 'plug-A-on' launcher will be executed and turn on a light that is plugged to a wireless power outlet.
Notice: The above example to take effect, we need to let the loop continuous running and print out conditions than waiting for a 'light' command to be send. The modified sketch should be...
// We'll have a few threshholds, qualitatively determined if (photocellReading < 10) { Serial.println("Dark"); } else if (photocellReading < 200) { Serial.println("Dim"); } else if (photocellReading < 500) { Serial.println("Light"); } else if (photocellReading < 800) { Serial.println("Bright"); } else { Serial.println("Very_Bright"); } } delay(1000);
}
But still you can use a scheduler and evaluator that applies to original sketch. Follow this article to see how you can do that.
Update
So we come back to see how we can make a running daemon with a scheduler that evaluates the light conditions.
First we need to create a launcher that executes the 'light' command we set to arduino sketch and fetch the state. Then we need a new Instruction Set that invokes it.
From the Instruction Set menu click Add New Launcher and give a name and the judo API call to send the 'light' command to the serial port.
After that create a new Instruction Set that invoke the launcher and make the evaluation with the 'Dark' condition. Type a name of your choise and the evaluation that follows...
{ evalBool("*getlight" == "Dark"); plug-A-on; ; }
The '*getlight' pointer will invoke the 'getlight' launcher and get its returning. Then it will be replaced by the condition data ('Dark', 'Dim', 'Light', etc) and proceed to evaluation. If condition is true the 'plug-A-on' launcher will be triggered, else nothing will happen.
The last thing to do to make it a runnable daemon is to create a new schedule that call the above Instruction Set within an interval.
From Scheduler menu click Add New enter a name, <Repeat> on the period dropdown, interval in milliseconds (the example use 60000ms which is 1 minute) and finally the 'evallight' Instruction Set as the action.
After this tutorial we're coming back to make another kind of remote control. This time we will use infrared modules to receive and transmit codes to devices such as TVs, Hi-Fi systems, Projectors, etc. Thus will give as a universal remote control.
First wire the modules and then install the library. To do so navigate to Sketch/Import Library/Add Library
Receiver
Transmitter
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 the serial monitor point the IR receiver module and press a key of a remote control. It should return back the readings (code type, code value and code length).
To transmit back we have a simple implementation within loop that translates a specific form of data.
i.e. <codeType:><codeValue>&<codeLength>
For example, son:2704&12 which will cause the transmission.
Jubito as a virtual remote control
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 son:2704&12
Then visualize it. Again on 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.
As you might already know from previous tutorials, we point the 'sonypower' launcher with an asterisk in front of that.
After that final step you'll see a 'Media' category to your dashboard with the action we've just created.
Scan and enjoy your virtual universal remote control.
Alternatively use codebender
Open serial monitor and start moving, after that, follow this post and learn how to perform operations with Jubito or this one that concerns security.
In this tutorial we will make a gas leakage detecting system with MQ-2 gas sensor which is sensitive to LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke.
Open serial monitor and type 'smoke', 'co' or 'lpg'. Each of these commands will return concentrations of smoke, carbon monoxide and liquefied petroleum gas. You can read more details here.
You can define your own commands by changing the lines below...
After that we will use those values to detect for any king of leakage. We will make a new schedule that will run every 60 seconds and perform evaluation.
As usual please make sure you have properly configure arduino serial port and then enable it.
Let's get dirty
First we need to make a new launcher to retrieve smoke values for this particular example. Go to Instruction Sets menu and press Add New Launcher. Enter a name (handler) and type the following command...
judo serial send smoke
Then our notification launcher using judo mail send API command. Syntax: judo mail send <from> <to> `<subject>` `<message>`
And finally the Instruction Set that handle the evaluation function. Press Add New Instruction Set, type a name and the following command...
{ evalBool(*getsmoke > 0); sendmailonsmoke; ; }
Note: Zero value can be changed with one of your choice you consider dangerous.
The above action will call the first launcher and get a value from the sensor, then will evaluate if it's greater than zero, if the statement is true the second launcher will be triggered and send us an email notification. Read more about evaluation function.
Now we are ready to create a 60 seconds schedule for task to be repeated. Click on scheduler and press Add New. In the popup window enter a name, period <Repeat>, interval in milliseconds <60000> and the 'smokeschedule' instruction set we had create in order to call the evaluation procedure.
This is it, once we save the schedule it will be activated. You can do the same way for gas (co) and perform a test with a lighter.
Another approach is to trigger an event from the sketch like this example.
You can accomplish that by change the lines below...
void loop(void) {
if (MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_SMOKE) > 500) Serial.println("HazardousSmokeDetection");
When the measurement exceeds the value we have set, the 'HazardousSmokeDetection' will be printed to serial port and cause Jubito to execute the corresponding event.
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...
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 /\>', '') + '°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.
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.
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.