When running following script on an Adafruit HUZZAH32 with MicroPython v1.9.4-447-g86e0b2553 on 2018-08-13; ESP32 module with ESP32 I got an error :
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== from socket import AF_INET, SOCK_DGRAM
=== import sys
=== import socket
=== import struct, time
===
=== def getNTPTime(host = "pool.ntp.org"):
=== port = 123
=== buf = 1024
=== address = (host, port)
=== msg = '\x1b' + 47 * '\0'
=== msg = msg.encode('utf-8')
=== # reference time (in seconds since 1900-01-01 00:00:00)
=== TIME1970 = 2208988800 # 1970-01-01 00:00:00
===
=== # connect to server
=== client = socket.socket(AF_INET, SOCK_DGRAM)
=== client.sendto(msg, address)
=== msg, address = client.recvfrom(buf)
===
=== t = struct.unpack("!12I", msg)[10]
=== t -= TIME1970
=== return time.ctime(t).replace(" "," ")
===
=== if __name__ == "__main__":
=== print(getNTPTime())
===
===
Traceback (most recent call last):
File "<stdin>", line 25, in <module>
File "<stdin>", line 17, in getNTPTime
ValueError: invalid arguments
>>>
Script running on python2.7 and python3.5 but not on micropython
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Script running on python2.7 and python3.5 but not on micropython
I suggest you look at this solution.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Script running on python2.7 and python3.5 but not on micropython
Thank you very much. Works great!
Ingmar Hallberg
Ingmar Hallberg