Recently I posted on using MQTT to collect air quality data from an IKEA VINDRIKTNING air quality sensor. The WiFi around my house appears to be subject to numerous, brief interruptions, causing problems for the TCP connection MQTT maintains between client and gateway. For the devices that need to deep-sleep, MQTT-SN is used, but it would preferable to use a single protocol for both wall and battery powered devices.

Trivial File Transfer Protocol (TFTP) offers a connectionless transport for file transfer, with a single outstanding response/request handshake over UDP. Files are serialized into 512 byte packets, by default. Since Toit allows rapid encode/decode of int, bool, float, string, ByteArray, List or Map via tison, TFTP might be a useful transport between two Toit agents. As described in RFC 1350, TFTP lacks security.

The initial experiment was for a seedling greenhouse, primarily measuring temperature and humidity, using a BME280 running off a 500mAh LiPo.

setup.jpg

The facility to write files (WRQ) was implemented and a simple web page was generated on the ESP32 and sent to a Raspberry Pi 3B. The Pi was running a TFTP-GO server (to demonstrate some rudimentary specification compliance), delivering the index.html file to an “asset” directory, that was served by a tiny webserver. The webpage looked like:

webpage

At a little over 1200 bytes, the page typically took less than 40mS to send. As implemented the client attempts to send a message 3 times, with an increasing backoff, which many times is sufficient to overcome the issues of my network (and the 3 stud walls + 1 block wall, between the router and greenhouse).

JAG was used for development, but all the tuning and modifications were made remotely using Artemis. The device.json file declares the application trigger interval as 450 seconds, between which the device deep-sleeps, courtesy of Artemis. A toy RingStore (conceptually similar to the RingBuffer, but backed by a storage.Bucket to persist the data across deep-sleeps) is used to provide a min/max record over a sliding 12 hour window.

Tailscale, a “zero-config business VPN”, is used for the Pi, my computers and cellphone. The Pi then has a secure, fixed IP4 address making the webpage readily available to the browser on all my devices, including the phone (no app required).

The code is available here. The experiment has worked well enough, now to build out the rest of the protocol and implement the packet size negotiation option.