• Here is the working code! Whom it is necessary.

     var server = "m14.cloudmqtt.com";
     var options = {
     keep_alive: 60,
      port: 15577,
    username: "ciug****",
    password: "eYV1ivU****",
    protocol_name: "MQTT",
    protocol_level: 4
    };
    var mqtt = require("MQTT").create(server, options);
    var wifi = require("Wifi");
    function onInit() {
     wifi.stopAP();  
          wifi.connect("AndroidAP", {password: "tssu7350"}, function(err) { 
            if(err)console.log(err);else console.log("connected!");
            console.log(wifi.getIP().ip);
          wifi.getStatus(function(ap) {
             if(ap.station === 'connected'){
        print("START...");
        mqtt.on('connected', function() {
         print("connect!!!");
        mqtt.subscribe("test");
        });
        mqtt.on('publish', function (pub) {
          console.log("topic: "+pub.topic);
          console.log("message: "+pub.message);
        });
        mqtt.on('disconnected', function() {
          print("disconnected!!!");
         console.log("MQTT disconnected... reconnecting.");
         setTimeout(function() {
          mqtt.connect();
          print("mqtt connect");
         }, 2000);
         });
    mqtt.connect();
          }
        });
      });
    }
    wifi.save();
    save();
    
About

Avatar for Alexander @Alexander started