Progress is being made on the Smart Home project! I finally got the GrovePi+ with sensors I talked about last time.
It was almost everything I ever wanted. There are a few things that bothers me slightly, but it is not enough to bring my spirits down. I love Grove!
While I was waiting for the Grove stuff to arrive, I started creating a new application I knew I needed in my system: Something to save all the MQTT messages to a database.
MQTT-Message-Cataloger
I needed a pretty simple application. Something to listen to MQTT messages on specific topics and save those messages to a database. That way I can have other applications fetch data from said database and use it for stuff (like displaying statistics and other things, Im sure).
The application is written in Python and is thought to run on a Raspberry Pi (of course - where else!?). It uses a config file to set up connections to the MQTT broker and a Mongo Database. You give it a list of topics to listen for, and just let it loose.
The code is available at Github:
https://github.com/bjaanes/mqtt-message-cataloger
Grove
Let’s just start out with what I didn’t like about the Grove stuff: The documentation isn’t always 100%. The language is sometimes a bit lacking, and it seems outdated some places. It works, and you usually don’t have to mess too much around to make things work - but it’s not perfect.
However, it DOES work. And it was so nice to have software problems, instead of hardware ones. I can understand software issues - those are easily debuggable. It was heaven compared to the Ardunio mess.
Setup
To install the needed software and prepare you Raspberry for the Grove, just follow this guide:
http://www.seeedstudio.com/wiki/GrovePi%2B#Get_Started
Try testing it with a sample project (based on which sensor you got).
I tested with the Temperature sensor:
Using the following instructions:
The instructions said to plug it into D3, but I found that the code used A0… That’s OK, just plug it in A0 instead.
Trying it for real
The next step was to create a “real” test application with all of this. So I created a small application to read the temperature and publish it to the MQTT broker.
First I had to install the Grove libraries globally like so:
Inside Software/Python (This is inside the folder downloaded in the setup guide):
sudo python setup.py install
I could then create a script like this:
#!/usr/bin/env python import paho.mqtt.publish as publish import grovepi import time sensor = 0 def readTemperature(): while True: try: temperature = grovepi.temp(sensor, '1,2') publish.single("office/temperature", '{0:0.1f}'.format(temperature), hostname="192.168.10.200") time.sleep(2) except KeyboardInterrupt: break except IOError: print "IOError happened" readTemperature()
Woho! It works!
I have now ordered more Grove components and more Raspberry Pi’s. More is coming soon!
Follow me on Twitter: @gjermundbjaanes