Matrixportal M4 stop logging data after 30 min with Adafruit

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
richardorluk
 
Posts: 4
Joined: Thu Dec 02, 2021 8:44 am

Matrixportal M4 stop logging data after 30 min with Adafruit

Post by richardorluk »

Hello,
New to circuit python. I have a matrix portal m4 with display. Most of the time I'm actually running it without display and trying to view CO2 values through Adafruit IO. I can send values to Adafruit IO, but can not pull them to verify. This works for 30 min, then data stops showing up on Adafruit. When the screen is connected it will also stop logging about 50% of the time after 30 min. Even though the SCD30 sensor is still lighting up. Tried using a 3 amp power supply. If I delete the internet / adafruit IO code, then the matrix portal will work indefinitely.
There's also some neopixel code at the end, but I can't get it to do anything with the neopixel. (was trying to work on changing the neopixel color to correspond with CO2.) I'm using this in a medical office and want it to be subtle and mostly run without display.

Any help appreciated,

Code below:

Code: Select all

import time
import board
import displayio
import microcontroller
import adafruit_imageload
from adafruit_matrixportal.matrix import Matrix
from adafruit_matrixportal.network import Network
import adafruit_scd30
import neopixel
import digitalio
from random import randint
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError


pixel_pin = board.NEOPIXEL
num_pixels = 1

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False,
                           pixel_order=(1, 0, 2, 3))
# --| User Config |----
CO2_CUTOFFS = (1000, 2000, 5000)
UPDATE_RATE = 1
# ---------------------

# the sensor
scd30 = adafruit_scd30.SCD30(board.I2C())

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

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

RED = (255, 0, 0, 0)
YELLOW = (255, 150, 0, 0)
GREEN = (0, 255, 0, 0)
CYAN = (0, 255, 255, 0)
BLUE = (0, 0, 255, 0)
PURPLE = (180, 0, 255, 0)

# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

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)

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

# 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.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]

# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

try:
    # Get the 'temperature' feed from Adafruit IO
    co2_feed = io.get_feed("co2")
except AdafruitIO_RequestError:
    # If no 'temperature' feed exists, create one
    co2_feed = io.create_new_feed("co2")
try: 
    neo_feed = io.get_feed("neocolor")
except AdafruitIO_RequestError:
    neo_feed = io.create_new_feed("neocolor")
    
    
# optional if known (pick one)
# scd30.ambient_pressure = 1013.25
# scd30.altitude = 0

# the display
matrix = Matrix(width=64, height=32, bit_depth=6)
display = matrix.display
display.rotation = 270  # matrixportal up
# display.rotation = 270 # matrixportal down

# current condition smiley face
smileys_bmp, smileys_pal = adafruit_imageload.load("/bmps/smileys.bmp")
smiley = displayio.TileGrid(
    smileys_bmp,
    pixel_shader=smileys_pal,
    x=0,
    y=0,
    width=1,
    height=1,
    tile_width=32,
    tile_height=32,
)

# current condition label
tags_bmp, tags_pal = adafruit_imageload.load("/bmps/tags.bmp")
label = displayio.TileGrid(
    tags_bmp,
    pixel_shader=tags_pal,
    x=0,
    y=32,
    width=1,
    height=1,
    tile_width=32,
    tile_height=16,
)

# current CO2 value
digits_bmp, digits_pal = adafruit_imageload.load("/bmps/digits.bmp")
co2_value = displayio.TileGrid(
    digits_bmp,
    pixel_shader=digits_pal,
    x=0,
    y=51,
    width=4,
    height=1,
    tile_width=8,
    tile_height=10,
)

# put em all together
splash = displayio.Group()
splash.append(smiley)
splash.append(label)
splash.append(co2_value)

# and show em
display.show(splash)


def update_display(value):

    value = abs(round(value))

    # smiley and label
    if value < CO2_CUTOFFS[0]:
        smiley[0] = label[0] = 0
    elif value < CO2_CUTOFFS[1]:
        smiley[0] = label[0] = 1
    elif value < CO2_CUTOFFS[2]:
        smiley[0] = label[0] = 2
    else:
        smiley[0] = label[0] = 3

    # CO2 value
    # clear it
    for i in range(4):
        co2_value[i] = 10
    # update it
    i = 3
    while value:
        co2_value[i] = value % 10
        value = int(value / 10)
        i -= 1




while True:
    # protect against NaNs and Nones
    try:
        update_display(scd30.CO2)
        print("CO2:", scd30.CO2, "PPM")
        print("Temperature:", scd30.temperature, "degrees C")
        print("Humidity:", scd30.relative_humidity, "%%rH")
        io.send_data(co2_feed["key"], scd30.CO2)
        print("received: ", receive_data)
        pixels.fill(RED)
        pixels.show() 
        time.sleep(1)
    except:
        pass
    time.sleep(UPDATE_RATE)
Last edited by dastels on Thu Dec 02, 2021 10:33 am, edited 1 time in total.
Reason: Added code block

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: Matrixportal M4 stop logging data after 30 min with Adaf

Post by dastels »

I see from the code that you are sending data every second. That's (stating the obvious) 60 updates per minute so I assume you have a plus account. Even so that's pushing the limit. If there's some latency at some point you might end up with exceeding the 60 update/minute limit. Have you tried lengthening the time between updates?

Dave

User avatar
richardorluk
 
Posts: 4
Joined: Thu Dec 02, 2021 8:44 am

Re: Matrixportal M4 stop logging data after 30 min with Adaf

Post by richardorluk »

Hi thank you for replying. I have the free account. I can try to put a delay. I do not get any data back in the serial from the IO nor can I seem to get the neopixel to light. Would this cause it to stop reading from the sensor? As the display also freezes after 30 min. I’m brand new at this. Trying to read up as much as I can.

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: Matrixportal M4 stop logging data after 30 min with Adaf

Post by dastels »

I'm not sure of the effects of hitting the Adafruit IO posting limit, it would depend heavily on how the error is handled. For free accounts I believe the limit is 30 posts per minutes, so you would need to reduce your posting to under that so make your delay a bit more than 2 seconds and see how that changes things

Dave

User avatar
richardorluk
 
Posts: 4
Joined: Thu Dec 02, 2021 8:44 am

Re: Matrixportal M4 stop logging data after 30 min with Adaf

Post by richardorluk »

I added a sleep time of 5 seconds and it worked a good amount of the day. Until I touched it :)
Thank you

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

Return to “Wireless: WiFi and Bluetooth”