Having obtained the raw protocol description from the vendor, I confirmed many of my earlier observations and now have a working system which can read the information. Like many programmers I approach the problem in a step-wise manner by getting each element working in turn and refining my solution. These are the steps I took so far:
- Obtained and assembled hardware, including a XY-017 TTL converter in a USB stick. This is used to read the incoming RS485 protocol.
- Attempted to read anything from the USB interface. I developed a program (‘disp.py’) to do this and the results are in the Github library.
- Cycle on #3 above until satisfied.
- Started work on a simple sending program on a Pycom LoPy which transmits to my LoRa antenna in my loft. I’d previously got the whole LoRa thing working hardware assembly and work on connecting to The Things Network.
- Vacillated for a few months. Hey, this is a hobby!
- Created a program to read the incoming message from MQTT as The Things Network publishes all incoming messages on a MQTT broker, and by subscribing using the appropriate keys you can read the raw messages.
- Decomposed the messages by using ctypes library on the CPython implementation, and uctypes on the MicroPython implementation.
This latter stage wasn’t so easy, as having muddled through to gain an understanding of how ctypes works and mapping the fields, I then had to learn a new way of mapping bit structures since MicroPython tries to be helpful by removing all the challenges of endian architecture in their implementation and it works different to CPython. It took a good chunk of time to get the normal Python working, and then realising that I had to grok something that looks completely different.
I’ve written some small-n-dirty test programs to make sure I understand this new aspect of MicroPython, and then I will implement it in my actual program running on the LoPy. I also need to create an accumulation as not all data will be sent immediately, and also turn off WiFi radio and set the IoT device into low power state. Lots more fun along the road.