Matrix Portal M4, unable to send data to Adafruit.io

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

Hey all, I've been trying to do as much reading as possible before asking y'all - I'm absolutely stumped in how to send data to https://io.adafruit.com/ using a Matrix Portal M4.

I've tried the following:

Code: Select all

import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
io = IO_HTTP(secrets['adafruit_io_username'], secrets['adafruit_io_key'], requests)

try:
    indoor_temp_feed = io.get_feed("indoor-temp-sensor")
except AdafruitIO_RequestError:
    indoor_temp_feed = io.create_new_feed("indoor-temp-sensor")
and I get the following back:

Code: Select all

 
Traceback (most recent call last):
  File "code.py", line 33, in <module>
  File "code.py", line 31, in <module>
  File "adafruit_io/adafruit_io.py", line 670, in get_feed
  File "adafruit_io/adafruit_io.py", line 529, in _get
  File "adafruit_requests.py", line 684, in get
AttributeError: 'NoneType' object has no attribute 'request'
I've made sure that the libs/ contains the most up to date, correct libraries for the version of circuitpython I'm using (Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit Matrix Portal M4 with samd51j19). I've read a few documents where I'd have to do:

Code: Select all

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
 
requests.set_socket(socket, esp)
but that leads to other errors where I get an error of the ESP being busy.

Any direction would be greatly appreciated Sorry for the giant wall of text as well, but I wanted to be as explicit as possible.

User avatar
tenexxxxxxxxxx
 
Posts: 9
Joined: Tue May 18, 2021 1:31 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by tenexxxxxxxxxx »

Have you tried the example code at https://github.com/adafruit/Adafruit_Ci ... o_feeds.py ?

It looks you need to follow a setup process, shown in the example to get it working.

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

Hey!

I tried to follow that example actually and this is as far as I got:

Code: Select all

# Adafruit.io
from digitalio import DigitalInOut
import busio
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
and then I'd get the following error back:

Code: Select all

raceback (most recent call last):
  File "code.py", line 46, in <module>
  File "adafruit_matrixportal/matrixportal.py", line 98, in __init__
  File "adafruit_matrixportal/network.py", line 60, in __init__
  File "adafruit_matrixportal/wifi.py", line 69, in __init__
ValueError: ESP_BUSY in use
I've also tried the commented out options in that example you linked:

Code: Select all

esp32_cs = DigitalInOut(board.D9)
esp32_ready = DigitalInOut(board.D10)
esp32_reset = DigitalInOut(board.D5)
and that resulted in:

Code: Select all

Traceback (most recent call last):
  File "code.py", line 31, in <module>
AttributeError: 'module' object has no attribute 'D9'
It'll probably help to see what I'm trying to do in it's entirety, so this is my source code:

Code: Select all

#!/usr/bin/env python3

import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# Adafruit.io
import busio
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP

from busio import I2C
import adafruit_bme680

try:
    from secrets import secrets
    LATITUDE = secrets['latitude']
    LONGITUDE = secrets['longitude']
    OPENWEATHER_TOKEN = secrets['openweather_token']
    OPENWEATHER_UNITS = secrets['openweather_units']
    IO_USERNAME = secrets['aio_username']
    IO_KEY = secrets['aio_key']
except ImportError:
    print("WiFi secrets, Openweather API Tokens, and Latitude/Longitude values are kept in secrets.py, please add them!")
    raise

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# io = adafruit_io.Client(IO_USERNAME, IO_KEY)
# Get Feeds for adafruit.io
# indoor_temp_feed = io.get_feed("indoor-temp-sensor")

# try:
#     outdoor_feed = io.get_feed("outdoor-temp")
# except AdafruitIO_RequestError:
#     outdoor_feed = io.create_new_feed("outdoor-temp")

# --- Display setup ---
matrixportal = MatrixPortal(
    status_neopixel=board.NEOPIXEL
)

NEXT_SYNC = 0

