Skip to content

BUG: NetworkEvents::removeEvent crashes #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// bug-NetworkEvents-removeEvent.ino

#define wifiSSID "Your_WiFi_SSID"
#define wifiPassword "Your_WiFi_Password"

#include <WiFi.h>

bool RTK_CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC = false;

//----------------------------------------
// System initialization
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("bug-NetworkEvents-removeEvent.ino");

// Listen for wifi events
Serial.printf("Registering callback handler: %p\r\n", (void *)wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);
Network.onEvent(wifiEvent);

// Start displaying the events
Serial.println("==================== Receiving 4 events / actual event ====================");

// Start WiFi
WiFi.begin(wifiSSID, wifiPassword);
}

//----------------------------------------
// Main loop
void loop()
{
static bool eventRemoved;
static uint32_t lastTimeMillis;
static bool wifiState;

uint32_t currentMillis = millis();
if ((currentMillis - lastTimeMillis) >= (10 * 1000))
{
lastTimeMillis = currentMillis;

// Toggle the Wifi state
wifiState ^= 1;
if (wifiState)
{
Serial.println("---------- WiFi.disconnect ----------");
WiFi.disconnect(true);
}
else
{
Serial.println("---------- WiFi.begin ----------");
WiFi.begin(wifiSSID, wifiPassword);
}
}
if ((!eventRemoved) && (currentMillis >= (60 * 1000)))
{
// Removing the WiFi event handler
// This should remove them all!!!!!!
Network.removeEvent(wifiEvent);
eventRemoved = true;
Serial.println("==================== Removed all the WiFi Event Handlers ====================");
Serial.println("==================== No Event Output Should Be Displayed ====================");
}
}

//----------------------------------------
void wifiEvent(arduino_event_id_t event, arduino_event_info_t info)
{
char ssid[sizeof(info.wifi_sta_connected.ssid) + 1];
IPAddress ipAddress;

// Handle the event
switch (event)
{
default:
Serial.printf("ERROR: Unknown WiFi event: %d\r\n", event);
break;

case ARDUINO_EVENT_WIFI_OFF:
Serial.println("WiFi Off");
break;

case ARDUINO_EVENT_WIFI_READY:
Serial.println("WiFi Ready");
break;

case ARDUINO_EVENT_WIFI_SCAN_DONE:
Serial.println("WiFi Scan Done");
// wifi_event_sta_scan_done_t info.wifi_scan_done;
break;

case ARDUINO_EVENT_WIFI_STA_START:
Serial.println("WiFi STA Started");
break;

case ARDUINO_EVENT_WIFI_STA_STOP:
Serial.println("WiFi STA Stopped");
break;

case ARDUINO_EVENT_WIFI_STA_CONNECTED:
memcpy(ssid, info.wifi_sta_connected.ssid, info.wifi_sta_connected.ssid_len);
ssid[info.wifi_sta_connected.ssid_len] = 0;
Serial.printf("WiFi STA connected to %s\r\n", ssid);
break;

case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
memcpy(ssid, info.wifi_sta_disconnected.ssid, info.wifi_sta_disconnected.ssid_len);
ssid[info.wifi_sta_disconnected.ssid_len] = 0;
Serial.printf("WiFi STA disconnected from %s\r\n", ssid);
// wifi_event_sta_disconnected_t info.wifi_sta_disconnected;
break;

case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
Serial.println("WiFi STA Auth Mode Changed");
// wifi_event_sta_authmode_change_t info.wifi_sta_authmode_change;
break;

case ARDUINO_EVENT_WIFI_STA_GOT_IP:
ipAddress = WiFi.localIP();
Serial.print("WiFi STA Got IPv4: ");
Serial.println(ipAddress);
break;

case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
Serial.print("WiFi STA Got IPv6: ");
Serial.println(ipAddress);
break;

case ARDUINO_EVENT_WIFI_STA_LOST_IP:
Serial.println("WiFi STA Lost IP");
break;
}
}
147 changes: 147 additions & 0 deletions Example_Sketches/bug-NetworkEvents-removeEvent/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
######################################################################
# makefile
#
# Builds the example
######################################################################

##########
# Source files
##########

EXAMPLE_SKETCH=bug-NetworkEvents-removeEvent

EXECUTABLES += example

PARTITION_CSV_FILE=RTKEverywhere

ifeq ($(OS),Windows_NT)
# Windows NT utilities
CLEAR=cls
COPY=copy
DELETE=rmdir /s
DIR_LISTING=dir
TERMINAL_APP=
TERMINAL_PARAMS=

# Windows NT generic paths
USER_DIRECTORY_PATH=C:\Users\$(USERNAME)
ARDUINO_LIBRARY_PATH=$(USER_DIRECTORY_PATH)\Documents\Arduino\libraries
HOME_BOARD_PATH=$(USER_DIRECTORY_PATH)\AppData\Local\Arduino15\packages\esp32
PATCH_SRC_PATH=Patch\

