Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Release 1.20.2.r2 #499

Merged
merged 31 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8d07cd9
Add timeout parameter to lte_send_at_cmd
Xykon Jul 27, 2020
09e39fe
Update modlte.c
Xykon Jul 27, 2020
d93abce
Update modlte.c
Xykon Jul 27, 2020
86665a2
PYCOM : make option MICROPY_FLOAT_IMPL
rcolistete Aug 5, 2020
a06c014
PYCOM : improved option MICROPY_FLOAT_IMPL
rcolistete Aug 7, 2020
218035c
Merge branch 'master' into lte_send_at_cmd_timeout
Xykon Aug 24, 2020
fdedb33
Merge pull request #167 from pycom/lte_send_at_cmd_timeout
Xykon Sep 21, 2020
38f9019
Fix memory leak happens after Bluetooth disconnect, fix a problem in …
geza-pycom Oct 21, 2020
ca10cd1
Fix a problem when machine.sleep(resume_wifi_ble=True) drops exceptio…
geza-pycom Oct 24, 2020
ca673c0
Small changes
geza-pycom Oct 25, 2020
e3f3b41
Adding these changes because looks good and even they not needed with…
geza-pycom Oct 25, 2020
c3e7b6c
pygate: reset the JIT queue margins
gijsio Oct 28, 2020
b728776
Merge pull request #193 from geza-pycom/Resume_problem_bt_disconnect_…
Xykon Nov 1, 2020
9f44896
Resume the BT Connection from the original list if connection was not…
geza-pycom Nov 3, 2020
e3f7111
Merge pull request #194 from geza-pycom/resume_problem_2
geza-pycom Nov 3, 2020
da9f545
Update _terminal.py
Xykon Nov 12, 2020
2064cbd
Merge pull request #174 from pycom/float_option
Xykon Nov 20, 2020
944d708
lorapf: add pygate_reset() to power cycle the module
peter-pycom Aug 27, 2020
58db509
LTE: check for SIM card before attaching
peter-pycom Aug 26, 2020
b822a70
lorapf: fix warnings
peter-pycom Nov 6, 2020
7d2e8e0
str_utils: add hexdump()
peter-pycom Nov 9, 2020
4937349
lte: debug MSG and state
peter-pycom Nov 9, 2020
9cc50b2
lte: callback LTE_EVENT_BREAK
peter-pycom Nov 10, 2020
a641ac5
modlte: improve exception texts
peter-pycom Nov 10, 2020
8e631ef
lte: reduce AT+CEREG from 2 to 1
peter-pycom Nov 11, 2020
6b4f392
BLE update
Xykon Nov 6, 2020
4254ab2
update idf 3394ee573
peter-pycom Nov 12, 2020
9a9a5b9
Merge remote-tracking branch 'pycom-micropython-sigfox/release_1.20.2…
Xykon Nov 23, 2020
6e2ff29
Update Pybytes to version 1.6.1
Xykon Nov 23, 2020
1097cbe
Update pycom_version.h
Xykon Nov 23, 2020
72bc4a7
Update _pybytes_protocol.py
Xykon Nov 23, 2020
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
Prev Previous commit
Next Next commit
Fix a problem when machine.sleep(resume_wifi_ble=True) drops exceptio…
…n when Pybytes & SmartConfig is used, but no WLAN connection has been established
  • Loading branch information
geza-pycom committed Oct 25, 2020
commit ca10cd1e52687cda8431d245bcd041f29f62bee0
4 changes: 2 additions & 2 deletions esp32/mods/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) {
}

modbt_deinit(reconnect);
wlan_deinit(NULL);
// TRUE means wlan_deinit is called from machine_sleep
wlan_deinit(mp_const_true);

if(ESP_OK != esp_light_sleep_start())
{
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Wifi or BT not stopped before sleep"));
}

/* resume wlan */
wlan_resume(reconnect);
/* resume bt */
Expand Down
101 changes: 72 additions & 29 deletions esp32/mods/modwlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ wlan_obj_t wlan_obj = {
.irq_enabled = false,
.pwrsave = false,
.is_promiscuous = false,
.sta_conn_timeout = false
.sta_conn_timeout = false,
.country = NULL
};

/* TODO: Maybe we can add possibility to create IRQs for wifi events */

static EventGroupHandle_t wifi_event_group;

static bool mod_wlan_is_deinit = false;
static uint16_t mod_wlan_ap_number_of_connections = 0;

/* Variables holding wlan conn params for wakeup recovery of connections */
Expand Down Expand Up @@ -135,6 +135,7 @@ SemaphoreHandle_t smartConfigTimeout_mutex;

static const int ESPTOUCH_DONE_BIT = BIT1;
static const int ESPTOUCH_STOP_BIT = BIT2;
static const int ESPTOUCH_SLEEP_STOP_BIT = BIT3;
static bool wlan_smart_config_enabled = false;

/******************************************************************************
Expand Down Expand Up @@ -202,24 +203,36 @@ void wlan_pre_init (void) {
wlan_obj.mutex = xSemaphoreCreateMutex();
timeout_mutex = xSemaphoreCreateMutex();
smartConfigTimeout_mutex = xSemaphoreCreateMutex();
memcpy(wlan_obj.country.cc, (const char*)"NA", sizeof(wlan_obj.country.cc));
// create Smart Config Task
xTaskCreatePinnedToCore(TASK_SMART_CONFIG, "SmartConfig", SMART_CONF_TASK_STACK_SIZE / sizeof(StackType_t), NULL, SMART_CONF_TASK_PRIORITY, &SmartConfTaskHandle, 1);
}

void wlan_resume (bool reconnect)
{
if (!wlan_obj.started && mod_wlan_is_deinit) {

mod_wlan_is_deinit = false;

if(reconnect)
{
wifi_country_t* country = NULL;

if(strcmp((const char*)wlan_obj.country.cc, "NA"))
{
country = &(wlan_obj.country);
// Configure back WLAN as it was before if reconnect is TRUE
if(reconnect) {
// If SmartConfig enabled then re-start it
if(wlan_smart_config_enabled) {
// Do initial configuration as at this point the Wifi Driver is not initialized
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
wlan_set_antenna(wlan_obj.antenna);
wlan_set_mode(wlan_obj.mode);
wlan_set_bandwidth(wlan_obj.bandwidth);
if(wlan_obj.country != NULL) {
esp_wifi_set_country(wlan_obj.country);
}
xTaskNotifyGive(SmartConfTaskHandle);
}
// Otherwise set up WLAN with the same parameters as it was before
else {
// In wlan_setup the wlan_obj.country is overwritten with the value coming from setup_config, need to save it out
wifi_country_t country;
wifi_country_t* country_ptr = NULL;
if(wlan_obj.country != NULL) {
memcpy(&country, wlan_obj.country, sizeof(wifi_country_t));
country_ptr = &country;
}

wlan_internal_setup_t setup_config = {
Expand All @@ -234,11 +247,11 @@ void wlan_resume (bool reconnect)
false,
wlan_conn_recover_hidden,
wlan_obj.bandwidth,
country,
country_ptr,
&(wlan_obj.max_tx_pwr)
};

// initialize the wlan subsystem
// Initialize & reconnect to the previous connection
wlan_setup(&setup_config);
}
}
Expand All @@ -258,12 +271,15 @@ void wlan_setup (wlan_internal_setup_t *config) {
wlan_set_bandwidth(config->bandwidth);

if (config->country != NULL) {

if(ESP_OK != esp_wifi_set_country(config->country))
esp_err_t ret = esp_wifi_set_country(config->country);
if(ESP_OK != ret)
{
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
}
memcpy(&(wlan_obj.country), config->country, sizeof(wlan_obj.country));
if(wlan_obj.country == NULL) {
wlan_obj.country = (wifi_country_t*)malloc(sizeof(wifi_country_t));
}
memcpy(wlan_obj.country, config->country, sizeof(wifi_country_t));
}

if(config->max_tx_pr != NULL)
Expand Down Expand Up @@ -950,9 +966,8 @@ static void TASK_SMART_CONFIG (void *pvParameters) {
static uint32_t thread_notification;

smartConf_init:
wlan_smart_config_enabled = false;
connected = false;
// Block task till notification is recieved
// Block task till notification is received
thread_notification = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

if (thread_notification) {
Expand All @@ -967,30 +982,37 @@ static void TASK_SMART_CONFIG (void *pvParameters) {
}
CHECK_ESP_ERR(esp_smartconfig_set_type(SC_TYPE_ESPTOUCH), smartConf_init)
CHECK_ESP_ERR(esp_smartconfig_start(smart_config_callback), smartConf_init)
wlan_smart_config_enabled = true;
goto smartConf_start;
}
goto smartConf_init;

smartConf_start:
//mp_printf(&mp_plat_print, "\n-------SmartConfig Started-------\n");
wlan_smart_config_enabled = true;
mp_printf(&mp_plat_print, "\n-------SmartConfig Started-------\n");
/*create Timer */
wlan_smartConfig_timeout = xTimerCreate("smartConfig_Timer", 60000 / portTICK_PERIOD_MS, 0, 0, wlan_timer_callback);
/*start Timer */
xTimerStart(wlan_smartConfig_timeout, 0);
while (1) {
uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT | ESPTOUCH_STOP_BIT, true, false, portMAX_DELAY);
uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT | ESPTOUCH_STOP_BIT | ESPTOUCH_SLEEP_STOP_BIT, true, false, portMAX_DELAY);
if(uxBits & ESPTOUCH_STOP_BIT) {
wlan_smart_config_enabled = false;
esp_smartconfig_stop();
//mp_printf(&mp_plat_print, "\nSmart Config Aborted or Timed-out\n");
goto smartConf_init;
}
if(uxBits & ESPTOUCH_SLEEP_STOP_BIT) {
esp_smartconfig_stop();
//mp_printf(&mp_plat_print, "\nSmart Config Aborted because sleep operation has been requested\n");
goto smartConf_init;
}
if(uxBits & CONNECTED_BIT) {
//mp_printf(&mp_plat_print, "WiFi Connected to ap\n");
connected = true;
}
if(uxBits & ESPTOUCH_DONE_BIT) {
//mp_printf(&mp_plat_print, "smartconfig over\n");
wlan_smart_config_enabled = false;
esp_smartconfig_stop();
wlan_stop_smartConfig_timer();
//set event flag
Expand Down Expand Up @@ -1244,11 +1266,25 @@ mp_obj_t wlan_deinit(mp_obj_t self_in) {

if (wlan_obj.started)
{
bool called_from_sleep = false;

// stop smart config if enabled
if(wlan_smart_config_enabled)
{
xEventGroupSetBits(wifi_event_group, ESPTOUCH_STOP_BIT);
vTaskDelay(100/portTICK_PERIOD_MS);
if(wlan_smart_config_enabled) {
// If the input parameter is not the object itself but a simple boolean, it is interpreted that
// wlan_deinit is called from machine_sleep()
if(mp_obj_get_type(self_in) == &mp_type_bool) {
called_from_sleep = (bool)mp_obj_get_int(self_in);
if(called_from_sleep == true) {
// stop smart config with special event
xEventGroupSetBits(wifi_event_group, ESPTOUCH_SLEEP_STOP_BIT);
vTaskDelay(100/portTICK_PERIOD_MS);
}
}
else {
// stop smart config with original STOP event
xEventGroupSetBits(wifi_event_group, ESPTOUCH_STOP_BIT);
vTaskDelay(100/portTICK_PERIOD_MS);
}
}

mod_network_deregister_nic(&wlan_obj);
Expand All @@ -1262,7 +1298,11 @@ mp_obj_t wlan_deinit(mp_obj_t self_in) {

/* stop and free wifi resource */
esp_wifi_deinit();
mod_wlan_is_deinit = true;
// Only free up memory area of country information if this deinit is not called from machine.sleep()
if(called_from_sleep == false) {
free(wlan_obj.country);
wlan_obj.country = NULL;
}
wlan_obj.started = false;
mod_network_deregister_nic(&wlan_obj);
}
Expand Down Expand Up @@ -2446,6 +2486,9 @@ STATIC mp_obj_t wlan_country(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
}

if(wlan_obj.country == NULL) {
wlan_obj.country = (wifi_country_t*)malloc(sizeof(wifi_country_t));
}
memcpy(&(wlan_obj.country), &country_config, sizeof(wlan_obj.country));

return mp_const_none;
Expand Down
2 changes: 1 addition & 1 deletion esp32/mods/modwlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct _wlan_obj_t {
uint8_t channel;
uint8_t antenna;
int8_t max_tx_pwr;
wifi_country_t country;
wifi_country_t* country;

// my own ssid, key and mac
uint8_t ssid[(MODWLAN_SSID_LEN_MAX + 1)];
Expand Down