# Create a static label
# "IN"
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(2, 4),
    text_scale=1
)

# "OUT"
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(35, 4),
    text_scale=1
)

# "F" for degrees for INDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(26, 16),
    text_scale=1
)

# "F" for degrees for OUTDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(59, 16),
    text_scale=1
)

# Dynamic labels
# Temperature INDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(2, 18),
    text_scale=2
)

# Temperature OUTDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(35, 18),
    text_scale=2
)

i2c = I2C(board.SCL, board.SDA)

bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)

def sensor_data_stringified(bme680):
    temperature = "%0.0f" % ((bme680.temperature * 1.8) + 32)
    # pressure = "%0.1fhPa" % bme680.pressure
    # gas = "{}%".format(bme680.gas)

    return "{}".format(temperature)

def callWeatherAPI(token, lat, lng):
    DATA_SOURCE = 'https://api.openweathermap.org/data/2.5/onecall?units={}&lat={}&lon={}&appid={}&exclude=minutely,hourly'.format(
        OPENWEATHER_UNITS,
        LATITUDE,
        LONGITUDE,
        OPENWEATHER_TOKEN
    )

    print(DATA_SOURCE)
    value = matrixportal.network.fetch_data(DATA_SOURCE, json_path=['current', 'temp'])
    return value

def parseForTemperature(weatherData):
    return int(weatherData[0])


outdoor_temp = '??'
indoor_temp = '??'

while True:
    NOW = time.time() # Current epoch time in seconds

    matrixportal.set_text("IN", 0)
    matrixportal.set_text("OUT", 1)
    matrixportal.set_text("F", 2)
    matrixportal.set_text("F", 3)
    matrixportal.set_text(indoor_temp, 4)
    matrixportal.set_text(outdoor_temp, 5)

    if NOW > NEXT_SYNC:
        NEXT_SYNC = NOW + (60 * 60) # Network call every hour
        value = callWeatherAPI(OPENWEATHER_TOKEN, LATITUDE, LONGITUDE)
        outdoor_temp = parseForTemperature(value)

        # print("Sending to Adafruit IO...")
        # io.send_data(indoor_temp_feed['key'], int(indoor_temp))
        # io.send_data(outdoor_feed['key'], int(outdoor_temp))

    indoor_temp = sensor_data_stringified(bme680)

    time.sleep(10)

User avatar
tenexxxxxxxxxx
 
Posts: 9
Joined: Tue May 18, 2021 1:31 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by tenexxxxxxxxxx »

You do need to use ESP (ESP_CS, ESP_BUSY, etc) pins on the MatrixPortal, as it has an ESP co-processor that it talks to via SPI for WiFi access.

The ESP_BUSY in use message seems to be the real issue - what happens if you run just this code:

Code: Select all

import board
import digitalio

esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

That's a great idea, I can't believe that slipped my mind to try and take it a part piece by piece.

So this works:

Code: Select all

import time
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# Set-up for AdafruitIO
import board
import digitalio

esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)
and the moment I import the matrixportal library, that's when it stops working:

Code: Select all

import time
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# Set-up for AdafruitIO
import board
import digitalio

esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
esp32_reset = digitalio.DigitalInOut(board.ESP_RESET)

matrixportal = MatrixPortal(
    status_neopixel=board.NEOPIXEL
)
It's this second code example is where:

Code: Select all

Traceback (most recent call last):
  File "code.py", line 14, in <module>
  File "adafruit_matrixportal/matrixportal.py", line 98, in __init__
  File "adafruit_matrixportal/network.py", line 60, in __init__
  File "adafruit_matrixportal/wifi.py", line 69, in __init__
ValueError: ESP_BUSY in use
comes in. I'll see if there's any examples of how to by pass this.

User avatar
tenexxxxxxxxxx
 
Posts: 9
Joined: Tue May 18, 2021 1:31 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by tenexxxxxxxxxx »

Try this:

Code: Select all

