After succesfully sending data from anywhere between 15 to 30 minutes the communication will fail with the mentioned error:
OSError: Failed SSL handshake
After rebooting the device communication will continue.
Below the script I'm running:
Code: Select all
import board
import time
import wifi
from adafruit_funhouse import FunHouse
import digitalio
#################### FUNCTIONS ####################
def reset_dotstar():
dots = funhouse.peripherals.dotstars
dots.brightness = 0.0
return dots
def connected(client):
print("Connected to Adafruit IO! Subscribing...")
#################### FUNCTIONS ####################
#################### VARIABLES ####################
RED = 0xFF0000 # (255,0,0)
YELLOW = 0xFFFF00 # (255,255,0)
GREEN = 0x00FF00 # (0,255,0)
#################### VARIABLES ####################
#################### Board initialization ####################
# Initialize Funhouse object
funhouse = FunHouse(default_bg=None)
# Create a dots object to config individual leds
dots = reset_dotstar()
# Initialize a new MQTT Client object
print("Setting up network and Adafruit IO connections")
funhouse.network.init_io_mqtt()
funhouse.network.on_mqtt_connect = connected
funhouse.network.mqtt_connect()
# Turn of screen
l = digitalio.DigitalInOut(board.TFT_BACKLIGHT)
l.direction = digitalio.Direction.OUTPUT
l.value = False # turns the display backlight off / True will enable the backlight
# startup timestamp
event_timestamp = time.monotonic()
#################### Board initialization ####################
#################### Running code ####################
while True:
# Process Adafruit IO messages
funhouse.network.mqtt_loop()
# Send sensor data to Adafruit IO every 10 seconds
if (time.monotonic() - event_timestamp) > 10:
funhouse.peripherals.led = True
print("Sending data to adafruit IO!")
funhouse.network.mqtt_publish("temperature", float(funhouse.peripherals.temperature))
funhouse.network.mqtt_publish("humidity", float(funhouse.peripherals.relative_humidity))
funhouse.network.mqtt_publish("pressure", float(funhouse.peripherals.pressure))
event_timestamp = time.monotonic()
funhouse.peripherals.led = False
# Use the UP button to turn on/ off the display backlight
if funhouse.peripherals.button_up:
if l.value:
l.value = False
else:
l.value = True
# Color the first dotstar red or green based onn wifi connection
if wifi.radio.ipv4_address:
dots[0] = GREEN
dots.brightness = 0.01
else:
print("No network connection!")
dots[0] = RED
dots.brightness = 0.01