https://www.hackster.io/rayburne/nist-date-amp-time-with-esp8266-and-oled-display-e8b9a9
Ray
Projects: http://www.hackster.io/rayburne/
Explore... Chat... Share...
Moderator: igrr
GET HEAD / HTTP /1.1\r\nHost: time.is
GET / HTTP /1.1\r\nHost: time.is\r\nUser_Agent: MyESPClient\r\n\r\n
#!/usr/bin/python
import time
import serial
import binascii
port = serial.Serial('/dev/ttyUSB2', 115200, timeout=1)
def waitFor(str):
timeout = 0
serial_rxbuf = ""
while True:
while port.inWaiting() > 0:
c = port.read()
serial_rxbuf += c
if serial_rxbuf.endswith(str):
return True
time.sleep(0.01)
timeout += 1
if timeout > 100:
print "waitFor Timeout !"
return False
def getRxLine():
timeout = 0
serial_rxbuf = ""
while True:
while port.inWaiting() > 0:
c = port.read()
serial_rxbuf += c
if c == '\n':
return serial_rxbuf.strip()
time.sleep(0.01)
timeout += 1
if timeout > 100:
print "Timeout !"
return serial_rxbuf
port.write("AT+CIPSTART=\"TCP\",\"www.timeapi.org\",80\r\n")
waitFor("CONNECT")
waitFor("OK")
get_str = "GET /utc/now?format=%25a%20%25b%20%25d%20%25I:%25M:%25S%20%25Z%20%25Y HTTP/1.1\r\nHost: www.timeapi.org\r\nUser_Agent: MyESPClient\r\n\r\n"
print get_str
print "sending AT+CIPSEND=%d\r\n" % len(get_str)
port.write("AT+CIPSEND=%d\r\n" % len(get_str))
time.sleep(0.3)
waitFor(">")
port.write(get_str)
for i in range(0,20):
str = getRxLine()
print "Echo: %s" % str
GET /utc/now?format=%25a%20%25b%20%25d%20%25I:%25M:%25S%20%25Z%20%25Y HTTP/1.1
Host: www.timeapi.org
User_Agent: MyESPClient
sending AT+CIPSEND=130
User_Agent: MyESPClientat=%25a%20%25b%20%25d%20%25I:%25M:%25S%20%25Z%20%25Y HTTP/1.1
Echo: Recv 130 bytes
Echo:
Echo: SEND OK
Echo:
Echo: +IPD,283:HTTP/1.1 200 OK
Echo: Date: Tue, 20 Oct 2015 17:36:56 GMT
Echo: Connection: keep-alive
Echo: X-Frame-Options: sameorigin
Echo: X-Xss-Protection: 1; mode=block
Echo: Content-Type: text/html;charset=utf-8
Echo: Content-Length: 31
Echo: Server: thin 1.5.0 codename Knife
Echo: Via: 1.1 vegur
Echo:
Timeout !
Echo: Tue Oct 20 05:36:56 +00:00 2015
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]