One of the new tech-waves is the IoT or Internet of Things. But, what is that? Nowadays, it is very easy to have everything connected and when I mean connected I mean remotely connected. This is something that we have to thank to the new cellular technologies like UMTS and LTE, common known as 3G and 4G. IoT is a concept whose purpose is to give the opportunity to the final user of knowing about the "things", managing the things and enriching the experience with the "things" even without its presence. But which kind of "things"? In a first step, all the electronic devices like Air-conditioning machines, fridges, TVs or even cars and In the next step the "wearables" will try to blow up our concept of living (I will write a post of wearables). But the king and the main catalyst of this movement is the Smart phone. Almost 2 billion of smart phones are working everyday and most of them are using the Android OS.
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:
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:
The main part of the whole system is the server. This server isolates the final users, android phones, and the devices, arduino's boards. This isolation helps us a lot because the final user does not want to know which device is controlling the light of its kitchen (neither do the developer of the android's phone) or image that a device has been changed, we also need to change the logic of all android phones. The latter is disturbing the user. But not all the users are stupid, and leaving direct connection between the users and the devices, so it is a security matter.
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.
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
I began programming a stupid protocol inside my Arduino Mega with its Ethernet shield and I put a led light with a 1K resistor.
The protocol only communicates the ON/OFF of the light and its status.
Arduino's code.
Server
In order to develop the server I have chosen Python and Flask.
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.
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 final user will use an Android phone to interact with the Arduino, through the server.
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.
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 first feeling is satisfaction, because I accepted my own challenge and I did it.
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.
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.