Avatar for d0773d

d0773d

Member since Feb 2014 • Last active Jul 2018
  • 67 conversations
  • 382 comments

Most recent activity

  • in Interfacing
    Avatar for d0773d

    I figured this out. setIP() returns true when it successfully finishes.

    Updated onInit code:

    function onInit() {
      console.log("Connecting to Ethernet");
    
      SPI2.setup({ mosi:B15, miso:B14, sck:B13 });
      eth = require("WIZnet").connect(SPI2, B10);
    
      console.log("Connect?: " + isConnected);
    
      isConnected = eth.setIP();
      console.log("Connect?: " + isConnected);
    
      if (isConnected == true) {
        mqttConnect();
      }
    
      //eth.getIP();
      eth.getIP(function(f,ip) {
        console.log("IP: ",ip);
        mqttConnect();
      });
    
    }
    
  • in Interfacing
    Avatar for d0773d

    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();
      });
    
    }
    
  • in JavaScript
    Avatar for d0773d

    @allObjects greetings, I sent you a pm..

    • 20 comments
    • 1,378 views
  • in JavaScript
    Avatar for d0773d

    @allObjects howdy. It has been awhile since I updated my status on this project/your code. Turns out, the PH sensor that I am using from atlas-scientific is a bit older and buggy which in turn doesn't give me proper readings so I resorted to checking my water ph using the old fashioned method i.e. using the General Hydroponics Test Kit solution. I guess doing things the "old fashioned" way gets the job done :-)

    Now, I'm looking for another project for the espruino.

  • in News
    Avatar for d0773d

    Very cool! Thank you for this :-)

    • 9 comments
    • 553 views
Actions