import board
import busio
import digitalio
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_esp32spi import adafruit_esp32spi

esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
esp32_reset = DigitalInOut(board.ESP_RESET)
esp32_cs = DigitalInOut(board.ESP_CS)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(
    spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0
)

try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

matrixportal = MatrixPortal(
    status_neopixel=board.NEOPIXEL
    esp=esp
)
This passes esp (an ESP_SPIcontrol instance) to the MatrixPortal constructor, instead of letting MatrixPortal create it. You can also use esp with the IO_HTTP further down...

Code: Select all

import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP

socket.set_interface(esp)
requests.set_socket(socket, esp)

aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
io = IO_HTTP(aio_username, aio_key, requests)
Hopefully (I can't test this) MatrixPortal and IO_HTTP are now sharing esp!

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

I think we are definitely on the right track, a lot more of the Python code gets executed and it seems like all that set-up with passing the esp was the right move.

I'm sure because of these changes, it would affect how the matrixportal.network.fetch_data works a bit now since I'm getting a different error. Here's my source code now:

Code: Select all

import time
import board
import busio
import digitalio
from adafruit_matrixportal.matrixportal import MatrixPortal

from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket

# Set-up for AdafruitIO
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
esp32_cs = digitalio.DigitalInOut(board.ESP_CS)
esp32_gpio0 = digitalio.DigitalInOut(board.ESP_GPIO0)
esp32_ready = digitalio.DigitalInOut(board.ESP_BUSY)
esp32_reset = digitalio.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, esp32_gpio0
)

socket.set_interface(esp)
requests.set_socket(socket, esp)

try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

# Additional Adafruit IO setup
io = IO_HTTP(secrets["aio_username"], secrets["aio_key"], requests)
try:
    outdoor_temp_feed = io.get_feed("outdoor-temp")
except AdafruitIO_RequestError:
    outdoor_temp_feed = io.create_new_feed("outdoor-temp")

matrixportal = MatrixPortal(
    status_neopixel=board.NEOPIXEL,
    esp=esp,
    debug=True
)

def callWeatherAPI(token, lat, lng, units="imperial"):
    DATA_SOURCE = 'https://api.openweathermap.org/data/2.5/onecall?units={}&lat={}&lon={}&appid={}&exclude=minutely,hourly'.format(
        units,
        lat,
        lng,
        token
    )

    print("Calling: {}".format(DATA_SOURCE))

    value = matrixportal.network.fetch_data(DATA_SOURCE, json_path=['current', 'temp'])

    print("current temperature data: {}".format(value))
    return value

while True:
    weatherData = callWeatherAPI(secrets["openweather_token"], secrets["latitude"], secrets["longitude"])
    outdoor_temp_data = int(weatherData[0])

    print("Sending to Adafruit IO...")
    io.send_data(outdoor_temp_feed['key'], int(outdoor_temp_data))

    time.sleep(10)
and this is the console output:

Code: Select all

Calling: https://api.openweathermap.org/data/2.5/onecall?units=imperial&lat=***&lon=***&appid=***&exclude=minutely,hourly
Retrieving data...Traceback (most recent call last):
  File "code.py", line 70, in <module>
  File "code.py", line 64, in callWeatherAPI
  File "adafruit_portalbase/network.py", line 548, in fetch_data
  File "adafruit_portalbase/network.py", line 467, in fetch
  File "adafruit_requests.py", line 684, in get
  File "adafruit_requests.py", line 562, in request
  File "adafruit_requests.py", line 429, in _get_socket
RuntimeError: Sending request failed
(I on purpose removed the app_id, lat, lng, but those values are definitely in the HTTPS call.)

Thanks again for getting me at least this far, I'm learning quite a bit more because of all this troubleshooting. I really appreciate your help.

User avatar
tenexxxxxxxxxx
 
Posts: 9
Joined: Tue May 18, 2021 1:31 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by tenexxxxxxxxxx »