# Windows NT patch source paths
PARTITION_SRC_PATH=..\$(PARTITION_CSV_FILE).csv
PATCH_SRC_PATH=Patch\

# Windows NT patch destination paths
BLE_PATCH_DST_PATH=$(ARDUINO_LIBRARY_PATH)\ESP32_BleSerial\src\
MBED_LIB_DEST_PATH=$(HOME_BOARD_PATH)\tools\esp32-arduino-libs\${{ env.ESP_IDF }}\esp32/lib\
PARTITION_DST_PATH=$(HOME_BOARD_PATH)\hardware\esp32\$(ESP_CORE_VERSION)\tools\partitions\$(PARTITION_CSV_FILE).csv

else
# Linux utilities
CLEAR=clear
COPY=cp
DELETE=rm -Rf
DIR_LISTING=ls
TERMINAL_APP=minicom
TERMINAL_PARAMS=-b 115200 -8 -D /dev/ttyUSB0 < /dev/tty

# Linux generic paths
USER_DIRECTORY_PATH=~
ARDUINO_LIBRARY_PATH=$(USER_DIRECTORY_PATH)/Arduino/libraries
ESP_IDF_PATH=$(HOME_BOARD_PATH)/tools/esp32-arduino-libs
HOME_BOARD_PATH=$(USER_DIRECTORY_PATH)/.arduino15/packages/esp32

# Linux patch source paths
PARTITION_SRC_PATH=../$(PARTITION_CSV_FILE).csv
PATCH_SRC_PATH=Patch/

# Linux patch destination paths
BLE_PATCH_DST_PATH=$(ARDUINO_LIBRARY_PATH)/ESP32_BleSerial/src/
MBED_LIB_DEST_PATH=$(ESP_IDF_PATH)/$(ESP_IDF_VERSION)/esp32/lib/
PARTITION_DST_PATH=$(HOME_BOARD_PATH)/hardware/esp32/$(ESP_CORE_VERSION)/tools/partitions/$(PARTITION_CSV_FILE).csv

endif

##########
# Buid all the sources - must be first
##########

.PHONY: all

all: $(EXECUTABLES)

##########
# Add ESP32 board support
##########

.PHONY: arduino-config

arduino-config:
arduino-cli config init --overwrite --additional-urls "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json"

##########
# Build an example
##########

.PHONY: example

example: build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin

DEBUG_LEVEL=none
#DEBUG_LEVEL=debug
#DEBUG_LEVEL=verbose

build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin: $(EXAMPLE_SKETCH).ino *.ino makefile
$(CLEAR)
arduino-cli compile --fqbn "esp32:esp32:esp32":DebugLevel=$(DEBUG_LEVEL),PSRAM=enabled $< \
--warnings default \
--build-property build.partitions=$(PARTITION_CSV_FILE) \
--build-property upload.maximum_size=6291456 \
--build-property "compiler.cpp.extra_flags=-MMD -c \"-DPOINTPERFECT_TOKEN=$(POINTPERFECT_TOKEN)\" \"-DFIRMWARE_VERSION_MAJOR=$(FIRMWARE_VERSION_MAJOR)\" \"-DFIRMWARE_VERSION_MINOR=$(FIRMWARE_VERSION_MINOR)\" \"-DENABLE_DEVELOPER=$(ENABLE_DEVELOPER)\"" \
--export-binaries

##########
# Upload the example
##########

ESPTOOL_PATH=~/Arduino/hardware/espressif/esp32/tools/esptool
TERMINAL_PORT="/dev/ttyUSB0"
BOOT_LOADER_PATH=~/SparkFun/SparkFun_RTK_Firmware_Uploader/RTK_Firmware_Uploader/resource

.PHONY: upload

upload: build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin
python3 $(ESPTOOL_PATH)/esptool.py \
--chip esp32 \
--port $(TERMINAL_PORT) \
--baud 921600 \
--before default_reset \
--after hard_reset \
write_flash \
--flash_mode dio \
--flash_freq 80m \
--flash_size detect \
--compress \
0x1000 $(BOOT_LOADER_PATH)/RTK_Surveyor.ino.bootloader.bin \
0x8000 $(BOOT_LOADER_PATH)/RTK_Surveyor_Partitions_16MB.bin \
0xe000 $(BOOT_LOADER_PATH)/boot_app0.bin \
0x10000 $<
$(TERMINAL_APP) $(TERMINAL_PARAMS)

##########
# Terminal
##########

.PHONY: terminal

terminal:
$(TERMINAL_APP) $(TERMINAL_PARAMS)

##########
# Clean up the example
##########

clean:
$(DELETE) build