Voici la question qui me guide dans mes recherches...

L’appât du gain manifesté par les entreprises supranationales et certains groupes oligarchiques, de même que le contrôle des ressources naturelles par ceux-ci, dirigent l’humanité vers un nouvel ordre mondial de type féodal, voir même sa perte. Confronté à cette situation, l’être humain est invité à refuser d’accepter d’emblée une pseudo-vérité véhiculée par des médias peut-être à la solde de ces entreprises et groupes. Au contraire, il est invité à s’engager dans un processus de discernement et conscientisation afin de créer sa propre vérité par la confrontation de sa réalité nécessairement subjective à des données objectives, telles que révélées par la science, par exemple.

The penalty that good men pay for not being interested in politics is to be governed by men worse than themselves. - Plato

mardi 23 février 2016

IoT: Installing a MQTT broker

Introduction to MQTT

For my IoT devices, I will be using MQTT to communicate sensor data to clients.

Here's a quick diagram showing how this works.

  • Publisher can be a xBee + temperature sensor, a nodeMCU + humidity sensor, sending topic and data.
  • The broker is the server part receiving the publication from the publishers (sensors) and serving the subscribers, reading the data.
  • Subscribers are the clients subscribing to the topics and getting the data for display, analysis etc.

Installing a broker

In this quick post, I am using the MQTT broker called mosquitto on fedora server 23 x64bit.  Here are the steps to install and test it.

Install
  • dnf install mosquitto.x86_64
Testing
  • ssh1: start mosquitto
    • mosquitto
      1456270790: mosquitto version 1.4.5 (build date 2015-11-27 15:20:56+0000) starting
      1456270790: Using default config.
      1456270790: Opening ipv4 listen socket on port 1883.
      1456270790: Opening ipv6 listen socket on port 1883.
      1456270827: New connection from ::1 on port 1883.
      1456270827: New client connected from ::1 as mosqsub/26144-localhost (c1, k60).
      1456270870: New connection from ::1 on port 1883.
      1456270870: New client connected from ::1 as mosqpub/26149-localhost (c1, k60).
      1456270870: Client mosqpub/26149-localhost disconnected.
  • ssh2: Starts a subscription to the topic "hello/world".
    • mosquitto_sub -d -t hello/world
      Client mosqsub/26499-localhost sending CONNECT
      Client mosqsub/26499-localhost received CONNACK
      Client mosqsub/26499-localhost sending SUBSCRIBE (Mid: 1, Topic: hello/world, QoS: 0)
      Client mosqsub/26499-localhost received SUBACK
      Subscribed (mid: 1): 0
  • ssh3: Publish a first message on the topic "hello/world"
    • mosquitto_pub -d -t hello/world -m "This is my first message"
      Client mosqpub/26511-localhost sending CONNECT
      Client mosqpub/26511-localhost received CONNACK
      Client mosqpub/26511-localhost sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (24 bytes))
      Client mosqpub/26511-localhost sending DISCONNECT
In the window that started the broker (mosquitto), (ssh1),  you should see:
1456274285: New connection from ::1 on port 1883.
1456274285: New client connected from ::1 as mosqpub/26549-localhost (c1, k60).
1456274285: Client mosqpub/26549-localhost disconnected.

In the window that started the subscription (ssh2), you should see this:
Client mosqsub/26499-localhost received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (24 bytes))
This is my first message
 and from time to time those ping request:
Client mosqsub/26499-localhost sending PINGREQ
Client mosqsub/26499-localhost received PINGRESP
For the above, I used this video for reference.

Windows MQTT client:


Now let's try a MQTT client on Windows.  I found this Chrome extension:
You may need to open the firewall on the server side to open port 1883:
firewall-cmd --add-port=1883/tcp
Then from the MQTTlens, you can now create a new connection like this:

After a save, you should get a connection.
Then you can try the subscribe and publish








We see here that the publish we pushed from the windows client, appeared in the subscription windows of the server. Then we sent from the server "this is my first message" and saw in the on both the server subscription and the client.

 Next step... getting my IoT device talking to the broker.  Hardware ordered!

Aucun commentaire: