How to subscribe to a MQTT topic? ESP sends messages, but does not accept. code: var server = "m14.cloudmqtt.com"; var options = {
client_id : "random", keep_alive: 60, clean_session: true, port: 15577, username: "ciugiy**", password: "eYV1ivUWk***", protocol_name: "MQTT", protocol_level: 4,
};
var mqtt = require("MQTT").create(server, options); var wifi = require("Wifi");
function onInit() { wifi.stopAP();
wifi.connect("INGRI", {password: "3hotswf3"}, function(err) { // 192.168.83.196// //wifi.connect("AndroidAP", {password: "tssu7350"}, function(err) { // 192.168.83.196// if(err)console.log(err);else console.log("connected!"); console.log(wifi.getIP().ip); wifi.getStatus(function(ap) { if(ap.station === 'connected'){ mqtt.on('connected', function() { print("connect!!!"); var topic = "test/espruino"; var message = "hello, world"; mqtt.publish(topic, message); }); mqtt.on('publish', function (pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); }); mqtt.on('disconnected', function() { console.log("MQTT disconnected... reconnecting."); setTimeout(function() { mqtt.connect(); print("mqtt connect"); }, 2000); }); mqtt.connect(); } }); });
}
wifi.save(); save();
@Alexander started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
How to subscribe to a MQTT topic?
ESP sends messages, but does not accept.
code:
var server = "m14.cloudmqtt.com";
var options = {
};
var mqtt = require("MQTT").create(server, options);
var wifi = require("Wifi");
function onInit() {
wifi.stopAP();
}
wifi.save();
save();