Hobby electronics and hardware hacks have always impressed and inspired me, however it wasn’t until 2012 that I picked up a soldering iron to call my own. Since then I’ve been getting into drones and embedded hardware and dreaming about robots. I’ve even been sniffing around the internet of thangs movement that everyone is so exited about. Looking forward to collecting and using that data.
Earlier this summer, a friend from Sauce Labs told me about the Pinocc.io microcontroller. Pinoccio boards are small, Arduino compatible, 802.15 mesh networked (with wifi handoff) microcontrollers that can be expanded with stackable “backpacks”. Pinoccio boards are designed to be driven via ScoutScript through the Pinocc.io HQ. The Pinoccio HQ web interface provides a great set of tools for building simple Pinoccio projects and provides a websocket API which can be monitored for data from the scouts.
Here at home, Sean and I had some plants which were proving to be incredibly sensitive to moisture in both the air and their potting soil (such is life in the Outer Richmond) and I decided that building a Gardenbot on the Pinoccio platform would be a lot of fun.
Some of the tasks required for this build were:
- Building a sensor circuit with a DHT22 Temp/Humidity sensor, a TSL2561 light sensor, and a handful of DFRobot Soil Moisture sensors.
- Creating a custom Pinoccio sketch to incorporate the sensor libraries, poll the sensors and deliver custom reports to Pinoccio HQ.
- Writing a poller for the Pinoccio API to ingest data into Graphite.
- Setting up alerts based on moisture and humidity levels.
Sadly the project got put on hold awaiting a new tool (toy). However I wanted to put up what was complete and highlight some of the Pinoccio Arduino code. I received a lot of help from the folks in #pinoccio on freenode for the custom reports, and want to document it for others.
Custom Reports
While ScoutScript allows for sending custom reports, they are currently limited to a simple key-value pair, where both key and value must be strings. Submitting a multi-value report can still be done by hand building the necessary JSON string, however given the amount of work already going into the custom firmware sketch, it was easier to mimic the built-in reporting.
Building this functionality seemed straight forward, but wound up being enlightening to some of the inner workings of the Pinoccio firmware.
The biggest mystery was getting the JSON key strings correct. The Pinoccio firmware stores most strings inside a keymap, to allow efficient reuse. Adding a key to the key map seemed straight forward enough, and worked as expected through serial console testing, but the streaming API was still receiving gibberish. The trick turned out to be that the space saving string map functionality was used even for scout-to-scout messaging purposes. This meant that any lead scout which needed to accept custom strings had to have those strings in the same position in their key map. In order to satisfy this map synchronization all that is required is ensuring the keyMap() calls happen in the same order at startup. See the setup{} blocks in the Gardenbot-pinoccio.ino and lead_garden_sketch.ino files for more.
Another gotcha was that the Pinoccio StringBuffer class uses vsnprintf, which within the Arduino libraries only supports string and int types by default. In order to work around this I had to convert float values into strings before sending them into the API report. The Ardunio avr-gcc libraries have a dtostr
method which handles this. This was used for all the values coming from the DHT sensor.
Many thanks to @soldair and Blathjis from the #pinoccio IRC channel for their timely help.