I want to be able in the future to connect the robot with Internet, so I think a good starting point is to design a remote control running on my Android tablet. The target is to create something that can be used for different missions, so I took some time to develop a generic design to cater for different needs.
To create a remote there are basically two options:
- build from the scratch that is program java applets, forms, etc
- use a remote framework
I opted for the second one as I think it is more interesting to focus on the design of the whole system rather than going into the low level details of programming sockets & Co.
I found that the NetIO Controller, is the perfect solution for my needs: very simple to install runs on Android and iOS and, since it uses Python, it integrates perfectly with Raspberry.
Another interesting framework worth mentioning is Openremote.org; looks very promising, but is not easy to install on Raspberry.
After familiarizing with the key concepts the development in NetIO became very intuitive and create controls like the one in the image above is just fun.
The main element of the system are:
- Controller application: available for Android and iOS
- Remote design, done in the cloud and synced (downloaded) with the Android/iOS device
- Python script as a server running on the Raspberry (thanks Stephen’s post I created a daemon)
In essence each time the user generates an event in the remote such as pressing or releasing a button, the controller application sends a string to the Raspberry via the socket managed by the Python script. The script simply loop through if statements and take actions according the signals sent, in the specific example below if the data transmitted is “P1 ON” the Raspberry will change the status of the LED1 pin to HIGH. It is possible to send back some feedback to the remote by using the .conn() method so the remote can also be used to display sensor readings.
data = conn.recv(1024)
if data == 'P1 ON\n':
elif data == 'P1 OFF\n':
I have designed the remote for landscape mode so the controls can be placed at the side of the screen; I tried to pack a many controls as I can without hindering the usability of the remote. The central area is reserved for information, specifically I think it is important to know the status of the system after each command. For this I used a clever feature of NetIO called “Webview”, which essentially it allows to embed a webpage in the remote.
In order to get the status of the GPIO I installed WebIOPi, an automation framework that has, among many good features, a great debug functionality. In the picture above I posted the GPIO layout where the user is able to see the GPIO status.
Source files https://github.com/pfnegrini/Robot.git
NetIO controller http://netio.davideickhoff.de/
post from Stephen C Philiips on how to daemonize a Python script http://blog.scphillips.com/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/