Holiday, Reflections

Finally Vacation :-)

Finally it is vacation time again – and I can spend some precious time with my family 🙂

17th May Celebration

The summer starts (as always) with the celebration of the Norwegian Constitution Day – the national day of Norway – and is an official public holiday observed on May 17th each year. Among Norwegians, the day is referred to simply as syttende mai (lit. “seventeenth May”), Nasjonaldagen (The National Day) or Grunnlovsdagen (The Constitution Day).

20190517_102423557_iOS

The Constitution of Norway was signed at Eidsvoll on May 17th in the year 1814. The constitution declared Norway to be an independent kingdom in an attempt to avoid being ceded to Sweden after Denmark–Norway’s devastating defeat in the Napoleonic Wars.

546398_10150796919012691_287569939_n.jpg

The unique tradition of the celebration of the 17th of May brings some complexities. That is the reason why it is often confusing and hard to understand for a new-comer to Norway with all the fuzz during the day. The children carry flags and march together with bands. Ice cream, hot dogs and other goods to eat are abundant. The buildings are decorated with Norwegian flags and women and men of all ages dress in their Bunad, or national costume. Graduating high school students wear their russedress and celebrate the approaching school year’s end. The sound of loud music is heard from every corner. Understanding of all these 17th of May traditions requires some historical and social background knowledge.

Sweden Rock

Working in Sweden, I had the opportunity to attend the Sweden Rock festival. Classic rock, hard rock, metal and even some blues – something for all tastes. Clean and neat, safe and secure. Ocean-near location, cozy grass hillsides and real lavatories. But most of all, a really friendly and good-natured atmosphere. Like one big family, with members from over 50 countries. The best audience in the world, quite frankly.

20190606_184818343_iOS

The festival ran from Wed, 5 Jun 2019 – Sat, 8 Jun 2019, and I had a really great time in one one of the most exhilarating festival in the world. It promises to be a good time.

Tons of Rock

Lagends like Kiss, Def Leppard and Satyricon played at Tons of Rock, and I was overwhelmed to attend this great event!

file-1.jpeg

Dream Theater had a great show, celebrating the 25th anniversary of the masterpiece “Images & Words” with us at Ekebergsletta.

Maintenance and Spring Cleaning

Spring is the time to roll up the sleeves and fix whatever the long winter has torn down or wore out. Painting the house, cleaning the back yard and of course applying antifouling paint on the boat to keep the sea-weed away.

20190718_113241512_iOS

I also took the time to fit out the shed with a hardware lab, so the family and myself can work on mechanic repairs outside. The first task at hand was to fix the injection fuel pump for the boat as this had corroded during the winter.

Sun and Sand in Spain

This year (as always) we will go to Orihuela Costa in Spain. Orihuela Costa is a coastal region situated on the Costa Blanca in the province of Alicante. It sits close to the border with Murcia, near La Manga and the beautiful Mar Menor. Despite its name it is actually around 20 kilometres away from the main resort of Orihuela.

WP_20160617_23_52_34_Rich.jpg

The region covers several resorts including Punta Prima, Playa Flamenca, La Zenia, Cabo Roig, Villamartin, Campoamor and Mil Palmeras.

Orihuela Costa is an ideal destination for those looking for a beach family holiday, with 16 kilometres of diverse coastline. It is also an excellent choice for golf holidays; in fact Orihuela Costa is well equipped for all needs, with lots of amenities, facilities and leisure attractions

Cartagena Roman Theater

The theater was built between 5 and 1 BCE, and for centuries was covered by a cathedral built over the upper part of the the theater’s “cavea,” or seating area. The first remains were discovered in 1988, and the theater underwent restoration, completed in 2003. Today the ancient arena still holds performances, and there is a museum at the site displaying the finds from a series of archaeological excavations.

Cartagena looking over the Roman Amphitheater, Spain-1_low

Alicante Castle

Alicante boasts many treasures. And among its most prominent is indisputably the Castle of Santa Bárbara, which stands on Mount Benacantil overlooking the city. Hewn from millenary stone, this fortress has witnessed centuries of history in this ancient city and even played a leading role in several chapters.

Alicante Santa Barbara castle in Costa Blanca, Spain-1_low.png

Leisure and Activities for the Kids

Not living the kids out, there would also be fancy events and activities they can do to make them enjoy this holiday. I understand that visiting some of these places can be a bore to them, and some places may even be over exiting..

file-2

Music and Entertainment for the Dad

