Friday, 4 October 2013

Concatenate a String with a Float

I came up with a very simple and difficult problem with my little Arduino, I couldn't concat a string and a float number, after a few hours on Google I found out the solution:

elpful link:

Lightwave RF Arduino

I had some spare time ( and money ) and I decided to make my little flat a beginning of automate house.
I did some research how to control my lights from an Arduino, even knowing that I could replace the normal switch with a relay. This wasnt enough because I wanted to keep the manual system and to be controlled from an Arduino, so after few hours I came up with LightWaveRF system that has been "hacked" and it is possible to be controlled from an Arduino.

Their products are working with a simple RF protocol at 434 mhz, and they give you the possibility to control it from your smartphone, remote controller and a webpage.
Some people understood how the protocol works and they just write a simple library to interact with Arduino.
There are various adapter: Light switch, Power socket, Light, Sensor PIR, etc.. and if you get a remote controller and a RF receiver, you can reproduce the same signal from your code.

I was using this library to find out what ID and what kind of signals the remote controller was sending to the light switch. After a few minutes on the result and few website, I understood how to reproduce the same behaviour with a single click.
I suggest to use the Decode example to get your ID and to understand what kind of signal your are sending. If you have a multi channels remote, you have to be careful on which command and which channel.

Here an example to turn on my light:

Here a little description what message it sends:

When you got the ID, Channel and which command to send, you re ready to send your first message to your device.
Use the SEND example as based and create your custom message, replace it on the turnOn function and then compile. When the terminal is ready, you should be able to send "1" and whatever you decided to do, it will do it.
Be careful! If something is not working, just try with simple command like ON and OFF, after that move on dimming and mood ones.

Wednesday, 13 February 2013

[Python] Monitor directory in linux

I was looking for  something that could tell me when a file has been modified into a specific directory, I found that with Python and Linux, you can use the system call FCNTL.

The system call FCNTL helps you to monitor a directory and call a personalized function when it is happening.
Below you can find an example that I found on Stack Overflow.

Tuesday, 12 February 2013

[JS] Prevent selection when drag

I had a case where I was dragging an object in my canvas and when the mouse was going outside of it, the whole website was selected by my cursor.

I found this fix that resolve my problem:

Friday, 11 January 2013

[JS] Webcam in HTML5

Webcam in HTML5

HTML5 has introduced a few months ago this opportunity to access your personal webcam from a webpage, in that way you can avoid to use any flash plugin to grab a snapshot.
You might asking about compatibility with browsers and this is a bad point for this technology because IE still a step behind from other browsers, you can check to this website.

HTML part
You need to add two tags on your page that are the follow:

JS part
The follow part of code is made that will work cross-broswer:

The next part is to get a snapshot when you press on the video object, that is the follow part:

Now your are ready to try to grab your first snapshot from your webcam, just put everything together and you should see yourself.

Monday, 3 December 2012

[Supervisor] How to Monitor your program

Supervisor is a great program that takes care about the healthy of your application.
The main feature is to monitor your application and then if something happens e.g. crash, it will restart the program.
There is a web interface where you can check the healthy of your programs and check uptime and logs, also you can stop/restart the process.


The follow command is to install supervisor on your Ubuntu/Debian machine:

sudo apt-get install supervisor

The configuration file is located on your etc folder, I found it into /etc/supervisor/supervisor.conf on my Ubuntu.

You can easier add your applications to the file, just following the guide at this link, but I can give you some advice to configure it.
Each application that you want to monitor have to start with this header:

Add your path where the application is:

and the process name


after that you are ready to restart your supervisor and it should start the process, just check it with "ps aux".
If everything is fine, continue to add more features, otherwise go back and check what is wrong.

These are helpful settings that you should have on your process that makes it alive even if it crashes

Also add some settings to save all logs from your application:

After that, restart your supervisor and everything should be fine.

Enable Web Interface
Usually the web interface is not enabled by default but you can do it , just adding these 3 lines on your configuration file

port =
username = user
password = 123

Wednesday, 7 November 2012

[Python] HUAWEI E3131 library

The modem Huawei E3131 is used to connect any pc or laptop to internet through a 3G network, you can also think about it and create a program that  needs a 3G connection.
This model is very useful because you don't need to install any drivers and it works strength away on each operate system, due the clever idea to show this device as a normal Ethernet card.
I used this great product on my Raspberry project and I can say that I am very happy with it!

I found a website that talks about how to use the API with the modem Huawei and which commands you can send.
Check this out to understand what can you do with this little device, on the website is not described all functions but just the basic one.
You can even looking for a specific action when you are browsing the web interface of the modem, it's very simple and clear! Just go to when the dongle is attached on your computer.

I had to create a library to use this dongle with my project, you may not like Python but you can even port my helper class to any other languages!
Just remember that each call have to be sent as XML content

Link of the library

How to use it
The library is very easy to use, just import it on your own project and then create the object:
a  = Huawei()
after that you can easily check if your dongle is already connected, just calling:

Please send me an email if you are going to find any issue with this library or if you want to add some other things.

Implementation with Raspberry