• Hi All, I've been using the MQTT module without any problems for at least a month. However, I started having problems yesterday, which I see was the day that a new MQTT module was posted on https://www.espruino.com/modules

    mqtt.connect() gives this immediate error:

    >mqtt.connect()
    =undefined
    Uncaught SyntaxError: Got ':' expected EOF
     at line 1 col 70
    ...;var f=c.charCodeAt(0)>>4;a:{var d=c.substr(1,5);var k=1,l=0...
    

    Code is running on
    ESP8266-12E flashed with espruino_1v95_esp8266_4mb_combined_4096.­bin ...

    Test program, which has worked without a problem is listed below.

    Is there an error in the MQTT module? Is there a change in using it?
    Also, a related question: is there a way to access a previous version of a module?

    Thanks,

    Dan

    Program:

    var wifi = require("Wifi");
    
      var server = 'm14.cloudmqtt.com';
      var options = {
              keep_alive: 60,
              port: xxxx,
              clean_session: true,
              client_id: "xxxx",
              username: "xxxx",
              password: "xxxx",
              protocol_name: "MQTT",
              protocol_level: 0 };
    
      var mqtt = require("MQTT").create(server, options); // changes here
        mqtt.on('connected', function() {
        mqtt.subscribe("red");
          mqtt.subscribe("blue");
        console.log("connected");
      });
    
    mqtt.on('disconnected', function() {
      console.log("MQTT disconnected... reconnecting.");
      setTimeout(function() {
        mqtt.connect();
      }, 1000);
    });
      
       mqtt.on('publish', function (pub) {  // this place throw error
        console.log("topic: "+pub.topic);
        console.log("message: "+pub.message);
        if (pub.topic == "red") {
         if (pub.message == "on") {digitalWrite(16,0);}
         if (pub.message == "off") {digitalWrite(16,1);}
        }
          if (pub.topic == "blue") {
         if (pub.message == "on") {digitalWrite(2,0);}
         if (pub.message == "off") {digitalWrite(2,1);}
        }   
      });
    
    function onInit() {
      console.log("In onInit");
      wifi.connect("xxxx", {password:"xxxx"}, function(err){
    console.log("connected? err=", err, "info=", wifi.getIP());
    });
    wifi.stopAP(); 
    mqtt.connect(); 
    }
    
About

Avatar for DanB @DanB started