Control Raspberry Pi’s GPIO with REST (Qt, WebIOPi)

Abstract

To control the GPIO pins of my raspberry pi, I am using WebIOPi framework. You can thus have a web page to remotely control the GPIO from a laptop, mobile phone or anything web capable on ‘http://192.168.1.x:8000’ where x is the Raspberry Pi on your LAN. You get an interface like this:

snapshot10
But if you want to create a real application to control the GPIO, you gotta need some API.

WebIOPi REST API learnt from bash

WebIOPi provides a REST API. Here’s the API reference: https://code.google.com/p/webiopi/wiki/RESTAPI
I’m assuming you have already installed WebIOPi on your Raspberry Pi and the daemon is running.

1.Install curl on my laptop.
$ sudo apt-get install curl

2. Testing a few commands to see if work. (-u username:password)
2.1 Making GPIO 4 as OUT

HTTP GET /GPIO/(gpioNumber)/function
Returns “in” or “out”

$ curl -v -X POST -u webiopi:raspberry http://192.168.1.x:8000/GPIO/4/function/out

The web interface displays the change automatically.

snapshot11
2.2 Outputting voltage on GPIO 4

HTTP POST /GPIO/(gpioNumber)/value/(0 or 1)
Returns new value : 0 or 1

$ curl -v -X POST -u webiopi:raspberry http://192.168.1.x:8000/GPIO/4/value/1

snapshot12
However, including the above commands in your custom application as a system call is not so desirable because it needs curl to be installed on the target machine and has to be Linux/UNIX type.To make cross-platform apps which run on Linux, Windows and Android, I use Qt Framework.

Qt

To create the above call in Qt C++, it is done like this:

#include<QDebug>

#include<QNetworkAccessManager>
#include<QUrl>
#include<QNetworkRequest>
#include<QNetworkReply>

int main(int argc, char *argv[])
{
int no = 4; // GPIO number
int value = 1; // 1 or 0 for On and Off
   QNetworkAccessManager*manager=newQNetworkAccessManager(this);

   QUrl url("http://192.168.1.6:8000/GPIO/"+QString::number(no)
+"/value/"+QString::number(value));
   url.setUserName("webiopi");
   url.setPassword("raspberry");
   QNetworkReply *reply = manager->post(QNetworkRequest(url),"");
   qDebug() << reply->readAll();
}

You just need to change the URL each time for different functions ;)

Next, i’m gonna create a UI in QML to control the GPIO so as to be able to be used to make a remote controlled car. Stay tuned 🙂

Porn to be blocked by Mauritian Government?

According to some newspaper articles and blog posts [1], the government is planning to block porn websites. They say it is for the “security” of the population. They say such websites contain malware which can infect PCs. This blog post is not about whether porn is good or bad. It is about the government blocking websites of the so-called ´free´ Internet.

If the government can block porn websites today, it would be able to block any other website in the future which doesn’t support its propaganda and gets flagged as “negative websites”

Examples can be the “opposition” website, free press and later, maybe, even Facebook or Twitter.
Why not? Some countries do it already.

Ok. How do you think this law will be put the constitution?

1. The government will block access to pornography websites which poses as a security threat to the population.

Or

2. The government may block access to websites which poses as a security threat to the population such as pornography websites…

These two statements above may look the same to some people. But it is not. Read then again. They’re doing different things.

The discussion on porn can be a mere distraction. Parents, religious people would support the government the decision. But something else could be done at the end.

Conclusion

Everyone knows porn websites are “risky”. We don’t dictatorship methods to be tested on us.

GNOME 3.12

KDE 4.13 is powerful as hell. But it is just a generic or classic desktop that awaits for the user to customise it. GNOME on the other hand aims to provide the user with a workspace. A delightful experience!

GNOME is based on the GTK+ toolkit which i believe not to be the on bleeding edge of technology as Qt actually is with it’s innovating QML technology.

GNOME, says to me:

Hi you there, welcome! Let me hold your hand and walk you around. You want to hear some music? You want to start working? Just type in your command and i’ll do it for you 🙂

Here’s how the menu or dashboard looks like. Type any program or recently used files here:

snapshot5

Vertical space is very precious in modern 16/10 screens. GNOME knows that very well. It takes minimal amount of your screen and allows you to focus on what you have to do. Let’s compare reading a PDF in KDE 4.13 and GNOME 3.12

Reading PDF on Okular (KDE)

————–

Reading PDF on Document Viewer (GNOME)

Saw the difference is readable space?

GNOME is dedicated to offer you an experience as stated before. You’re listening to music while working. You press the next button on your keyboard, a non-intrusive notification appears at the bottom of the screen which disappears by itself after few seconds.

Screenshot from 2014-04-29 21:13:06

If you want to know more about the song, just put your cursor over it, it expands revealing more controls.

Screenshot from 2014-04-29 21:13:12

Click on it, the full music app shows up. Genius! Choose the song you want then close it. Continue working as if nothing happened.

rythmbox

Conclusion

Despite KDE apps like Dolphin, Okular and all have much much more feature and are more powerful, using GNOME apps at first seems such a great experience 🙂

In an ideal world,i’d like GNOME to be written with Qt Framework and QML. Or GNOME ‘Human Interaction’ team to take over KDE Plasma and make KDE rule the world. Or just forking existing KDE apps into GNOME. Do try GNOME 3.12 😀

Killing your own people

I always thought it is illegal to kill your own people. For example, in the Arab Uprising, the ex-governors were trialled for giving orders or allowing police/army to shoot the people. Reading the Mauritian Constitution, i was kinda surprised to have read the following in section 4:-

(2) A person shall not be regarded as having been deprived of his life in contravention
of this section, if he dies as the result of the use, to such extent and in such circumstances

(c) for the purpose of suppressing a riot, insurrection or mutiny;

I’m no lawyer. Wondering why the so called “dictators” are trialled for their actions during uprising period. Is it really illegal to shoot at rebelling people in their countries?

Anyways, hope Mauritius doesn’t become dictated country.