Most systems have two different parts: the user interface and the 'engine'.
The user interface:
The user interface is - as the name indicates - the part of the system where the user interacts with the system. This involves giving the system commands to do whatever you want it to do, at get the result in a way that can be seen by the user.
We often want the user interface to be smart and good looking. Graphic presentation is often preferred over stupid figures. A web application is a good way to accomplished this, and at the same time makes the interface available on several different platforms.
The 'engine':
The engine is the interface to the electronic world. It could be logic to read temperatures, control relays, manage time, access data and so on.
The engine must be able to handle hardware and data of any kind in an efficient way.
The combination:
The user interface and the engine must have a way to communicate with each other. As the communication between the user interface and the engine is limited by the user’s ability to interact with the user interface, this communication does not have to be very fast, but preferable standardized in order to have flexibility to access the system from several platforms.
I all my systems, the standard modules consist of the following:
- The engine is based on Node.js, because there are so many modules available to interface with all types of hardware and data. The JavaScript-like programming is well known and far more productive than C or C++.
- The transport mechanism to the user interface is a web-server, which is part of the Node.js engine. I take very few lines of code to establish the web server in Node.js.
- The user interface is designed as web-pages. In the past, any action on a web-page would result in sending a new web-page to the browser. This resulted in flickering screens and much data to be send back and forth. Therefore my user interfaces usually consist of only one web-page. This one web-page handles all changing of pages internally. Only changed data are transmitted to the web interface or send to the server. To improve the visible part and ease the programming of the user interface, I use jQuery, JavaScript and html.
- To handle the transmission of these data I use Socket.io. An interface available for both Node.js and html pages (java script);
That is all. To get access to an application, I open a browser window and write the URL of the application like http://my_rasberry_pi:86 where 86 is the port assigned to the applications web-server.
- Sometimes I use a web-server on another platform for performance reasons. In those cases, the engine only handles the communication of data - not the web-pages.
Updating the port forwarding in the router makes the application available from the outside world. Useful if you want the use a home automation application.
So - what do you need to do?
- Install Node.js
- install node.js
- install forever
- install socket.io
- Install web server for node.
- write your node app
- write your web-page
- you are done!
You can download a scelleton template of an application here (including web-page)
If you want to start the system when the Pi is started, you need to do a few more thing.
What is next?
Go ahead. Find your project and start coding.
Some of my projects are:
- House automation system for my vacation house. Control temperature and monitor heating fuel level.
- This project uses OneWire communication to monitor temperature around the house.
- The oneWire device to monitor heating fuel level is implemented in an ATTiny85 with an SRF02 to measure the distance to the oil surface. The calculation of remaining liters in the tank is then calculated in the ATTiny85 and reported to the Raspberry Pi via the OneWire link.
- Relays are also connected to the OneWire link and they control the burner and the hot water circulation pump.
- When I am away from the house, the temperature is controlled to min 13 degrees and the hot water circulation pump is stopped.
- When I am visiting the house, the min temperature is set to 25 degrees (controlled individually by thermostats) and the hot water pump is running during day-time only.
- All values are saved in a MySQL database and can be presented graphically. The MySQL database is not located on the Raspberry Pi but remotely at my internet provider.
- System monitor for controlling health of systems.
- Each system (application or platform) is set to send a TCP message on a certain interval. Ff the monitor system is not receiving the message within an interval; the monitor program will send me an email and a SMS message to my phone.