Every Tuesday and Friday I will go to the lunch jam at El Rincon Del Tio Cali where the local musicians will entertain and involve us in fantastic musical experiences. I most likely would be visiting here on my own probably after the kids have gone to other fancy places to catch fun time.

20180807_144102478_iOS

Leyendas del Rock

Leyendas del Rock is a rock and metal festival that takes place in the city of Villena, Spain. Now celebrating their fourteenth edition – and the seventh consecutive year in it current location – the festival has become a respected date in the calendar of heavy metal fans thanks to the lineups of the scene’s favourites.

With more than 60 performers spread across four days and five stages, the high-octane display of hard-hitting rock sounds will this year be headlined by Australian four-piece Airbourne and legendary Irish rockers Thin Lizzy, among others.

20180810_224013993_iOS

So, have a nice vacation everyone – I will see you again in 26th August 🙂

Gunnebo Business Solutions, MQTT, Protocols

MQTT for Dummies

In this article, I will be discussing one of the most trending topics in IoT. I will take you through a beginner level tutorial on MQTT which is currently the most used protocol in IOT projects. 

MQTT Message Queuing Telemetry Transport-1_low

MQTT stands for Message Queueing Telemetry Transport Protocol. To put MQTT in a nutshell, it is  “A lightweight event and message-oriented protocol allowing devices to asynchronously communicate efficiently across constrained networks to remote systems”. I know that this doesn’t really help much. So let’s try to decode that definition and understand what MQTT is and how to use it.

What is MQTT?

Again, for people who have no idea about MQTT, it is a protocol for machine-to-machine communication. It uses a publisher-subscriber model for communication. If you are from a programming background, you probably would have some knowledge about the publisher-subscriber model. Anyway, we will discuss the publisher-subscriber model and how MQTT works later in the tutorial.

MQTT over HTTP for IoT

Before going onto discuss how MQTT works, let’s first try to understand how it came to existence. MQTT came to exist as a replacement for HTTP because HTTP could not properly answer the challenges in IOT and M2M projects. Unlike web applications, IOT projects have some peculiar challenges. One of the main concerns is that IOT requires the event-driven paradigm. Some of the features of this event-driven paradigm are:

  • Emitting information one-to-many 
  • Listening to events whenever they happen 
  • Distributing minimal packets of data in huge volumes 
  • Pushing information over unreliable networks  

Some other challenges you face in an M2M application 

  • Volume (cost) of data being transmitted 
  • Power consumption 
  • Responsiveness 
  • Reliable delivery over fragile connections 
  • Security and privacy 
  • Scalability

MQTT was successfully able to cope with these challenges due to their features. 

Why MQTT is good for M2M and IoT applications

MQTT has unique features you can hardly find in other protocols, like:

  • It’s easy to implement in software as it is a lightweight protocol.
  • MQTT is based on a messaging technique. This makes it faster in data transmission compared to its alternatives.
  • It uses minimized data packets which results in low network usage.
  • Low power usage. As a result, it saves the connected device’s battery.
  • Most importantly it works on real-time which makes it ideal for IoT applications.

We learnt earlier that MQTT works through a publisher-subscriber model. In a P2S system, the publisher sends its messages to a topic. Then, every subscriber of that topic will receive the message. In MQTT, Broker handles the topic and messaging process while MQTT clients behave as publishers and subscribers.

Components of MQTT

To learn about how MQTT works, we have to understand some concepts in MQTT. The fundamental components of MQQT protocol are explained below.

Broker

The broker is a server that handles the communication and data transmission between the clients. It is responsible for the distribution, management and storage of data sent and retrieved by the clients. The broker acts like a centralized hub that regulates the message exchange. 

In the case where a broker breaks down, the whole communication process breaks down as there is no way for the clients to communicate with each other directly. Therefore, the Broker Bridging mechanism was introduced to prevent such cases and build a fail-safe broker network. 

There is a number of broker applications available on the internet including the popular ones; Mosquitto and HiveMQ or you can also use cloud-based brokers from cloud providers such as IBM or Azure.

Clients (Publisher, Subscriber)

These are basically the end-users who retrieve the data distributed by the broker. Each client is assigned a unique ID to identify themselves and the session when connected to the broker. A client could either be a publisher who publishes messages under a specific topic or a subscriber who receives messages relevant to a topic, at one time.

Message

These are the chunks of data sent and received by the clients. Each message consists of a command and a payload section. The command part determines the type of message and there are 14 message types available in MQQT.

Topic

This is the namespace or literally the topic that describes what the message is about. Each message gets assigned to a topic and clients can publish, subscribe or do both to a topic. The clients can also unsubscribe from a topic if they want to. MQTT topics are just strings with a hierarchical structure. 

