-
Notifications
You must be signed in to change notification settings - Fork 31
Add new IP-based time endpoint #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I did not see any example for this so I tried:
but it failed on a PyPortal:
What did I miss? |
bf2e0bd
to
88cb011
Compare
@jerryneedell I rebased the pull request onto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested on pyportal with
import board
import busio
from digitalio import DigitalInOut
# ESP32 SPI
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
# Import NeoPixel Library
import neopixel
# Import Adafruit IO REST Client
from adafruit_io.adafruit_io import RESTClient
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# PyPortal ESP32 Setup
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
ADAFRUIT_IO_USER = secrets['adafruit_io_user']
ADAFRUIT_IO_KEY = secrets['adafruit_io_key']
# Create an instance of the Adafruit IO REST client
io = RESTClient(ADAFRUIT_IO_USER, ADAFRUIT_IO_KEY, wifi)
print('Getting time from IO...')
time = io.receive_time()
print(time)
responded ok:
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.3-15-gcfb54f026 on 2019-03-12; Adafruit PyPortal with samd51j20
>>> import io_time
Getting time from IO...
Failed to connect, retrying
('No such ssid', b'Needell Airport')
struct_time(tm_year=2019, tm_mon=3, tm_mday=12, tm_hour=21, tm_min=19, tm_sec=46, tm_wday=2, tm_yday=71, tm_isdst=1)
looks good.
after rebase, both examples (time and weather) ran as expected. |
This PR modifies the
receive_time
method to support the new time endpoint on Adafruit IO:/integrations/time/struct.json
. This endpoint will return a time based on the IP Address.The new
receive_time
returns the time as astruct_time
(https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.struct_time)The previous /time endpoint returned a plaintext response, instead of json. Since the new endpoint returns a JSON response, this PR will remove the
return_text
kwarg from the HTTP_get
method