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/temperature.py
#!/usr/bin/python import mosquitto import sys mqttc = mosquitto.Mosquitto("python_pub") mqttc.connect("127.0.0.1", 1883, 60, True) mqttc.publish("hello/temperature", sys.argv[1] )
chmod 755 /mnt/sda1/temperature.py
/mnt/sda1/temperature.py 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/temperature.py"); // Process that launch the command p.addParameter(temperature); // pass parameter p.run(); // Run the process and wait for its termination delay(5000); }
Comments powered by CComment