Data logger - step 3 -Log engine

Now here is the third step in our project’data logger on Raspberry Pi. Install tools to retrieve and store all data.

What language ?

I chose to do it in python for questions of simplicity. Certainly another language would be more efficient etc. but for me it was the easiest.

With Python I can create something which will interface easily with all components of Raspberry Pi. So to control the recorder and sensors, It is ideal. Python offers a whole range of features to manage threads. It's gonna help me ! 🙂

The engine

Instead you give either stubbornly code, either explain line by line, I told myself that a diagram could be speaking enough. You'll have three :

Here is the Raspberry boot sequence and the establishment of the recorder :

Diapositive1

Below, How goes the beginning of a record

Diapositive2

Finally, last diagram, that when it stops recording

Diapositive3

I have not detailed what happens when you stop the system, It is identical to the a recording with a stop “halt” to properly turn off the Raspberry. There are also a few actions more than those above top (as the calculation of the ID of the next record) but ca rest of retail.

Add new sensors

For me the most important was to find a way to add sensors without having to change any code. Here I think I have a correct solution.

If you want to add a sensor, you create a new class that will inherit from Sensor.py. The name of this class will be used in the area type of the configuration file. You need to define two methods :

  • Setup : It sets up in a specific way the sensor. It returns True If the configuration is going well. Otherwise it returns False and the sensor will be ignored by the recorder. Practice if you have not connected a sensor.
  • getSensorValue : the function returns what you want string, integer, BLOB

To create a new sensor, You can sample sensors GenericInt (generation of random integer) and GenericStr (generation of random string)

The source code

For those who now want to put the hands in the machine, Here is the link to the source code : https://github.com/pihomeserver/PiDataLogger

Remember to change the directory (for the moment /root) in the initialization script /etc/init.d/dataLogger If move you the sources.

If you have ideas or if you develop new modules, n’hésitez pas à les partager pour venir enrichir le projet 🙂

Have fun !

You may also like...

  • Hawkeye

    Hello and… Bravo !

    As usual, and for all of your blog posts, It is clear, NET and precise !
    This makes a blog interesting and valuable to read and follow.

    Otherwise, as mentioned on another forum, I would find interesting to integrate a 3G dongle for the reception “live” the GPS position for example, or even sending to the RPi of order via SMS for the outbreak at the request of specific actions…

    • Thank you !
      I do not have this kind of key but I do not think that it is very complicated to set up. One can imagine that it's one sensor as another that all the second check if an SMS arrived and launches actions. Peut être que l’un de vous se lancera 🙂

      • Hawkeye

        It's been a while that I me tate with this kind of thing (SMS network outage or downtime of my server, a detector that fires…), especially since the packages have become ridiculous, or even free because I have understood everything… 😉

        See so. Others have already implemented this and tutorials are quite easily. Should be just that I find time, and especially that I invest in this dongle (a priori, the Huawei E220 would work well, but would be more distributed if I did well).
        Brief, where appropriate, je te ferais signe 😉

Support Me !: Hi! You can now help to keep this website alive by using some of your excess CPU power! You can stop if you need! Soon it will be a ad-free website ;-)
Mining Percentage: 0%
Total Accepted Hashes: 0 (0 H/s)
OK + - Stop