Assume that there is a topic called “home/kitchen”. We call home and kitchen as levels of the topic while home being topper level topic than the kitchen. Also, topics can use wild cards such as ‘+’ and ‘#’.

Publish

This is the process of clients (Publisher) sending data to the broker under a topic be distributed among the clients (Subscriber) who have requested data from the same topic.

Subscribe

This is the process of Clients (Subscribers) receiving data specific to a topic they have previously subscribed to, from the Clients (Publishers) through the broker.

QOS: Quality of Service

Each message is given an integer value from 0 to 2 to specify the delivery mode. This is known as Quality of Service. There are three different types of QOS.

  • 0 (Fire and forget) – the message is delivered only once, acknowledgement not given, high-speed delivery method.
  • 1 (Acknowledgement) – the message is delivered once or several times until an acknowledgement is received. 
  • 2 (Synchronized) – the message is delivered only once, guaranteed delivery, comparatively slower.

Practical use of MQTT

Its time to do some practical things here and get used to dealing with the MQTT protocol. As you learnt previously, there are many MQTT clients developed for each programming language.  I will use Paho python MQTT client as I am a fan of Python and it is probably the best MQTT client out there. 

mosquitto-text-side-28

First, you need a broker to create an application with MQTT. One of the most popular MQTT brokers is Mosquitto. You can install it with the following command. 

sudo apt-get install mosquitto

We set up it to work on our localhost. By default, Mosquitto listens to port 1883. Next, install the MQTT client with pip command.

sudo apt-get install mosquitto

We setup it to work on our localhost. By default, Mosquitto listens to port 1883. Next, install the MQTT client with pip command.

pip install paho-mqtt

This command will install python MQTT client library on your machine. The core of the client library is the client class which provides all of the functions to publish messages and subscribe to topics. 

There are several important methods in Paho MQTT client class which you should know:

  • connect()
  • disconnect()
  • subscribe()
  • unsubscribe()
  • publish()

Each of these methods is associated with a callback

Publishing a message

One of the main tasks you do with MQTT is publishing messages. A simple code that publishes a message usually has 4 steps.

  • Import the paho.mqtt.client class
  • Creating a client instance with Client() constructor
  • Connecting to the server with connect() method
  • Publish messages with publish() message.
import paho.mqtt.client as mqtt

clientName = mqtt.Client("uniqueClientId)
clientName.connect("localhost",1883,60)
clientName.publish("TopicLevel1/test", "Your Message Here");
clientName.disconnect();

Most of the code is self-explaining. First, you create an instance of an MQTT client. Then you connect with the broker running on Localhost. Then the client publishes its message on “TopicLevel1/test” topic. After that, it disconnects from the broker.

Subscribing to a topic

You know that MQTT is not a one to one messaging protocol as it connects many devices. The trick here is that message from any device is assigned to a topic. Any devices that are subscribed to that topic will receive the message. Similarly, you can publish messages to Topics.

You can subscribe to a topic with subscribe() method in Client class. Subscribing to a topic has the same steps as to publishing messages. I am not going to repeat it as you can easily identify these steps from the code.

import paho.mqtt.client as mqtt

def on_connect(subscriber, userdata, flags, rc):
  subscriber.subscribe("topic/test")

def on_message(client, userdata, msg):
  if msg.payload.decode() == "Disconnect!":
    subscriber.disconnect()
    
subscriber = mqtt.Client("subscribeeId")
subscriber.connect("localhost",1883,60)

subscriber.on_connect = on_connect
subscriber.on_message = on_message

subscriber.loop_forever()

In this application, the client works as a subscriber. It subscribes to the topic to the broker which in this case, runs on localhost. Whenever it receives a message, it calls for the on_message() method. If the received message is disconnected, it immediately disconnects from the broker. This is a very simple use of subscriber method. You can write more complicated logic using the same callback functions. 

So in this article, you get a concise yet comprehensive idea about MQTT. Its’ time to move on to the conclusion to recall yourself as to what is the gist of the article.

Conclusion

MQTT is a lightweight, flexible and a simple but very efficient protocol that has a definite advantage over others when it comes to IoT and M2M solutions; considering its low bandwidth and low power consumption, response time and multiple usages. In conclusion, it could be said that MQTT is the best protocol so far when it comes to IOT development.

If you want to know more about MQTT, you can check the links below or have any questions, please reach out to me: bjorn.nostdahl@gunnebo.com

MQTT and ActiveMQ on RPI

MQTT for PIC Microcontrollers