UDOO baby room with AI2

This tutorial aims to replicate the Baby Room Automation project found on Hackster.


For this project we will use an Android device, that will run the AI2 application, and a UDOO Board, installed in the baby room. The UDOO Board runs Linux and has a camera, a microphone, the sensors and relays to control the lights.



  • stream the video from the baby room to a remote AI2 app
  • stream the audio from the baby room to a remote AI2 app
  • turn on/off lights in the baby room
  • get data from the sensors, like DHT11 temperature sensor

Turn lights on/off

To control a light you need two buttons (on / off) and any relay, like this one. Connect a lamp to the “normally open” and “in” plugs. On the Arduino side of the relay connect the enable pin to a free GPIO on the UDOO Board. You can the use the digitalWrite method on the UdooArduino component:


Read temperature, motion and audio sensors

We want to get some data from the sensors connected to the UDOO Board:

  • motion sensor: we want to know if the baby moves
  • audio sensor: we want to know if the baby cries
  • temperature sensor: we want to know if the room is too hot


Inside the Timer event of a Clock we read the three sensors. If the digitalRead of the movement sensor returns 1, it means that a movement is detected and the Android device running the AI2 app vibrates.

If the analogRead of the audio sensor returns a number greater than i.e. 50, some noise is detected in the room, and we assume it is the cry of the baby.

We also call ReadSensor on the DHT11 sensor, and we check for the temperature value on the DataReady callback. While digitalRead and analogRead are synchronous, ReadSensor is not, so there is a separate callback for this reason.


Video streaming

The video streaming is achieved installing MJPG-Streamer on the UDOO Board. It exposes a webserver with a MJPEG images, creating a fake (low frame rate) video:

ubuntu@udoobuntu: ~/mjpg-streamer/mjpg-streamer-experimental $ ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so -d /dev/video0 -r 640x480 -y -fps 2"

Then in App Inventor create a WebViewer component and set the URL to

data:text/html;charset=utf-8,<img src="" />

having care to replace with the IP address of the UDOO Board.



Audio streaming

Connect a microphone to the UDOO Board, the install icecast (you can easily find some tutorials on Google). Icecast creates a webradio, records the audio, encodes it in mp3/ogg and streams it over the network.

To play the audio on your board, add a Player component to the AI2 app and set the source to a string containing the radio URL.

Posted in Uncategorized | Leave a comment

App Inventor (AI2) for the UDOO board

Recently as part of the research activity carried out by the Interaction Design Lab of the University of Siena we started to hack MIT App Inventor 2, making it able to communicate with the Arduino of a UDOO Board running Android KitKat.

What do you need

You need to use a custom version of App Inventor 2. The code is on GitHub. You can easily compile it and run the AI2 server on your computer in order to follow this tutorial.

You will also need to flash this sketch on the Arduino of your UDOO. So of course you will need a UDOO Board :-)

Driving a motor (or a LED)

You can connect any digital device to the Arduino pinout of your UDOO board, like a DC motor or a simple LED:


Create a new App Inventor project and add some buttons to turn the motor and the LED on and off:



Then from the components palette you can pick the UdooArduino component from the UDOO panel:



This component creates a connection to the Arduino (locally, using ADK, or via TCP/IP). Once connected, it is possible to call the functions part of the Arduino API, like digitalWrite, digitalRead, analogRead, …
Switch to the Blocks editor to handle the buttons’ click event.


The Connected event fires when a connection between the Android app and the Arduino is established. On a local ADK connection this happens when the user allows the app to use the USB accessory. On a remote TCP connection the event fires when the socket is successfully created.

The goal of the Connected event is to provide a place where to put the code you would put in the setUp() function of an Arduino sketch. Please bear in mind that this event could potentially fire multiple times while your app is running: if the connection drops it will be recreated and the Connected event fired again.

The handlers of the click events are self explanatory. We simply call digitalWrite(pin, value) to turn on or off the motor and the LED.

Reading a temperature/humidity sensor

