Can't make the SNTP module work

Posted on
  • Hi.

    I'm making a watch so I needed an accurate time source. I've found the SNTP module which seems to do just that. However, it always times out and I'm not sure how to proceed to figure out why it doesn't work.

    The SNTP module is based on @hapi/sntp so I tried running that module on my laptop against the same NTP service and it works fine. Both the laptop and the MCU are on the same network.

    Any tips on how to proceed to debug this?

    TIA,

    Per.

  • Wed 2019.09.18

    While I'm not able to provide any direct help here @perbu posting your code might assist others.

    This article would be of benefit also:

    Writing an effective forum post

  • @Robin

    Thanks for the suggestion. So, for what it is worth, here are some more details about my setup:

    The code is pretty simple, it is the example from the module documentation:

    var wifi = require("Wifi");
    var Sntp = require('sntp');
    
    // All options are optional
    
    var options = {
      host: 'no.pool.ntp.org',
        port: 123,                      // Defaults to 123 (NTP)
        timeout: 3000                   // Defaults to zero (no timeout)
    };
    
    // Request server time
    
    Sntp.time(options, function (err, time) {
    
        if (err) {
            console.log('Failed: ' + err.message);
            return;
        }
    
        console.log('Local clock is off by: ' + time.t + ' milliseconds');
    });
    

    .env looks like this:

    
    ={
      VERSION: "2v04",
      GIT_COMMIT: "3956264e",
      BOARD: "ESP8266_4MB",
      FLASH: 0, RAM: 81920,
      SERIAL: "68c63a9f-c13f",
      CONSOLE: "Serial1",
      MODULES: "Flash,Storage,hea" ... "r,crypto,neopixel",
      EXPTR: 1073643636 }
    

    Ideally what I'd would like to have is some sort of debugger, but I've not seen those working on the esp8266 - but there might be a way to enable the debugger which I've yet to find. I'm currently considering importing the SNTP module into the IDE and printf-debug it. We'll see how that goes.

    Cheers,

    Per.

  • For fun I tried to push the code to an ESP32-WROVER-B-module I had lying around and it worked perfectly.

    I'll be happy to work some more on the issue if anyone can suggest a direction. But if nothing else, I've found out how I can get my clock project to the next phase. :-)

    Cheers,

    Per.

  • maybe you like to try this too setTime via webserver

  • That is a nice tip, @MaBe. Thanks!

  • and more more, as you are running on ESP8266

    http://www.espruino.com/Reference#l_Wifi­_setSNTP

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can't make the SNTP module work

Posted by Avatar for perbu @perbu

Actions