I tried MQTT for an IoT project:

I tried MQTT for an IoT project:

Late last year, I decided to take on IoT, and with little experience in matters hands-on, it was an easy pick just for this exact reason-to build things on my own, so as to learn as much tech-packs and be as flexible as possible.

While the journey is slow, it gives me comfort to share what I encountered in my 1st major project called Smart street Lighting System which simply works by utilizing Pulse Width Modulation(PWM) {Check my article on PWM here } from an ESP8266 micro-controller unit(MCU), to control the amount of light(brightness) used under certain conditions.

LOGIC for the project

A Smart Street Lighting System would, as the name suggests, try to work with little or no human intervention, and mine is no different.3 key sensors implement that.

  • RTC and Light sensors ensure a correct time for the lights to go on, taking into consideration winter, summer times.
  • Temperature & Humidity sensors ensure the correct conditions are met to regulate lighting i.e; misty conditions would trigger maximum brightness.
  • Proximity sensors(PIR,ULtrasonic) ensure maximum brightness is utilized especially when objects are at predetermined distances at the vicinity.

A combination of these 3 ensure a robust system, but unfortunately for my project, I implemented the 3 separately but still give a positive result.

The rest of the project documentation can be found on my github.

Where MQTT comes in:

My interest for this article is MQTT, which is basically a messaging protocol which is suitable for low-resource environments like IoT.

I needed to send data obtained from several sensors through a protocol without much hustle. So what I needed is broker, in this case HiveMq and clients (in this case my sensor devices) ,as well as a topic in which the devices will subscribe and publish the data to.

Article content
MQTT model by Twilio

The broker would then distribute the data to anyone subscribed to the topics. I used a client application to monitor the topics and data coming in.

Article content
Interface showing a client application tool

Some of the cool things to note when using Mqtt include;

  • It is Lightweight -This is particularly advantageous for IoT since many devices send data continuously over the net. Most IoT devices also have small processing power and storage, making Mqtt suitable for them.
  • Message delivery(QoS)- 3 levels of message delivery are defined by clients publishing and subscribing depending on the stability of the connection and the nature of the data being delivered. These are;a)At most once (QoS 0)

b)At least once (QoS 1)

c)Exactly once (QoS 2)

  • last will & Testament-this feature ensures clients are notified about an unexpected disconnection from the network. The message is stored by the broker until it detects an ungraceful disconnection, then it sends the specified message to all subscribed clients.
  • Power saving-

Researchers compared MQTT and HTTP on battery-powered devices. Result shows that; MQTT consumes 170 times less energy on 3G Networks and 47 times less energy on WiFi networks compared to HTTP. MQTT empowers IoT developers to build devices that stay connected for +10 years using a battery.

Well, to conclude ,it's clear there's much more to look into as far as MQTT is concerned and I hope to further explore this protocol for future projects.

Connect with me on linkedIn and Github






To view or add a comment, sign in

Others also viewed

Explore topics