resources

what

go-cutie

goqtt is a MQTT 3.1.1 Client library written in Go. It is my first Go package, and really my first project in Go. I guess it was also my first low level networking project. Lots of firsts in here!

goqtt is a different type of project than I normally do, for a few reasons. First and foremost, it started out as a class project. I was taking CS 594, Internetworking Protocols at Portland State University, and for the course project we had to implement a network protocol (surprise surprise). I chose MQTT as the protocol and Go as the language.

I knew that I wanted to use MQTT in a separate project, so I was probably more motivated than normal, but also learning about the protocol from the ground up seemed fun and interesting.

Sidebar - I haven’t had a course project in many years

why

The main reasons I chose this project were:

  • Learn about MQTT
  • Learn Go
  • Create something useful for a different IoT side project

MQTT is a super common protocol for IoT devices as it’s lightweight and the pub/sub model is great for sending and processing data common to IoT devices, such as sensor information. Because of this, I’ve been interested in it for a long time and I felt that writing a client library would be a great way to get familiar with it.

After the course was finished, I felt like I did gain a pretty good grasp on the protocol. However, I kept working on it.

learnings

I kept working because I wanted to keep learning Go. I had started when COVID-19 forced everyone inside and my first impressions were very positive. Also, the end of the course left me with a couple specific topics I wanted to further grasp; namely interfaces and channels.

I found goqtt to be a great project to help explain these. With the MQTT control packets, e.g. CONNECT and PUBLISH packets, I was writing the same boilerplate over and over again. I created an interface here to help reduce some of the complexity of reading in the packets. See PR 7 for more info. A lot of the boilerplate was still there though. I was thinking this would be a good place for generics, but I’m not really sure. I know in Python I probably would have reached for a base class and inheritance.

Part of the course project was writing a server/broker as well as the client. Creating a MQTT broker, albeit a basic one, was a great way to be introduced to the power of goroutines and channels. This isn’t part of the package anymore, see PR 11 for when it gets removed. Overall, I was pretty impressed by how powerful it seemed to use a goroutine per client connection and channels to pass around information.

Finally, it felt like writing a low level (is this considered low level?) library was teaching me not only about Go, but about computer science fundamentals that I never get exposed to using Python, e.g. encoding/decoding bytes.

current status

To me, the project is about as useful as I need it to be; in that I can use it to save sensor data to InfluxDB.

I’ve mostly accomplished my goals: I feel good about MQTT, I’ve learned some Go, and I’m using this project in another project.

However, the library isn’t fully compatible with the MQTT 3.1.1 specification. This is mainly around the QoS that is supported and things like last will messages. See the README in the repo for more details.

I want to continue to work on the library until it is fully compliant with the MQTT 3.1.1 spec, but I’m not sure if it’ll get that far. Likely, I will implement TLS connections and then fix bugs as I find them.

If more time comes my way I will add more support for higher QoS messages - and contributions are always welcome.

Also, look at that logo..