Publishing data by MQTT

After installing Mosquitto on Omega2+ in the blog post Using MQTT on Onion Omega2+ the subscription of messages was shown. Here I will send data to the MQTT broker to subscribe and access them from anywhere in the world.

For data generation I use the script wunderweather.phy again. The script mqtt.sh reads the requested data (temperature & humidity) and publishes these to my MQTT broker. Look for the files at Github.

mqtt.sh:

#!/bin/sh

#MQTT
BROKER="m20.cloudmqtt.com"
BRUSER="rawyjpid"
BRPASSW="ah52k3gjd8JS"
BRPORT=12394
TEMPTOP="OMEGA2/WU/temperature"
HUMITOP="OMEGA2/WU/humidity"

echo "Send data to MQTT Broker"

DATE="$(date +"%d-%m-%Y")"
read TEMP < /home/TEMP 
echo "Temperature = $TEMP *C"
read HUMI < /home/HUMI 
echo "Rel. Humidity = $HUMI %"

mosquitto_pub -h $BROKER -u $BRUSER -P $BRPASSW -p $BRPORT -t $TEMPTOP -m $TEMP
mosquitto_pub -h $BROKER -u $BRUSER -P $BRPASSW -p $BRPORT -t $HUMITOP -m $HUMI

The screenshot of my MQTT client MyMQTT shows messages from two publishers. WU labels the data received from Weather Underground requestet here and ASH2200 is a sensor placed outside of my house. The difference between the measured values is due to different measuring locations.

screenshot_20170202-103009

Advertisements
Publishing data by MQTT

Using MQTT on Onion Omega2+

MQTT is an important protocol for data exchange in IoT networks.The communication between the producer of data (publisher) and the consumer of that data (subscriber) goes over an MQTT Broker always.

publish_subscribe

There are some free MQTT Broker around. I use CloudMQTT  of the Swedish company 84codes AB for my applications. CloudMQTT are Mosquitto server in the cloud.

Whats’s to do on Onion Omega2+ side after creating an MQTT account?

We have to install Mosquitto.

opkg update 
opkg install mosquitto mosquitto-client libmosquitto

I have here several temperature sensors in a controller network that send temperature and humidity data to the CloudMQTT broker.

To subscribe these data the follwoing subscribe command is needed on Onion Omega2+:

mosquitto_sub -h m20.cloudmqtt.com -u "ra.....id" -P "ah.....8JS" -p 12394 -t "DHT11/+/#" -v

You must change the user (-u), password (-P), and port (-p) to the login data of your broker account.

As you can see from the following screenshot it’s winter in Switzerland with around 2°C and 80 % rel. Humidity.

subscription

Using MQTT on Onion Omega2+