Avatar for Svarog

Svarog

Member since Feb 2020 • Last active Apr 2021
  • 4 conversations
  • 13 comments

noob :)

Most recent activity

  • in ESP8266
    Avatar for Svarog

    Hi MaBe, thank you for your answer.
    That is the tricky part, if i use setSntp, I am getting error :

    Uncaught Error: Cannot read property 'connect' of undefined
    at line 57 col 5
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {

    Any idea why is this happening?

    Thanks 😊

  • in ESP8266
    Avatar for Svarog

    I am trying to sync my esp8266 with NTP server, but I am running into a two problems.

    The first one is that if I use setSNTP(sntpServer, timeOffset) method on require("Wifi")

    var wifi = require("Wifi").setSNTP('2.europe.pool.n­tp.org',1);
    

    I am getting error msg:

    Uncaught Error: Cannot read property 'connect' of undefined
     at line 57 col 5
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
    

    The second problem:
    If I ditch the idea of using SNTP and just use Date(), when esp is connected I print time and it sometimes shows my local time, and sometimes UTC time. But, if I press reset button on the board, it set time to 01.01.1970.

    What am I missing here?

    Here is my code:

        var  on = false;
        digitalWrite(D2,on)
    
        var WIFI_NAME = "name";
        var WIFI_OPTIONS = { password : "passwd" };
        var server = "192.168.1.24"; // the ip of your MQTT broker
        var wifi = require("Wifi").setSNTP('2.europe.pool.n­tp.org',1);
        var mqttOptions = { // ALL OPTIONAL - the defaults are below
            client_id : "random",   // the client ID sent to MQTT - it's a good idea to define your own static one   based on `getSerial()`
            keep_alive: 60,         // keep alive time in seconds
            port: 1883,             // port number
            clean_session: true,
            username: undefined,   // default is undefined
            password: undefined,   // default is undefined
            protocol_name: "MQTT",  // or MQIsdp, etc..
            protocol_level: 4,      // protocol level
        };
    
        var mqtt = require("MQTT").create(server, mqttOptions);
    
        //When Mqtt connection is enstablished subscribe on following topics
        mqtt.on('connected', function() {
            mqtt.subscribe("test");
            mqtt.subscribe("led");
            mqtt.subscribe("time");
        });
    
        mqtt.on('publish', function (pub) {
            console.log("topic: "+pub.topic);
            console.log("message: "+pub.message);
            if(pub.topic === "led"){
            console.log('Led msg');
            on = !on;
            digitalWrite(D2,on);
            mqtt.publish('ledStatus',on);
            } else if(pub.topic === 'time') {
            console.log(`I got time`);
            console.log(Date().toString());
            mqtt.publish('time', Date());
            }
        });
    
        wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) {
            console.log("Connection error: "+err);
            return;
        }
        wifi.save();
        console.log("Connected!");
        mqtt.connect();
        console.log(`Time : ${Date()}`);
        console.log(`Time Zone : ${Date().getTimezoneOffset()}`);
        });
    

    Thanks :)

  • in ESP8266
    Avatar for Svarog

    Thank you Robin.

  • in ESP8266
    Avatar for Svarog

    Thanks Robin, very friendly community :)

  • in ESP8266
    Avatar for Svarog

    Hi Robin,

    It's been a year and I didn't work on this and I completely forgot how I did it at the time. I wanted to refresh knowledge and got stuck with flashing and pushing the code. Sorry for the inconvenience.

    After a few hours of reading the documentation and examination I managed to make my esp8266 to connect to wifi and mqtt...

    I have a new questions since you answered my previous question.

    1. I do not understand the concept how espruino works. I am used to Arduino loop function and I can't get my head around how it works on espruino? How can I achieve the same behaviour in espruino?
    2. I guess that this code snippet listens for message 'connected' from mqtt broker and then executes the subscription to certain topics?

      mqtt.on('connected', function(pub) {//subscribe to topics});
      
    3. Can you please point me how to define pins for digital read and write? I am unable to find the documentation for that?

    Thanks :)

  • in ESP8266
    Avatar for Svarog

    Hello, I am new here and I am struggling to flash and use espruino with Esp boards.

    Can you please help me and post up to date tutorial so I can know how to push code to the board(permanently) and how to debug board?

    thanks :)

  • in ESP32
    Avatar for Svarog

    @Robin, thanks for response. My greenhouse is just near my hose, so I don't need LORA wan for communication. However, I will buy espruino board.

    @allObjects thanks for this elaboration, I will order a few boards and try to build the system.

    Thanks for your help guys :)

Actions