IoT Sensors with InfluxDB

I’ve discovered rather that microprocessors are rather cheap these days, and development kits that originally went for 20$ – 50$ can now be had for less than 10$. An ESP32 averages 6$ and the Pico series is roughly in the same place. Why would I would even need such a thing? I have other, significantly more capable machines. But the benefits are not in the compute – they are built for embedded systems where size and energy are primary concerns.

The question then becomes, what do I do with such a thing? What data could I even collect?

After scrounging through some of the old electronic kits from my time in college, I’ve come up with an assortment of sensors – a thermistor, a photocell. Since I already have an easy way to measure resistance with the picozero.py library, all that is left is set up a connection to a database.

Rather than trying to present data as a webpage and have Prometheus scrape it, I opted to push data to InfluxDB. Prometheus does not allow push metrics – which meant that I would have a harder time with data collection if my sensors did not update fast enough. Additionally, this method integrates well with my own alerting system.

However, file-size restrictions prevent usage of the Influx Python library. The urequests library for Pico does implement HTTP POST methods, so all that is left is translating the curl command into a requests function, and then into a urequests function. There are minor differences, but for the sake of this project, they are negligible.

View the code on GitHub.

Notes:

  1. The Pico does not draw enough current to run off a battery bank. while my code does include indicator lights, they can be safely omitted if you have a ‘dumb’ battery pack or draw more than 15 mA.
  2. Micropython’s urequests does not have HTTPBasicAuth – but authentication can simply be included in the header, as long as you to encode it.
  3. InfluxDB is not ‘technically’ RESTful, and the newer standard takes line protocol formatted strings rather than json.

Posted

in

by

Tags: