Monday, 7 September 2015

Publishing DHT22 data via MQTT with an ESP8266

Some time ago I picked up a couple of ESP-01 modules with the intention of using them as wireless temperature/humidity sensors coupled with a DHT22.

Initial investigations took place at the Perth Artifactory "Arduino-U" evenings - I managed to put on a nodemcu lua firmware and found a few (varying) dht22 libraries. however I couldn't ever manage to get it to consistently publish the information to my message broker - it'd do one or two and then lock up. I dug it out again recently and decided to have another go - especially as Pete Scargill seemed to be having success with them (running native C).

So trying to 'revert' to a newer espressif release turned out to be non-trivial - installing the relevant toolchain needs multiple bits. I gave up and noticed that there was a newer (0.9.6-dev_20150704) nodemcu release, so I gave that a try.

First discovery - There's native support for the dht sensors in the firmware, so to get the current values all you need is a
print(dht.read(4)) 
So, I trivially modified the example mqtt.client from the docs and uploaded it with luatool. I'd already set my wifi parameters by hand, so it was connecting to the network at power on automatically. Once I was happy that my 'pub.lua' was publishing OK, I added a trivial init.lua (also available on the gist)

Some points to note from that gist:

  • IP address of broker is hard coded. The nodemcu example uses a non standard port - be aware if you copy n paste
  • Although I have a last will, there's no status setting on successful connect. needs fixing.
  • I'd rather have temp / humidity as two separate topics, but I merged them into one json string to avoid having to worry about mqtt publishing concurrently (used to be fragile on the esp8266)
  • I publish every 5s (tmr.alarm) - 2s is the min recommended for the dht22
so I now see a pretty
sensors/ESP-10264640/json { "temp": 16.8, "humidity": 53.4 }
every 5 s ("mosquitto_sub -h broker -t '#' -v" makes for great sanity checking), which is great but not terribly pretty. Thankfully I have a websocket enabled mosquitto broker running, so I'd already dabbled at some html display. so I took jpmens' dial example and altered it to one of the other gauge styles. and lo...

Monday, 15 June 2015

Satellite Tracking / New rotor controller

(it appears I'm about due for my annual blog post entry). Those of you who follow me on twitter will be aware that I've just acquired an old Kenpro 5400 (this is roughly the same as the Yaesu G5500) Azimuth / Elevation rotator, that I plan to use to track cubesats and play with for ham radio.

On opening the control unit (I wanted to see if there were any other primary taps on the transformer, as it's a 110v controller) it was evident it had been 'altered' in the past. To quote someone on #highaltitude "that wiring job is responsible for a thousand dead kittens",

hence a plan was developed to leave the existing controller as an emergency spare and build a fresh 1U rack version instead. The ideas (such as they are) are on a github gist that I'll keep updated with plans. The rough idea being to have a decent embedded board (probably a beaglebone black as a Raspberry Pi depends on an SD card) controlling the relays for output directly, and reading in the potentiometer values to calc position. Using a more powerful microprocessor than say a pic or atmega (arduino) means I can update TLE's automatically and offload much of the tracking directly to the controller - meaning any SDR receivers can concentrate on the signal alone.

I'm also going to house in a GPS module (most likely another one from upu) so that it doubles as a stratum 1 NTP server as well as having accurate position to calculate passes from.




Word of mouth Skye History

Many years ago we lived in the Old Manse in Waternish, Skye. If you look on the maps, you'll spot that unlike nearly all the other house...