Code: Select all
"""
Send data to io.adadruit.com feeds
"""
def send_to_aio_feed():
TAG="send_to_aio_feed(): "
my_debug = my_dat.read(_debug)
aio_username = my_dat.read(_aio_username)
aio_key = my_dat.read(_aio_key)
aio_feed_name = "rtc-bi-sync-data"
resp_lst = my_dat.read(_resp_lst)
response = None
network = magtag.network
msg_sent = my_dat.read(_msg_sent)
dteData = resp_lst[0] # pr_dt(DATE_ONLY)
timData = resp_lst[1][:7] # pr_dt(TIME_ONLY)
rtcSyncedData = my_dat.read(_rtc_bi_synced)
msg = ""
msg_sent += 1 # increase the messages sent count
my_dat.write(_msg_sent, msg_sent)
if my_debug:
print(TAG+dteData)
print(". Sending Data message nr: ", end='')
print(msg_sent, end='')
print(" to Adafruit IO feed: {}".format(aio_feed_name, end='\n'))
msg = "https://io.adafruit.com/<aio_username>/feeds/rtc-bi-sync-data/"
msg += "&date=" + dteData
msg += "&time=" + timData
msg += "&rtcSynced=" + "1" if rtcSyncedData else "0"
print(TAG+"going to send to aio: \"{}\"".format(msg))
msg_nr = str(msg_sent)
response = network.fetch(msg) # Send the msg
if response is not None:
print()
if not my_debug:
print(TAG+"response.status_code=", response.status_code)
# print(TAG+"reponse.text=\"{}\"".format(response.text))
response.close()
The REPL output is:
Code: Select all
send_to_aio_feed(): going to send to aio: "https://io.adafruit.com/<aio_username>/feeds/rtc-bi-sync-data/&date=2022-08-04&time=17:01:1&rtcSynced=1"
Retrieving data...
send_to_aio_feed(): response.status_code= 200