Skip to content
Drasko DRASKOVIC edited this page Mar 22, 2015 · 5 revisions

MQTT Support in WeIO

MQTT Client - Paho

Paho is an Eclipse project that implements MQTT client with various language bindings

Support for Paho in WeIO can be added via paho-mqtt Python package (https://pypi.python.org/pypi/paho-mqtt).

  • Install paho-mqtt
root@WEIO:~# pip install paho-mqtt
Downloading/unpacking paho-mqtt
  Downloading paho-mqtt-1.1.tar.gz (41kB): 41kB downloaded
  Running setup.py egg_info for package paho-mqtt
    
Installing collected packages: paho-mqtt
  Running setup.py install for paho-mqtt
    
Successfully installed paho-mqtt
Cleaning up...
root@WEIO:~# 
  • Use following program in WeIO IDE to test:
from weioLib.weio import *

import paho.mqtt.client as mqtt

def setup():
    attach.process(myProcess)
    
def myProcess():
    # The callback for when the client receives a CONNACK response from the server.
    def on_connect(client, userdata, flags, rc):
        print("Connected with result code "+str(rc))

        # Subscribing in on_connect() means that if we lose the connection and
        # reconnect then subscriptions will be renewed.
        client.subscribe("$SYS/#")

    # The callback for when a PUBLISH message is received from the server.
    def on_message(client, userdata, msg):
        print(msg.topic+" "+str(msg.payload))

    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message

    client.connect("iot.eclipse.org", 1883, 60)

    # Blocking call that processes network traffic, dispatches callbacks and
    # handles reconnecting.
    # Other loop*() functions are available that give a threaded interface and a
    # manual interface.
    client.loop_forever()

MQTT Broker - Mosquitto

  • Install mosquitto in OpenWrt:
root@WEIO:~# opkg install mosquitto mosquitto-client
Installing mosquitto (1.3.4-1) to root...
Downloading http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/packages/mosquitto_1.3.4-1_ar71xx.ipk.
Installing mosquitto-client (1.3.4-1) to root...
Downloading http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/packages/mosquitto-client_1.3.4-1_ar71xx.ipk.
Installing libcares (1.10.0-1) to root...
Downloading http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/packages/libcares_1.10.0-1_ar71xx.ipk.
Installing libmosquitto (1.3.4-1) to root...
Downloading http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/packages/libmosquitto_1.3.4-1_ar71xx.ipk.
Configuring libcares.
Configuring libmosquitto.
Configuring mosquitto-client.
Configuring mosquitto.
root@WEIO:~#