Ok I go to this website: https://learn.adafruit.com/adafruit-mag ... -date-time
Then I go through the steps for setting up the date and time on Adafruit IO, and I get stuck on Step 4:
Step 4) Upload Test Python Code
This code is like the Internet Test code from before, but this time it will connect to adafruit.io and get the local time
I added the Python test code as code.py to my Metro M4 Airlift Lite board running CircuitPython.
I try running the code and immediately getting and error:
code.py output:
Traceback (most recent call last):
File "code.py", line 1, in <module>
ImportError: no module named 'ipaddress'
Code done running.
I even tried commenting out the first import ipaddress and then I get that same error for import ssl.
Can you help me fix this so I can make it work.
Thanks,
Tom Henry
Getting the Date and Time from Adafruit IO
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- Tom_Henry
- Posts: 350
- Joined: Wed Aug 26, 2020 8:19 pm
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Getting the Date and Time from Adafruit IO
That code was written for the MagTag which has a builtin ipaddress module.
The MetroM4 Express AirLift is a very different board. The Magtag is built around the ESP32-S2 while the Metro is a SAMD51 with an ESP32 wifi module (it's essentially a Metro M4 Express with a builtin AirLift breakout). Thus, the wifi code is a little different. Have a look through the Metro AirLift guide: https://learn.adafruit.com/adafruit-met ... rlift-wifi, https://learn.adafruit.com/adafruit-io-basics-airlift, and https://learn.adafruit.com/adafruit-airlift-breakout.
Dave
The MetroM4 Express AirLift is a very different board. The Magtag is built around the ESP32-S2 while the Metro is a SAMD51 with an ESP32 wifi module (it's essentially a Metro M4 Express with a builtin AirLift breakout). Thus, the wifi code is a little different. Have a look through the Metro AirLift guide: https://learn.adafruit.com/adafruit-met ... rlift-wifi, https://learn.adafruit.com/adafruit-io-basics-airlift, and https://learn.adafruit.com/adafruit-airlift-breakout.
Dave
- Tom_Henry
- Posts: 350
- Joined: Wed Aug 26, 2020 8:19 pm
Re: Getting the Date and Time from Adafruit IO
Dave,
Thanks for your reply.
Is there a CircuitPython example somewhere that shows me how to add date and time via Adafruit io to my sensor outputs like temperature?
Tom Henry
Thanks for your reply.
Is there a CircuitPython example somewhere that shows me how to add date and time via Adafruit io to my sensor outputs like temperature?
Tom Henry
- jwcooper
- Posts: 1004
- Joined: Tue May 01, 2012 9:08 pm
Re: Getting the Date and Time from Adafruit IO
Here is an example using MQTT. I think this should work with your Metro Airlift:
https://github.com/adafruit/Adafruit_Ci ... io_time.py
There are quite a few useful examples in that repository as well, including using the http api, such as this weather integration:
https://github.com/adafruit/Adafruit_Ci ... weather.py
You could modify that to 'receive_time' instead of weather:
https://github.com/adafruit/Adafruit_Ci ... io.py#L712
Here is the specific page with an example for using your Metro Airlift to connect to the internet, might be useful to compare the MagTag example and port it to work with the Airlift:
https://learn.adafruit.com/adafruit-met ... -connect-2
https://github.com/adafruit/Adafruit_Ci ... io_time.py
There are quite a few useful examples in that repository as well, including using the http api, such as this weather integration:
https://github.com/adafruit/Adafruit_Ci ... weather.py
You could modify that to 'receive_time' instead of weather:
https://github.com/adafruit/Adafruit_Ci ... io.py#L712
Here is the specific page with an example for using your Metro Airlift to connect to the internet, might be useful to compare the MagTag example and port it to work with the Airlift:
https://learn.adafruit.com/adafruit-met ... -connect-2
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Getting the Date and Time from Adafruit IO
If you are running on a "portal" type device (PyPortal, Magtag, Pybadge, etc) it's deep int the support library. Since you're not, you can copy it out and add it to your code.
Have a look at the portalbase code in the bundle, specifically https://github.com/adafruit/Adafruit_Ci ... network.py. You want the get_local_time function and related bits and pieces: https://github.com/adafruit/Adafruit_Ci ... rk.py#L223.
Dave
Have a look at the portalbase code in the bundle, specifically https://github.com/adafruit/Adafruit_Ci ... network.py. You want the get_local_time function and related bits and pieces: https://github.com/adafruit/Adafruit_Ci ... rk.py#L223.
Dave
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.