Updated 'network' module

Operating in STA & AP mode at the same time (APSTA) is now supported

Updated 'machine.ADC' module
  Fixed bug: 'adc.read()' always  returns 0
  Added support for ADC2
  other minor bug fixes and improvements
This commit is contained in:
Boris Lovosevic
2018-04-15 14:38:23 +02:00
parent 1996d7b5c8
commit 7dd4cba81a
32 changed files with 802 additions and 435 deletions
@@ -1394,6 +1394,16 @@ bool ftp_terminate (void) {
return res;
}
//-------------------------
bool ftp_stop_requested() {
if ((FtpTaskHandle == NULL) || (ftp_mutex == NULL)) return false;
if (xSemaphoreTake(ftp_mutex, FTP_MUTEX_TIMEOUT_MS / portTICK_PERIOD_MS) !=pdTRUE) return false;
bool res = (ftp_stop == 1);
xSemaphoreGive(ftp_mutex);
return res;
}
//-------------------------------
int32_t ftp_get_maxstack (void) {
if ((FtpTaskHandle == NULL) || (ftp_mutex == NULL)) return -1;
@@ -79,6 +79,7 @@ bool ftp_disable (void);
bool ftp_reset (void);
int ftp_getstate();
bool ftp_terminate (void);
bool ftp_stop_requested();
int32_t ftp_get_maxstack (void);
#endif
@@ -723,6 +723,16 @@ bool telnet_terminate (void) {
return true;
}
//----------------------------
bool telnet_stop_requested() {
if ((TelnetTaskHandle == NULL) || (telnet_mutex == NULL)) return false;
if (xSemaphoreTake(telnet_mutex, TELNET_MUTEX_TIMEOUT_MS / portTICK_PERIOD_MS) !=pdTRUE) return false;
bool res = (telnet_stop == 1);
xSemaphoreGive(telnet_mutex);
return res;
}
//----------------------------------
int32_t telnet_get_maxstack (void) {
if ((TelnetTaskHandle == NULL) || (telnet_mutex == NULL)) return -1;
@@ -79,6 +79,7 @@ bool telnet_isenabled (void);
bool telnet_reset (void);
int telnet_getstate();
bool telnet_terminate (void);
bool telnet_stop_requested();
int32_t telnet_get_maxstack (void);
#endif
@@ -39,68 +39,185 @@
#include "py/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"
#include "machine_pin.h"
#define ADC1_CHANNEL_HALL ADC1_CHANNEL_MAX
typedef struct _madc_obj_t {
mp_obj_base_t base;
int gpio_id;
adc1_channel_t adc1_id;
adc_unit_t adc_num;
adc1_channel_t adc_chan;
adc_atten_t atten;
adc_bits_width_t width;
} madc_obj_t;
static uint16_t adc_chan_used = 0;
static uint16_t adc1_chan_used = 0;
static uint16_t adc2_chan_used = 0;
static int8_t adc_width = -1;
static int8_t last_adc_width = -1;
static int8_t last_adc_num = -1;
static uint32_t adc_vref = 1100;
static uint32_t last_adc_vref = 0;
static adc_atten_t last_atten = ADC_ATTEN_MAX;
static adc_atten_t last_atten2 = ADC_ATTEN_MAX;
static esp_adc_cal_characteristics_t characteristics;
static const uint8_t adc1_gpios[ADC1_CHANNEL_MAX] = {36, 37, 38, 39, 32, 33, 34, 35};
static const uint8_t adc2_gpios[ADC2_CHANNEL_MAX] = {4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
//-------------------------------------
static void set_width(madc_obj_t *self)
{
if (adc_width != self->width) {
if (self->adc_num == ADC_UNIT_1) {
esp_err_t err = adc1_config_width(self->width);
if (err != ESP_OK) mp_raise_ValueError("Set width Error");
}
else {
adc_set_data_width(self->adc_num, self->width);
}
adc_width = self->width;
}
}
//-----------------------------------------------------
static int get_adc_channel(adc_unit_t adc_num, int pin)
{
int channel = -1;
if (adc_num == ADC_UNIT_1) {
for (int i=0; i < ADC1_CHANNEL_MAX; i++) {
if (adc1_gpios[i] == pin) {
channel = i;
break;
}
}
}
else {
for (int i=0; i < ADC2_CHANNEL_MAX; i++) {
if (adc2_gpios[i] == pin) {
channel = i;
break;
}
}
}
return channel;
}
//------------------------------------------------------------------------------------------------------------
STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
{
enum { ARG_pin, ARG_unit };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none}},
{ MP_QSTR_unit, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ADC_UNIT_1}},
};
// parse arguments
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
//----------------------------------------------------------------------------------------------------------
STATIC mp_obj_t madc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
esp_err_t err = 0;
mp_arg_check_num(n_args, n_kw, 1, 1, true);
int pin_id = 0;
if (MP_OBJ_IS_INT(args[0])) pin_id = mp_obj_get_int(args[0]);
else pin_id = machine_pin_get_id(args[0]);
pin_id = machine_pin_get_gpio(args[ARG_pin].u_obj);
madc_obj_t *self = m_new_obj(madc_obj_t);;
self->base.type = &machine_adc_type;
if ((pin_id != ADC1_CHANNEL_HALL) && ((pin_id < 32) || (pin_id > 39))) mp_raise_ValueError("invalid Pin for ADC");
self->atten = ADC_ATTEN_0db;
self->adc_num = args[ARG_unit].u_int;
if ((self->adc_num != ADC_UNIT_1) && (self->adc_num != ADC_UNIT_2)) {
mp_raise_ValueError("invalid ADC unit (1 and 2 allowed)");
}
self->atten = ADC_ATTEN_DB_0;
self->width = ADC_WIDTH_BIT_12;
if (pin_id != ADC1_CHANNEL_HALL) {
if (pin_id > 35) self->adc1_id = ADC1_CHANNEL_0 + (pin_id-36);
else self->adc1_id = ADC1_CHANNEL_4 + (pin_id-32);
if ((adc_chan_used & 0x0100) && ((self->adc1_id == 36) || (self->adc1_id == 39))) mp_raise_ValueError("hall used, cannot use pins 36 & 39");
adc_chan_used |= (1 << self->adc1_id);
self->gpio_id = pin_id;
self->gpio_id = pin_id;
err = adc1_config_channel_atten(self->adc1_id, ADC_ATTEN_0db);
if (err != ESP_OK) mp_raise_ValueError("Parameter Error");
if (pin_id != ADC1_CHANNEL_HALL) {
int channel = get_adc_channel(self->adc_num, pin_id);
if (channel < 0) mp_raise_ValueError("invalid Pin for ADC");
self->adc_chan = channel;
self->gpio_id = pin_id;
if (self->adc_num == ADC_UNIT_1) {
if ((adc1_chan_used & 0x0100) && ((pin_id == 36) || (pin_id == 39))) mp_raise_ValueError("hall used, cannot use pins 36 & 39");
if (adc1_chan_used & (1 << self->adc_chan)) mp_raise_ValueError("pin already used for adc");
adc1_chan_used |= (1 << self->adc_chan);
err = adc_gpio_init(self->adc_num, self->adc_chan);
if (err != ESP_OK) mp_raise_ValueError("Error configuring ADC gpio");
err = adc1_config_channel_atten(self->adc_chan, ADC_ATTEN_DB_0);
if (err != ESP_OK) mp_raise_ValueError("Error configuring attenuation");
}
else {
if (adc2_chan_used & (1 << self->adc_chan)) mp_raise_ValueError("pin already used for adc");
adc2_chan_used |= (1 << self->adc_chan);
gpio_pad_select_gpio(self->gpio_id);
gpio_set_direction(self->gpio_id, GPIO_MODE_DISABLE);
gpio_set_pull_mode(self->gpio_id, GPIO_FLOATING);
adc_gpio_init(self->adc_num, self->adc_chan);
if (err != ESP_OK) mp_raise_ValueError("Error configuring ADC gpio");
if (last_atten2 != self->atten) {
adc2_config_channel_atten(self->adc_chan, self->atten);
last_atten2 = self->atten;
}
}
}
else {
if (adc_chan_used & 0x09) mp_raise_ValueError("adc on gpio 36 or 39 used");
self->adc1_id = ADC1_CHANNEL_HALL;
self->adc_num = ADC_UNIT_1;
if (adc1_chan_used & 0x09) mp_raise_ValueError("adc on gpio 36 or 39 used");
if (adc1_chan_used & 0x0100) mp_raise_ValueError("hall already used");
adc1_chan_used |= 0x0100;
self->adc_chan = ADC1_CHANNEL_HALL;
self->gpio_id = GPIO_NUM_MAX;
}
if (adc_width != self->width) {
err = adc1_config_width(self->width);
if (err != ESP_OK) mp_raise_ValueError("Set width Error");
adc_width = self->width;
}
set_width(self);
return MP_OBJ_FROM_PTR(self);
}
//-------------------------------------------
STATIC mp_obj_t madc_deinit(mp_obj_t self_in)
{
madc_obj_t *self = self_in;
if (self->gpio_id < 0) return mp_const_none;
if (self->adc_num == ADC_UNIT_1) {
if (self->adc_chan == ADC1_CHANNEL_HALL) {
adc1_chan_used &= 0x00FF;
gpio_pad_select_gpio(36);
gpio_pad_select_gpio(39);
}
else {
adc1_chan_used &= (~(1 << self->adc_chan) & 0x1FF);
gpio_pad_select_gpio(self->gpio_id);
gpio_set_direction(self->gpio_id, GPIO_MODE_INPUT);
gpio_set_pull_mode(self->gpio_id, GPIO_FLOATING);
}
}
else {
adc2_chan_used &= (~(1 << self->adc_chan) & 0x3FF);
gpio_pad_select_gpio(self->gpio_id);
gpio_set_direction(self->gpio_id, GPIO_MODE_INPUT);
gpio_set_pull_mode(self->gpio_id, GPIO_FLOATING);
}
self->gpio_id = -1;
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(madc_deinit_obj, madc_deinit);
//---------------------------------------------------------------------------------------
STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
madc_obj_t *self = self_in;
if (self->gpio_id < 0) {
mp_printf(print, "ADC( deinitialized )");
return;
}
char satten[16];
char spin[8];
if (self->atten == ADC_ATTEN_DB_0) sprintf(satten, "0dB (1.1V)");
@@ -112,22 +229,32 @@ STATIC void madc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
if (self->gpio_id == GPIO_NUM_MAX) sprintf(spin, "HALL");
else sprintf(spin, "Pin(%u)", self->gpio_id);
mp_printf(print, "ADC(%s: width=%u bits, atten=%s, Vref=%u mV)", spin, self->width+9, satten, adc_vref);
mp_printf(print, "ADC(%s: unit=ADC%d, chan=%d, width=%u bits, atten=%s, Vref=%u mV)", spin, self->adc_num, self->adc_chan, self->width+9, satten, adc_vref);
}
//----------------------------------------------
STATIC mp_obj_t madc_readraw(mp_obj_t self_in) {
madc_obj_t *self = self_in;
if (adc_width != self->width) {
esp_err_t err = adc1_config_width(self->width);
if (err != ESP_OK) mp_raise_ValueError("Set width Error");
adc_width = self->width;
}
if (self->gpio_id < 0) {
mp_raise_ValueError("Not initialized");
}
int val = 0;
if (self->gpio_id == GPIO_NUM_MAX) val= hall_sensor_read();
else val = adc1_get_raw(self->adc1_id);
if (val == -1) mp_raise_ValueError("Parameter Error");
int val = 0;
if (self->adc_num == ADC_UNIT_1) {
set_width(self);
if (self->gpio_id == GPIO_NUM_MAX) val= hall_sensor_read();
else val = adc1_get_raw(self->adc_chan);
if (val == -1) mp_raise_ValueError("Parameter Error (ADC raw read)");
}
else {
if (last_atten2 != self->atten) {
adc2_config_channel_atten(self->adc_chan, self->atten);
last_atten2 = self->atten;
}
esp_err_t err = adc2_get_raw(self->adc_chan, self->atten, &val);
if (err != ESP_OK) mp_raise_ValueError("Cannot read, ADC2 used by Wi-Fi");
}
return MP_OBJ_NEW_SMALL_INT(val);
}
@@ -136,21 +263,34 @@ MP_DEFINE_CONST_FUN_OBJ_1(madc_readraw_obj, madc_readraw);
//-------------------------------------------
STATIC mp_obj_t madc_read(mp_obj_t self_in) {
madc_obj_t *self = self_in;
esp_adc_cal_characteristics_t characteristics;
if (adc_width != self->width) {
esp_err_t err = adc1_config_width(self->width);
if (err != ESP_OK) mp_raise_ValueError("Set width Error");
}
if (self->gpio_id < 0) {
mp_raise_ValueError("Not initialized");
}
set_width(self);
int adc_val = 0;
if (self->gpio_id == GPIO_NUM_MAX) adc_val= hall_sensor_read();
else {
// Deprecated
//esp_adc_cal_get_characteristics(adc_vref, self->atten, self->width, &characteristics);
//adc_val = adc1_to_voltage(self->adc1_id, &characteristics);
if ((last_adc_num != self->adc_num) || (last_adc_vref != adc_vref) || (last_atten != self->atten) || (last_adc_width != self->width)) {
// New characterization needed
esp_adc_cal_value_t cal_val = esp_adc_cal_characterize(self->adc_num, self->atten, self->width, adc_vref, &characteristics);
last_adc_vref = adc_vref;
last_atten = self->atten;
last_adc_width = self->width;
last_adc_num = self->adc_num;
esp_adc_cal_value_t adc_val = esp_adc_cal_characterize(ADC_UNIT_1, self->atten, self->width, adc_vref, &characteristics);
esp_adc_cal_get_voltage(self->adc1_id, &characteristics, &adc_val);
ESP_LOGD("MOD_ADC", "Characterize ADC_UNIT_%d: Vref used: %s", self->adc_num, (cal_val == 0) ? "eFuse" : (cal_val == 1) ? "Two point" : "Default");
}
if ((self->adc_num == ADC_UNIT_2) && (last_atten2 != self->atten)) {
adc2_config_channel_atten(self->adc_chan, self->atten);
last_atten2 = self->atten;
}
esp_err_t err = esp_adc_cal_get_voltage(self->adc_chan, &characteristics, (uint32_t *)&adc_val);
if (err != ESP_OK) {
if (self->adc_num == ADC_UNIT_2) mp_raise_ValueError("Cannot read, ADC2 used by Wi-Fi");
else mp_raise_ValueError("Error reading");
}
}
return MP_OBJ_NEW_SMALL_INT(adc_val);
}
@@ -159,13 +299,26 @@ MP_DEFINE_CONST_FUN_OBJ_1(madc_read_obj, madc_read);
//---------------------------------------------------------------
STATIC mp_obj_t madc_atten(mp_obj_t self_in, mp_obj_t atten_in) {
madc_obj_t *self = self_in;
if (self->gpio_id == GPIO_NUM_MAX) return mp_const_none;
if (self->gpio_id < 0) {
mp_raise_ValueError("Not initialized");
}
if (self->gpio_id == GPIO_NUM_MAX) return mp_const_none;
adc_atten_t atten = mp_obj_get_int(atten_in);
if ((atten < ADC_ATTEN_DB_0) || (atten > ADC_ATTEN_DB_11)) mp_raise_ValueError("Unsupported atten value");
esp_err_t err = adc1_config_channel_atten(self->adc1_id, atten);
if (err != ESP_OK) mp_raise_ValueError("Parameter Error");
esp_err_t err;
if (self->adc_num == ADC_UNIT_1) {
err = adc1_config_channel_atten(self->adc_chan, atten);
if (err != ESP_OK) mp_raise_ValueError("Parameter Error (config attenuation)");
}
else {
if (last_atten2 != atten) {
adc2_config_channel_atten(self->adc_chan, atten);
last_atten2 = self->atten;
}
}
self->atten = atten;
return mp_const_none;
}
@@ -174,7 +327,11 @@ MP_DEFINE_CONST_FUN_OBJ_2(madc_atten_obj, madc_atten);
//---------------------------------------------------------------
STATIC mp_obj_t madc_width(mp_obj_t self_in, mp_obj_t width_in) {
madc_obj_t *self = self_in;
if (self->gpio_id == GPIO_NUM_MAX) return mp_const_none;
if (self->gpio_id < 0) {
mp_raise_ValueError("Not initialized");
}
if (self->gpio_id == GPIO_NUM_MAX) return mp_const_none;
adc_bits_width_t width = mp_obj_get_int(width_in);
if ((width < ADC_WIDTH_9Bit) || (width > ADC_WIDTH_12Bit)) mp_raise_ValueError("Unsupported width value");
@@ -224,6 +381,7 @@ STATIC const mp_rom_map_elem_t madc_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_atten), MP_ROM_PTR(&madc_atten_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&madc_width_obj) },
{ MP_ROM_QSTR(MP_QSTR_vref), MP_ROM_PTR(&madc_vref_togpio_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&madc_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_HALL), MP_ROM_INT(ADC1_CHANNEL_MAX) },
@@ -165,7 +165,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
// configure the pin for gpio
if (rtc_gpio_is_valid_gpio(self->id)) rtc_gpio_deinit(self->id);
if (self->id < 28) gpio_pad_select_gpio(self->id);
gpio_pad_select_gpio(self->id);
// set initial value (do this before configuring mode/pull)
if (args[ARG_value].u_obj != MP_OBJ_NULL) {
@@ -270,10 +270,19 @@ void micropython_entry(void) {
// === Set esp32 log levels while running MicroPython ===
if (CONFIG_MICRO_PY_LOG_LEVEL < CONFIG_LOG_DEFAULT_LEVEL) esp_log_level_set("*", CONFIG_MICRO_PY_LOG_LEVEL);
esp_log_level_set("wifi", ESP_LOG_ERROR);
esp_log_level_set("rmt", ESP_LOG_ERROR);
if ((CONFIG_LOG_DEFAULT_LEVEL > ESP_LOG_WARN) && (CONFIG_MICRO_PY_LOG_LEVEL > ESP_LOG_WARN)){
esp_log_level_set("wifi", ESP_LOG_WARN);
esp_log_level_set("rmt", ESP_LOG_WARN);
esp_log_level_set("tcpip_adapter", ESP_LOG_WARN);
esp_log_level_set("event", ESP_LOG_WARN);
esp_log_level_set("nvs", ESP_LOG_WARN);
esp_log_level_set("phy_init", ESP_LOG_WARN);
esp_log_level_set("wl_flash", ESP_LOG_WARN);
esp_log_level_set("RTC_MODULE", ESP_LOG_WARN);
}
#ifdef CONFIG_MICROPY_USE_OTA
esp_log_level_set("OTA_UPDATE", ESP_LOG_DEBUG);
if (CONFIG_LOG_DEFAULT_LEVEL >= ESP_LOG_DEBUG) esp_log_level_set("OTA_UPDATE", ESP_LOG_DEBUG);
else esp_log_level_set("OTA_UPDATE", CONFIG_LOG_DEFAULT_LEVEL);
#endif
nvs_flash_init();
@@ -52,6 +52,7 @@
#include "esp_log.h"
#include "esp_err.h"
#include "esp_pm.h"
#include "esp_wifi.h"
#include "driver/uart.h"
#include "py/obj.h"
@@ -64,6 +65,7 @@
#include "mpsleep.h"
#include "machine_rtc.h"
#include "uart.h"
#include "modnetwork.h"
#if MICROPY_PY_MACHINE
@@ -176,7 +178,7 @@ static void RTC_IRAM_ATTR wake_stub()
if ((machine_rtc_config.deepsleep_time) && (machine_rtc_config.deepsleep_interval)) {
// == Set the out pin to active level if configured
if (machine_rtc_config.stub_outpin >= 0) {
if (machine_rtc_config.stub_outpin < 28) gpio_pad_select_gpio(machine_rtc_config.stub_outpin);
gpio_pad_select_gpio(machine_rtc_config.stub_outpin);
if (machine_rtc_config.stub_outpin < 32)
gpio_output_set(machine_rtc_config.stub_outpin_level << machine_rtc_config.stub_outpin,
(machine_rtc_config.stub_outpin_level ? 0 : 1) << machine_rtc_config.stub_outpin,
@@ -279,6 +281,17 @@ void prepareSleepReset(uint8_t hrst, char *msg)
if (!hrst) {
if (msg) mp_hal_stdout_tx_str(msg);
// stop and deinitialize WiFi
if (wifi_network_state == WIFI_STATE_STARTED) {
wifi_network_state = WIFI_STATE_STOPPED;
wifi_sta_isconnected = false;
wifi_sta_has_ipaddress = false;
wifi_sta_changed_ipaddress = false;
wifi_ap_isconnected = false;
wifi_ap_sta_isconnected = false;
esp_wifi_stop();
esp_wifi_deinit();
}
// deinitialise peripherals
//ToDo: deinitialize other peripherals, threads, services, ...
machine_pins_deinit();
File diff suppressed because it is too large Load Diff
@@ -24,14 +24,23 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_ESP32_MODNETWORK_H
#define MICROPY_INCLUDED_ESP32_MODNETWORK_H
#include "esp_wifi_types.h"
#define WIFI_STATE_NOTINIT -1
#define WIFI_STATE_INIT 0
#define WIFI_STATE_STOPPED 1
#define WIFI_STATE_STARTED 2
enum { PHY_LAN8720, PHY_TLK110 };
typedef struct _wlan_if_obj_t {
mp_obj_base_t base;
int if_id;
wifi_mode_t wifi_mode;
} wlan_if_obj_t;
typedef void (*wifi_sta_rx_probe_req_t)(const uint8_t *frame, int len, int rssi);
@@ -245,7 +245,7 @@ class MicroWebSrv :
def Start(self, threaded=True, stackSize=8192) :
if not self._started :
if not network.WLAN().isactive():
if not network.WLAN().wifiactive():
print("WLAN not connected!")
return
gc.collect()
@@ -148,8 +148,8 @@ def ftpserver(timeout = 300, inthread = False, prnip = True):
if prnip:
print ("Starting ftp server. Version 1.2")
if not network.WLAN().isconnected():
print("Not connected!")
if not network.WLAN().wifiactive():
print("WiFi not started!")
return
DATA_PORT = 1050
@@ -700,29 +700,20 @@ int mp_thread_replAcceptMsg(int8_t accept) {
#if defined(CONFIG_MICROPY_USE_TELNET) || defined(CONFIG_MICROPY_USE_FTPSERVER)
// Check if WiFi connection is available
//----------------------
static int _check_wifi()
//-----------------------
static bool _check_wifi()
{
if (wifi_network_state < 2) return 2;
if (wifi_network_state < 2) return false;
tcpip_adapter_if_t if_type;
tcpip_adapter_ip_info_t info;
bool res = 0;
wifi_mode_t wifi_mode;
esp_err_t ret = esp_wifi_get_mode(&wifi_mode);
if (ret != ESP_OK) return 0;
if (wifi_mode == WIFI_MODE_AP) if_type = TCPIP_ADAPTER_IF_AP;
else if (wifi_mode == WIFI_MODE_STA) if_type = TCPIP_ADAPTER_IF_STA;
else return 2;
ret = tcpip_adapter_get_ip_info(if_type, &info);
if (ret != ESP_OK) return 0;
if (info.ip.addr == 0) return 0;
if ((wifi_mode == WIFI_MODE_STA) && ((!wifi_sta_isconnected) || (!wifi_sta_has_ipaddress))) return 0;
else if ((wifi_mode == WIFI_MODE_AP) && (!wifi_ap_isconnected)) return 0;
return 1;
if (ret == ESP_OK) {
if ((wifi_mode & WIFI_MODE_STA) && ((wifi_sta_isconnected) && (wifi_sta_has_ipaddress))) res = true;
if ((wifi_mode & WIFI_MODE_AP) && wifi_ap_isconnected) res = true;
}
return res;
}
#endif
@@ -730,45 +721,40 @@ static int _check_wifi()
//===================================
void telnet_task (void *pvParameters)
{
int res;
// Initialize telnet, create rx buffer and mutex
telnet_init();
// Check if WiFi connection is available
res = _check_wifi();
while ( res == 0) {
while (!_check_wifi()) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
res = _check_wifi();
if (telnet_stop_requested()) goto exit;
}
if (res == 2) goto exit;
// We have WiFi connection, enable telnet
telnet_enable();
while (1) {
res = telnet_run();
int res = telnet_run();
if ( res < 0) {
if (res == -1) {
ESP_LOGD("[Telnet]", "\nRun Error");
}
// -2 is returned if Telnet stop was requested by user
break;
}
vTaskDelay(1);
// ---- Check if WiFi is still available ----
res = _check_wifi();
if (res == 0) {
if (!_check_wifi()) {
bool was_enabled = telnet_isenabled();
telnet_disable();
while ( res == 0) {
while (!_check_wifi()) {
vTaskDelay(200 / portTICK_PERIOD_MS);
res = _check_wifi();
if (res == 2) goto exit;
if (telnet_stop_requested()) goto exit;
}
if (was_enabled) telnet_enable();
}
else if (res == 2) break;
// ------------------------------------------
}
exit:
@@ -802,17 +788,14 @@ uintptr_t mp_thread_createTelnetTask(size_t stack_size)
//================================
void ftp_task (void *pvParameters)
{
int res;
uint64_t elapsed, time_ms = mp_hal_ticks_ms();
// Initialize ftp, create rx buffer and mutex
ftp_init();
res = _check_wifi();
while ( res == 0) {
while (!_check_wifi()) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
res = _check_wifi();
if (ftp_stop_requested()) goto exit;
}
if (res == 2) goto exit;
// We have WiFi connection, enable ftp
ftp_enable();
@@ -822,29 +805,27 @@ void ftp_task (void *pvParameters)
elapsed = mp_hal_ticks_ms() - time_ms;
time_ms = mp_hal_ticks_ms();
res = ftp_run(elapsed);
int res = ftp_run(elapsed);
if (res < 0) {
if (res == -1) {
ESP_LOGD("[Ftp]", "\nRun Error");
}
// -2 is returned if Ftp stop was requested by user
break;
}
vTaskDelay(1);
// ---- Check if WiFi is still available ----
res = _check_wifi();
if (res == 0) {
if (!_check_wifi()) {
bool was_enabled = ftp_isenabled();
ftp_disable();
while ( res == 0) {
while (!_check_wifi()) {
vTaskDelay(200 / portTICK_PERIOD_MS);
res = _check_wifi();
if (res == 2) goto exit;
if (ftp_stop_requested()) goto exit;
}
if (was_enabled) ftp_enable();
}
else if (res == 2) break;
// ------------------------------------------
}
exit:
@@ -24,12 +24,12 @@
* THE SOFTWARE.
*/
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.2.9"
#define MICROPY_GIT_TAG "ESP32_LoBo_v3.2.10"
#define MICROPY_GIT_HASH "gbae9709a"
#define MICROPY_BUILD_DATE "2018-04-12"
#define MICROPY_BUILD_DATE "2018-04-15"
#define MICROPY_VERSION_MAJOR (3)
#define MICROPY_VERSION_MINOR (2)
#define MICROPY_VERSION_MICRO (9)
#define MICROPY_VERSION_STRING "3.2.9"
#define MICROPY_VERSION_MICRO (10)
#define MICROPY_VERSION_STRING "3.2.10"
#define MICROPY_CORE_VERSION "59dda71"
#define MICROPY_CORE_DATE "2018-04-10"

Some files were not shown because too many files have changed in this diff Show More