App Inventor supports the DHT11 sensors, connected directly to the UDOO board:


Add a UdooArduinoSensor from the UDOO components palette. This component will be used to read the DHT11 sensor. Add also a button to start the read (or a clock, to read the temperature periodically) and some labels to display the values:


Then switch to the Blocks editor:


Clicking on the button, the ReadSensor method is called on UdooArduinoSensor. The component will request the actual values from the sensor, and when data will be ready, the event DataReady will fire. That’s all!


Posted in Uncategorized | Leave a comment

<canvas> rocks, <video> sucks

When in news.yc I find posts like “iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>” I really fall in love.

Seriously. So much in love that I need to try it by myself. Hence, VideoCanvas.
VideoCanvas is a mix of PHP, ffmpeg and ImageMagik.

Starting from a video, it creates an images with all the tiles and an HTML page with hard-coded JSON containing frames info and some JavaScript to start the video.

It relies on ffmpeg to extract video frames in separate images. Then with the ImageMagik extension of PHP it creates a minimum set of tiles to recreate the video in the <canvas>.

Have a look at the final result of version 0.1. Here you can find the source video made with Kazam Screencaster.

(Edit: the JS code has been updated to use requestAnimationFrame when available)

Posted in Image processing, PHP | Leave a comment

Experimenting PHPADD on Doctrine2

Today I tried to unleash PHPADD over Doctrine2 sources.

Of course, it couldn’t even start: it didn’t support namespaces. So I had to improve the analysis of tokenized PHP source and now it works.

By the way, the report was not satisfying as I expected. With a big project such Doctrine you understand how much it is important to have a concise report. So now:

  • the parameters are internally indexed by name. This means that it is easy to detect a changed type, but names changes are still seen as “added param $newName” + “removed param $oldName”.
  • @inheritdoc is supported.
  • multiple types (integer|bool $param) are supported.

This leads to an almost accurate analysis of Doctrine2 ORM classes:

Scanned 261 files with 1672 methods in their classes. 919 methods (55.0%) are regular, 388 methods (23.2%) have no docblock, 365 methods (21.8%) have an outdated docblock.

Since these changes are not in the pear channel yet, if you are lazy&curious the report is here.

Posted in PHPADD | Leave a comment

5.3.7 is the best PHP release ever

Before release 5.3.7, PHP was fantastic. It had everything the web needed, built-in.
But starting from 5.3.7 something in the interpreter changed:
– a stupid regression on crypt()
– the knowledge it has only 70% of code covered by tests
– the knowledge it has almost 200 failing tests
– the knowledge that no one runs tests on it before release

So, now PHP is evil. Personally, I agree with Anna Filina:

This is an insult to all people who work hard at it. The words that you use to describe things are simply baffling. “You” and “them” are the community, and it’s your responsibility as much as theirs.

People can improve. The crypt() function can be fixed (ooops, already done). The failing tests can be analized and fixed. The release team can learn to avoid to be embarrassed again. If you understand something that can be improved, you can improve.

For this reason I think PHP 5.3.7 is a great release for self-improvement.
One point for PHP, zero points for stupidity.

Posted in Uncategorized | Leave a comment

PHPADD 1.3.0

I just uploaded to the PEAR repository the latest version of PHPADD, which is labeled 1.3.0.

From this release I can consider it useful, since it includes the ability of exclude whatever you do not want to scan. In fact, you can exclude from scanning any path, class name or method name.

In Allbus, the company where I work, we have several types of classes that are not so much interesting, like implementations of Factory or View Model patterns.  A Factory creates instances of Services with all the needed collaborator injected, with method names like getVehicleService() – which is self-explanatory. A View Model selects some fields from the Sacred Domain Model and always has just a method, setUp(). Nothing more!

As you can see, in such cases the use of docblocks is tautological. While analyzing what classes need a visit to their docblocks, it is important to have no noise around. Simply leave behind classes that do not introduce logic:

phpadd --exclude-paths application/*/view/model/* ...
phpadd --exclude-classes Factory$ ...
phpadd --exclude-methods ^setUp$ ...

If you have already installed an older version of PHPADD, you can just run pear upgrade-all. Otherwise, install it via the repository.

Posted in PHPADD | Leave a comment

PHPADD: abandoned docblocks detector

Docblocks may become as evil as comments when they’re not treated as first-class citizens (see: Meaningless docblocks).

PHPADD can analyze a directory with PHP source code and detect (for each file, for each class, for each method) if the parameters in the function declaration are compatible with the parameters found in the docblock, reporting the outdated ones.

This can be easily integrated in your build script and the result can be published in build result. Using Hudson, you just need HTML Publisher plugin.

Install it
With PEAR it is very simple. On Linux, you may need to prefix each command with sudo.

pear channel-discover pear.webmatters.it
pear install webmatters/phpadd

Try it
Once installed it responds to phpadd from your console.

phpadd --publish-html /tmp/output.html directory/to/analyze

This command will produce an output like this.

Please note, phpadd has to be improved. For example, it needs to ignore warning on files/classes/methods matching a given regular expression (controller classes, for example).
Or the difference between docblock params and function params: it is not so smart.
If you want to help, fork it on GitHub!

Posted in PHPADD | 15 Comments

BannedComboItems: ComboBox with disabled items

Combos are beasts. Beasts for developers (400 lines of ugly configuration) and beasts for customers.
For some business logic, you may not select some elements. What to do in these cases?

If you do not put unselectable items in the combo, your customers will say you: “Why can’t I see raspberries in the list? I’m sure I added them to the system“.
And if you put everything in the combo, they will say you “Oh, that’s too much, why do I see all this useless stuff?“.

But wait for a moment, we already solved this problem 20 years ago in menus!
Continue reading

Posted in ExtJS extensions, User experience | 1 Comment

Git tips and tricks

Display the active branch in the terminal prompt
Add this line to ~/.bashrc
PS1='\u@\h:\w$(__git_ps1 " (%s)")\$ '

Automatic add during commit
git commit -am "message"
It automatically adds already versioned files to the index before commit. This will automatically remove file disappeared from the filesystem. Untracked files will not be added.

Add to the index just some part of a file
git add --patch
For each chunk, you can type: y (stage it), n (do not stage it), q (do not stage & quit)

Interactive index add
git add --interactive
This UI has Super Cow Powers. Go in update mode with update. Now type:

1     to add the first file to the index
1-3 to add files 1, 2 and 3 to the index
-1   to unstage first file

To go back into “what now” mode, press Enter. With revert mode you can restore a file as it is in HEAD. For other modes, type help.

Undo a commit
To go back to the previous state
git reset --soft HEAD^
Fix what was wrong and commit from the discarded commit (ORIG_HEAD)
git commit -c ORIG_HEAD

Posted in Git | Leave a comment

Ext.Ajax on steroids [AuthorizedAjax]

In the company I work for we use ExtTop, the Windows-like desktop environment which provides icons, taskbar and start menu. It is a single page web application. You can open all the windows you want, but you will never reload the page.

We want to log users off after one hour of inactivity. If your user session is destroyed and you try to open a form, you should be warned that you cannot continue and you will be invited to log in again.

That’s very simple. For each Ext.Ajax request, you should check that you are still in, if not, open a login form and if the server accepts your credentials, continue. For each request. For each request. For each request. […]

That repetition sucks. What could we do?

  • copy and paste all the code, in every Ext.Ajax.request()
  • create a detectIfLoggedOf() function and call it in every success() callback of Ext.Ajax.request()
  • define a new Ext.Ajax that do everything.

Since you should spend your time writing a strong web application, let’s discard option 1 and 2. AuthorizedAjax is option 3.

Please keep in mind this is more a proof of concept rather than a real implementation. There is no documentation (yet?). See the example and read it’s configuration file.
Continue reading

Posted in Domain specific languages, ExtJS extensions | Leave a comment