Logging temperature using a USR-HTW,, Grafana, InfluxDB and of course Docker

I've previously posted about running InfluxDB and Grafana using Docker. This post covers getting data from a USR-HTW temperature sensor and weather data from


The USR-HTW is an inexpensive, Wifi enabled temperature and humidity sensor. Although it doesn't have a documented API, it's already been reverse engineered.

Data is retrieved from it by establishing a TCP connection to port 8899 then periodically (roughly every 15 seconds) packets will be received that can be decoded to the temperature and humidity reading.

I've written a Dockerfile which is just a minimal Alpine Linux container with python and curl installed. I also add the script for retrieving the data from the USR-HTW sensor and from

Running the container

docker run --name usr-htw --restart=always -d --link influxdb:influxdb tomdee/usr-htw <ADDRESS OF USR_HTW>

The container is configured to always restart (because it will die if it loses contact with the sensor)

It's also linked to the influx DB container so it can store it's data there.

Script details

The script itself is just a simple "while True" that blocks on data coming over the TCP connection then pumps it into influx DB using curl. Not super efficient but it doesn't need to be"curl -sS -i -XPOST 'http://influxdb:8086/write?db=tomdee' --data-binary 'temperature,room=XXX,location=YYY value=%s'" % temp, shell=True) provides both forecast and historical data for a multitude of weather related data. They have an excellent API that's simple to use and crucially free (for up to 1000 reqs/day).

Running the container

The USR-HTW container has the script in it too, so running it is very similar.

docker run --name usr-htw --restart=always -d --link influxdb:influxdb tomdee/usr-htw <FORECAST API KEY>

You can get an API key from

Script details

Another simple script that grabs the json from, reads the JSON then curls the result to influxdb.

The API call explicitly sets the units to be "si" and excludes all the unwanted forecast data.,hourly,daily,alerts,flags


Putting it together

I've been collecting data for a number of weeks now. I've created two dashboards in Grafana, one which doesn't aggregate the data and one which aggregates it daily (since the weather follows a diurnal cycle)

Grafana   Weather   Vicksburg Grafana   Weather   Vicksburg   Daily


Getting started with USR-HTW temperature/humidity sensor.

I've always wanted an easy solution for logging temperature and humidity in my house. I've messed around in the past with Arduino and Raspberry Pi based solutions, but inspired by a recent post on Hackaday I finally took the easy option and bought a WIFI enabled sensor. The hackaday post refers to a blog post detailing the simple communication protocol that the unit uses which seemed perfect for rolling my own simple data logging solution.

I ordered a unit off eBay and it arrived from China only a week later. Powering it up was a breeze (I used a standard wall wart power supply that I had knocking around) but connecting it to my network took a bit longer because of the flakey web UI that the unit has. It acts as an access point, so I could connect to it to give it my WIFI network credentials. Unfortunately it doesn't cope well with SSIDs that have spaces in them. I took this opportunity to set up another DMZ guest network on my router and once that was working everything connected fine.

I cribbed the code from the OzoneJunkie blog post but changed it to not rely on NumPy. The code is available on GitHub.


Tagged as: No Comments