Skip to content

Adafruit ESP32-S2 Feather hard crashes with wifi.radio.ping #5745

@BlueBackbite

Description

@BlueBackbite

CircuitPython version

Adafruit CircuitPython 7.1.0-beta.3 on 2021-12-13; Adafruit Feather ESP32S2 with ESP32S2
Board ID:adafruit_feather_esp32s2

Code/REPL

# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
# SPDX-FileContributor: Modified by Reppad
#
# SPDX-License-Identifier: MIT

import os
import board
import neopixel
import ipaddress
import wifi
import rtc
import time
import random
import socketpool

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

try:
    import json as json_module
except ImportError:
    import ujson as json_module


# Track time we've been unable to ping certain IPs
time_modem_ping = time.time()
# VERIFY this is the default modem management IP, it ussually is, and *ussually* responds to ping
modemIP = ipaddress.ip_address("192.168.100.1")

time_external_ping = time.time()
external_ips = [ipaddress.ip_address("1.1.1.1"),ipaddress.ip_address("8.8.8.8"),ipaddress.ip_address("8.8.4.4"),ipaddress.ip_address("1.0.0.1"),ipaddress.ip_address("208.67.222.222"),ipaddress.ip_address("208.67.220.220")]

# Delay the number of attempts we make, so we're not spamming ping all the time.
time_delay = time.time()

# Track when last power cycle happened.
time_reset = time.time()

#how often in seconds to check for connectivity (Will ping every x seconds) Don't flood the network with pings!
check_interval = 1

# count the number of pings
ping_counter = 0


#Set our hostname? (I think this works)
wifi.radio.hostname = "ModPowerMon"

print("Connect wifi")
wifi.radio.connect(secrets['ssid'],secrets['password'])
HOST = repr(wifi.radio.ipv4_address)
GATEWAY = repr(wifi.radio.ipv4_gateway)
DNS = repr(wifi.radio.ipv4_dns)
MYNAME = repr(wifi.radio.hostname)
PORT = 80        # Port to listen on
print(HOST,PORT)

# Use below for Most Boards
status_light = neopixel.NeoPixel(
    board.NEOPIXEL, 1, brightness=0.2
) 

# Run checks to see if we can reach outside the network...
def check_connectivity():
    global time_reset, time_modem_ping, time_external_ping, ping_counter
    sing_ip = random.choice(external_ips)
    print("pinging ",sing_ip)
    ping_result = wifi.radio.ping(sing_ip)
    if ping_result is None:
        #unable to ping site, try modem
        ping_modem_result = wifi.radio.ping(modemIP)
        if ping_modem_result is None and time.time() - time_modem_ping > 3600:
            # Toggle our latching relay to cut power to the modem for 2 minutes
            print("Haven't been able to reach any outside networks, for more than an hour")
            time_reset = time.time()
            time_external_ping = time.time()
            time_modem_ping = time.time()
        else:
            time_modem_ping = time.time()
    else:
        ping_counter += 1
        time_external_ping = time.time()
        ping_modem_result = wifi.radio.ping(modemIP)
        if ping_modem_result is None:
            print("Was able to ping external IP but not modem, that's weird.")
        else:
            ping_counter += 1
            time_modem_ping = time.time()
            print("Was able to ping external IP and modem, should be good to go!",ping_counter)

print(f"hostname: {MYNAME} gateway IP: {GATEWAY} DNS: {DNS}")


while True:
    # Our main loop where we have the server poll for incoming requests
    # Could do any other background tasks here, like reading sensors
    if time.time() > time_external_ping + check_interval and time.time() > time_delay + check_interval:
        time_delay = time.time()
        check_connectivity()

Behavior

After 30 pings, the board hard faults into safe mode.
The same behavior happens when using larger time intervals between pings.

Description

No response

Additional information

Nothing else is attached to the board.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashespressifapplies to multiple Espressif chips

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions