Hello guys, with your help
The mosquito broker is setup on YUN.
I can now send and receive data from mosquito with python.
Why i can't connect to this broker with paho javascript example below?
http://www.eclipse.org/paho/clients/js/utility/index.html
Sketch:
#include <Process.h>
void setup() {
// Initialize Bridge
Bridge.begin();
// Initialize Serial
Serial.begin(9600);
// Wait until a Serial Monitor is connected.
while (!Serial);
}
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(String(temperature)); // pass parameter
p.run(); // Run the process and wait for its termination
delay(1000);
}
Pub python:
#!/usr/bin/python
import paho.mqtt.client as mqtt
import sys
mqttc = mqtt.Client("python_pub")
mqttc.connect("192.168.2.100", 1883, 60)
mqttc.publish("/hello/temp", sys.argv[1] )
Sub python:
#!/usr/bin/python
import paho.mqtt.client as mqtt
# 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("/hello/temp")
# 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("175.180.71.93", 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()