ctypes and uctypes

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:

  1. Obtained and assembled hardware, including a XY-017 TTL converter in a USB stick. This is used to read the incoming RS485 protocol.
  2. 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.
  3. Cycle on #3 above until satisfied.
  4. 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.
  5. Vacillated for a few months. Hey, this is a hobby!
  6. 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.
  7. 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s