ntptime.py howto change host

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
spaceagejohnny
Posts: 2
Joined: Mon Oct 08, 2018 12:39 pm

ntptime.py howto change host

Post by spaceagejohnny » Sun Jan 06, 2019 2:57 pm

is the line:
host = "pool.ntp.org"
in ntptime.py changeable?
I copied this from https://github.com/micropython/micropyt ... ntptime.py.
is this even the file used by 'import ntptime' ?
I would like to run several esp8266 boards on an internal net or sub net that is not connected to the internet. ntp server would be a raspberry pi (I have that serving other computers - works well).
how can I change the host, and where.
hope I don't have to go messing around with the esp8266.---.bin file as I'm not sure I would be capable of doing that.
Thanks,
John

tylersuard
Posts: 7
Joined: Mon Jan 21, 2019 4:09 pm

Re: ntptime.py howto change host

Post by tylersuard » Mon Jan 21, 2019 4:32 pm

Ok yes, you can change the host. In the code you mentioned, the url is just set to the variable name "host". So you can change that. Also, for the number next to it in socket.getaddrinfo(host, 123), the "123" is just a random number, using but the program will use that as the port number for connection. You can use whatever port you want for that. BUT, if you are using your own server to provide the time, you need to be sure that when you send information to that server using s.sendto(NTP_QUERY, addr), you will get back the time using s.recv(48).

* as a side note, if you know the IP address of your own server, you don't need to even use the url getaddrinfo thing. You can just do s.sendto(NTY_QUERY, 1.23.45.67.8 90) (where 1.23.45.67.8 is the IP address of your server, and 90 is the port to which you want to connect).

spaceagejohnny
Posts: 2
Joined: Mon Oct 08, 2018 12:39 pm

Re: ntptime.py howto change host

Post by spaceagejohnny » Mon Jan 28, 2019 6:03 pm

* as a side note, if you know the IP address of your own server, you don't need to even use the url getaddrinfo thing. You can just do s.sendto(NTY_QUERY, 1.23.45.67.8 90) (where 1.23.45.67.8 is the IP address of your server, and 90 is the port to which you want to connect).
[/quote]

I changed it .. works great
thanks
John

Post Reply