Hi, all is it possible to receive MQTT data with P5.js?
I found this code but it does not seem to connect with my broker.
var mqtt;
var reconnectTimeout = 2000;
var host = "127.0.0.1";
var port = 1883;
function setup()
{
MQTTconnect(); //connect to MQTT Server
createCanvas(100,100);
background(200,0,0);
}
function draw()
{
}
function onConnect()
{
//once a connection has been made make a subscription and send a message.
console.log("Connected");
//mqtt.subscribe("sensor1");
message = new Paho.MQTT.Message("Hello World"); //Message
message.destinationName = "sensor1"; //publish topic
mqtt.send(message); //publish Message
}
function MQTTconnect()
{
console.log("connecting to " + host + " " + port);
mqtt = new Paho.MQTT.Client(host,port,"ClientJs"); //create client object
//document.write("connecting to " + host);
var options = {
timeout: 3,
onSuccess: onConnect,
};
mqtt.connect(options); //connect
}