Hmmm, maybe test Adafruit_CircuitPython_Requests on its own using this first...

https://github.com/adafruit/Adafruit_Ci ... pletest.py

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

The script here: https://github.com/adafruit/Adafruit_Ci ... pletest.py

works 100% all the way through.

Code: Select all

Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
Text Response:  This is a test of Adafruit WiFi!
If you can read this, its working :)

----------------------------------------
Fetching JSON data from https://httpbin.org/get
----------------------------------------
JSON Response:  {'url': 'https://httpbin.org/get', 'headers': {'User-Agent': 'Adafruit CircuitPython', 'Host': 'httpbin.org', 'X-Amzn-Trace-Id': 'Root=1-60a596bc-310fb1892f0a34f441e8a206'}, 'args': {}, 'origin': '71.187.51.200'}
----------------------------------------
POSTing data to https://httpbin.org/post: 31F
----------------------------------------
Data received from server: 31F
----------------------------------------
POSTing data to https://httpbin.org/post: {'Date': 'July 25, 2019'}
----------------------------------------
JSON Data received from server: {'Date': 'July 25, 2019'}
----------------------------------------

Code done running.

User avatar
tenexxxxxxxxxx
 
Posts: 9
Joined: Tue May 18, 2021 1:31 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by tenexxxxxxxxxx »

Looking at https://github.com/adafruit/Adafruit_Ci ... ts.py#L429, it's failing to get a socket.

This might sound a bit advanced but here's what I would do:
- delete the "adafruit_requests.mpy" file from the "lib" folder of the "CIRCUITPY" drive
- download https://raw.githubusercontent.com/adafr ... equests.py and put it into the "lib" folder of the "CIRCUITPY" drive

You now have an editable version of adafruit_requests that runs just the same as the compiled version!

Get in there and print out variables, error messages etc close to the line causing the error. I would definitely change the section at https://github.com/adafruit/Adafruit_Ci ... ts.py#L436 from...

Code: Select all

            
except OSError:
    continue
except RuntimeError:
    continue
...to ...

Code: Select all

            
except OSError as e:
    print(e)
    continue
except RuntimeError as e:
    print(e)
    continue
... just to see if something in there could help me out.

Good luck!

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

Hey! Sorry for the delayed response!

I didn't realize that I could import the raw requests python code and paste it into the matrixportal as a library. This is really useful to know for the future!

I went ahead and added a lot of print statements to figure out where the issue is and I think that the issue is there are aren't any additional sockets available.

This is the connection being allocated first for the Adafruit_IO feed via io.get_feed("outdoor-temp")

Code: Select all

*** Get host by name
addr_info:  (2, 0, 0, '', (bytearray(b'46\xa3\xc3'), 443))
*** Get socket
Allocated socket #0
sock_1:  <socket object at 2000b230>
sock.connect:  io.adafruit.com 443
*** Socket connect mode 2
*** Open socket to io.adafruit.com 443 2
socket:  <_FakeSSLSocket object at 2000b240>
and here's the next section where there's an attempt at requesting data to OpenWeatherAPI

Code: Select all

*** Get host by name
addr_info:  (2, 0, 0, '', (bytearray(b'\xc0\xf1\xa7\x10'), 443))
*** Get socket
Allocated socket #1
sock_1:  <socket object at 20006670>
sock.connect:  api.openweathermap.org 443
*** Socket connect mode 2
*** Open socket to api.openweathermap.org 443 2
OSError:  23
*** Closing socket #1
I tracked down the introduction of the OSError: 23 seems to be located here: https://github.com/adafruit/Adafruit_Ci ... /tag/3.5.3

Right now I'm trying to figure out how:
a) Sockets are allocated and configured in general
b) Multiple requests instances with different sockets made available

I'll continue to dig around in the documentation etc, but this type of networking trouble shooting is a bit new to me.

Thanks for all your help so far!

User avatar
hexxorleiva
 
