Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

OSError - Failed SSL handshake
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.
Please be positive and constructive with your questions and comments.

OSError - Failed SSL handshake

by basvdk on Tue May 25, 2021 7:54 am

I'm running a little script that will send temp/pressure/humidity from my Adafruit Funhouse to Adafruit IO.

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 | TOGGLE FULL SIZE
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

basvdk
 
Posts: 6
Joined: Sun May 23, 2021 7:33 pm

Re: OSError - Failed SSL handshake

by mikeysklar on Tue May 25, 2021 4:35 pm

How far is your Funhouse from the nearest WiFi device? Does it make a difference if you re-orient the Funhouse so the WiFi chip has line of site to the AP? Obviously a bit of overkill, but just trying to understand if this is a WiFi signal issue.

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: OSError - Failed SSL handshake

by basvdk on Tue May 25, 2021 5:49 pm

I tested it in several locations, one of which was directly besides the AP. These are Ubiquiti AP's and provice excellent coverage throughout the house.

basvdk
 
Posts: 6
Joined: Sun May 23, 2021 7:33 pm

Re: OSError - Failed SSL handshake

by mikeysklar on Wed May 26, 2021 9:39 am

@basvdk,

Thank you for confirming we are not losing WiFi signal.

There have been cases on this topic before that should be resolved with the current CircuitPython release.

https://github.com/adafruit/circuitpython/issues/3651

What are you currently running in terms of CircuitPython, bootloader and library bundle on the funhouse? It's quite new so I would be surprised if you are running something earlier than CircuitPython 6.2.0. There is a library bundle drop from 20210525 and a CircuitPython 6.3.0 release candidate you could try to see if it the issue resolves.

https://circuitpython.org/board/adafruit_funhouse/
https://circuitpython.org/libraries

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: OSError - Failed SSL handshake

by basvdk on Wed May 26, 2021 7:11 pm

I've updated to Circuit Python 6.3.0 RC0

Adafruit CircuitPython 6.3.0-rc.0 on 2021-05-25; Adafruit FunHouse with ESP32S2


Also updated the script to do a ping test if another OSError occurs.

Code: Select all | TOGGLE FULL SIZE
    # 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!")
        try:
            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))
        except OSError:
            print("Current IP address: %s" % str(wifi.radio.ipv4_address))
            ipv4 = ipaddress.ip_address("8.8.8.8")
            print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
        finally:
            funhouse.peripherals.led = False
            event_timestamp = time.monotonic()


Will keep you posted :-)

basvdk
 
Posts: 6
Joined: Sun May 23, 2021 7:33 pm

Re: OSError - Failed SSL handshake

by mikeysklar on Thu May 27, 2021 9:52 am

Thank you for trying the release candidated CP 6.3.0. Please confirm that you also updated the libraries to be current as well.

mikeysklar
 
Posts: 4576
Joined: Mon Aug 01, 2016 8:10 pm

Re: OSError - Failed SSL handshake

by basvdk on Fri May 28, 2021 5:00 am

After the update I had it running for 24 hours without loosing connection, so the connection seems more stable after the upgrade.

I then placed the funhouse further away from the AP. The latency for the connection is higher (as expected) but when the device has a bad connection when trying to send messages to IO the OSError returns. I used a simple ping monitor to see if the device was still connected and I can see it occasionally missing a single ping (time out).

It looks like the connection to IO isn't restored automatically after this, should I do a
Code: Select all | TOGGLE FULL SIZE
funhouse.network.mqtt_connect()
in the
Code: Select all | TOGGLE FULL SIZE
except:
block to restore the connection?

basvdk
 
Posts: 6
Joined: Sun May 23, 2021 7:33 pm

Re: OSError - Failed SSL handshake

by brubell on Fri May 28, 2021 9:28 am

Yep, within the except I'd also write some code to verify that the WiFi connection is still established prior to attempting a MQTT reconnection

brubell
 
Posts: 1381
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.