Install MQTT:

opkg update
opkg install mosquitto
opkg install mosquitto-client
/etc/init.d/mosquitto restart

Subscribing to a Topic:

mosquitto_sub -d -t hello/world
Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0

Publishing to a Topic, open second terminal windows:

mosquitto_pub -d -t hello/world -m "Hello World"
Received CONNACK
Sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (11 bytes))

at first windows you should see:

Received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (11 bytes))
Hello World

Python code:

opkg update
opkg install libmosquitto
opkg update
opkg install python-openssl #adds ssl support to python
opkg install distribute #it contains the easy_install command line tool (this can take some time)
easy_install pip #installs pip  (this can take some time)
pip install mosquitto
nano /mnt/sda1/
import mosquitto
import sys
mqttc = mosquitto.Mosquitto("python_pub")
mqttc.connect("", 1883, 60, True)
mqttc.publish("hello/temperature", sys.argv[1] )
chmod 755  /mnt/sda1/
/mnt/sda1/ 34

open second terminal windows:

mosquitto_sub -d -t hello/temperature

to confirm temperature sent.

ATmega32u4 code:

#include <Process.h>
void setup() {
  Bridge.begin();   // Initialize Bridge
void loop() {
  int temperature = random(0, 100);
  Process p;        // Create a process and call it "p"
  p.begin("/mnt/sda1/");   // Process that launch the  command
  p.addParameter(temperature); // pass  parameter;      // Run the process and wait for its termination



Comments powered by CComment