Posts: 7
Joined: Wed Sep 15, 2010 11:32 am

Re: Matrix Portal M4, unable to send data to Adafruit.io

Post by hexxorleiva »

I believe I was able to solve the answer to this issue by using the matrixportal class to make all the requests on my behalf.

I didn't realize that by CircuitPython v7.x, the matrixportal library included a matrixportal.push-to-io(FEED-NAME, VALUE) method that could be used to push the data AND using matrixportal.network.fetch_data(URL) could allow for fetching weather data as well.

I like this solution because it involved passing the esp class directly into the MatrixPortal class and since it is already the mediator between so much on the board - having it all in a super class like this works better than having to instantiate more requests classes.

Here's ultimately what I ended up with:

I think it's important to note that I didn't pass any of the credentials for the Adafruit IO to the matrixportal class whatsoever, but it is picking up the tokens necessary to post the data. I believe that somewhere it is picking this up internally by checking the secrets.py and looking for the specific keywords as defined here: https://learn.adafruit.com/electronic-h ... secrets-py

Code: Select all

#!/usr/bin/env python3
# Get temperature from sensor and temperate from OpenWeather and display it on the MatrixPortal

import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

from busio import I2C
import adafruit_bme680

try:
    from secrets import secrets
    LATITUDE = secrets['latitude']
    LONGITUDE = secrets['longitude']
    OPENWEATHER_TOKEN = secrets['openweather_token']
    OPENWEATHER_UNITS = secrets['openweather_units']
except ImportError:
    print("WiFi secrets, Openweather API Tokens, and Latitude/Longitude values are kept in secrets.py, please add them!")
    raise

# --- Display setup ---
matrixportal = MatrixPortal(
    status_neopixel=board.NEOPIXEL
)

NEXT_SYNC = 0

# Create a static label
# "IN"
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(2, 4),
    text_scale=1
)

# "OUT"
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(35, 4),
    text_scale=1
)

# "F" for degrees for INDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(26, 16),
    text_scale=1
)

# "F" for degrees for OUTDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(59, 16),
    text_scale=1
)

# Dynamic labels
# Temperature INDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(2, 18),
    text_scale=2
)

# Temperature OUTDOORS
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(35, 18),
    text_scale=2
)

i2c = I2C(board.SCL, board.SDA)

bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)

def sensor_data_stringified(bme680):
    temperature = "%0.0f" % ((bme680.temperature * 1.8) + 32)

    return "{}".format(temperature)

def callWeatherAPI(token, lat, lng, units):
    DATA_SOURCE = 'https://api.openweathermap.org/data/2.5/onecall?units={}&lat={}&lon={}&appid={}&exclude=minutely,hourly'.format(
        units,
        lat,
        lng,
        token
    )

    print(DATA_SOURCE)
    value = matrixportal.network.fetch_data(DATA_SOURCE, json_path=['current', 'temp'])
    return value

def parseForTemperature(weatherData):
    return int(weatherData[0])


outdoor_temp = '??'
indoor_temp = '??'

while True:
    NOW = time.time() # Current epoch time in seconds

    matrixportal.set_text("IN", 0)
    matrixportal.set_text("OUT", 1)
    matrixportal.set_text("F", 2)
    matrixportal.set_text("F", 3)
    matrixportal.set_text(indoor_temp, 4)
    matrixportal.set_text(outdoor_temp, 5)

    if NOW > NEXT_SYNC:
        NEXT_SYNC = NOW + (60 * 60) # Network call every hour
        value = callWeatherAPI(OPENWEATHER_TOKEN, LATITUDE, LONGITUDE, OPENWEATHER_UNITS)
        outdoor_temp = parseForTemperature(value)

    indoor_temp = sensor_data_stringified(bme680)

    matrixportal.push_to_io("outdoor-temp", outdoor_temp)
    matrixportal.push_to_io("indoor-temp-sensor", indoor_temp)

    time.sleep(60)

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”