Therefore, after all this information I wanted to build a PoC in only one day. The motivation was to create a system with the capacity of managing different devices (Arduino's boards in this PoC) using an android phone. In internet there are a lot of examples which show how to connect your mobile to your arduino's board but I was looking for a whole system.
The architecture of the system that I thought is the following:
If we add more devices to our home in order to have more control of it, the mobile phones will not have information about the new devices, which is a discovery matter. And imagine how we can scale this system if the connections are direct!!! So it is also a scalability matter.
Arduino
The protocol only communicates the ON/OFF of the light and its status.
Arduino's code.
Server
The server communicates with the Arduino, therefore it has to know my "stupid" protocol. Only the server will be the entity that will communicate, directly, to the Arduino.
The Server has a REST API to communicate with it. This door will be used by the Android phone. The API provides the devices that the user has access and the Arduino's operations (ON/OFF and status).
Server's code.
Android
The Android's code will only have two Activities: The first one is used to get the devices that the user has access and the second one to interact with the chosen Arduino, in this case the only one that we have.
Android's code.
Demo
Conclusion
The protocol for the Arduino was not a real protocol. For a more serious project I would use a real one. Modbus would be more than enough. But the Arduino has worked really well, although for this project a Arduino Ethernet board would have been more appropiate.
The election of Python and Flask for the server was a success. It is so easy to have a REST API with Flask and Python gives you flexibility and speed. For a real project I will probably chose Python and Flask again and I will model the device-user interaction in a DB, in this case a relational data base. Although I have used my own pc, the first idea was using a Raspberry Pi. The RPi can be enough if you have neither a lot of devices nor a lot of users.
I really love Android. I think that is a very flexible platform; hence you can do a lot of cool things. Besides, it was the phone that I had, so ...
At least, it worked !!
This project is in github.