• I've been attempting to connect to mqtt using the WIZ550io instead of wifi without success. My goal is to use a pico + WIZ550io + mqtt to trigger relays. I doubled checked if my pico has an IP address by typing eth.getIP() into the IDE console and I get the following result:

    ={
      "ip": "192.168.0.21",
      "subnet": "255.255.255.0",
      "gateway": "192.168.0.1",
      "dns": "************",
      "mac": "00:08:dc:1e:b9:73"
     }
    

    I'm following this guide: http://www.espruino.com/Home+Automation

    I think my issue is with in my onInit function. I'm trying to call mqttConnect(); on a successful

    eth.getIP

    , but I don't think

    mqttConnect()

    is getting called:

    eth.getIP(function(f,ip) {
        console.log("IP: ",ip);
        mqttConnect();
      });
    

    code:

    var turnedOFF = 1;
    
    var MQTT_HOST = "192.168.0.22";
    var PATH = "/mydevice/";
    var mqtt;
    var eth;
    
    function mqttMessage(pub) {
      console.log(
         "MQTT=> ",pub.topic,pub.message);
      if (pub.topic==PATH+"onoff") {
        var v = pub.message!=0;
        digitalWrite(B3, !v);
        mqtt.publish(PATH+"1/status", v?1:0);
      }
    }
    
    function mqttConnect() {
      console.log("mqttConnect");
      mqtt = require("MQTT").connect({
        host: MQTT_HOST,
      });
      mqtt.on('connected', function() {
        console.log("MQTT connected");
        // subscribe to wildcard for our name
        mqtt.subscribe(PATH+"#");
      });
      mqtt.on('publish', mqttMessage);
      mqtt.on('disconnected', function() {
        console.log("MQTT disconnected... reconnecting.");
        setTimeout(function() {
          mqtt.connect();
        }, 1000);
      });
    }
    
    setInterval(function() {
      if (!mqtt) return;
      mqtt.publish(
        PATH+"cputemp",
        E.getTemperature());
    }, 2*60*1000);
    
    function trigger() {
      turnedOFF = 1;
      digitalPulse(B3,0,1000);
      digitalWrite(LED1, 0);
      console.log("digitalWrite");
    }
    
    setWatch(function(e) {
      digitalWrite(LED1, e.state);
      trigger();
    }, BTN, { repeat: true });
    
    function onInit() {
      console.log("Connecting to Ethernet");
    
      SPI2.setup({ mosi:B15, miso:B14, sck:B13 });
      eth = require("WIZnet").connect(SPI2, B10);
    
      eth.setIP();
    
      //eth.getIP();
      eth.getIP(function(f,ip) {
        console.log("IP: ",ip);
        mqttConnect();
      });
    
    }
    
About

Avatar for d0773d @d0773d started