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

Commit dfa1176

Browse files
committed
LTE class bug fixes [1.18.1.r4]
1 parent 3aac0f3 commit dfa1176

File tree

3 files changed

+91
-42
lines changed

3 files changed

+91
-42
lines changed

esp32/lte/lteppp.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ static uint32_t lteppp_output_callback(ppp_pcb *pcb, u8_t *data, u32_t len, void
8181
******************************************************************************/
8282
void connect_lte_uart (void) {
8383

84-
uart_driver_delete(LTE_UART_ID);
84+
// bool success = uart_driver_delete(LTE_UART_ID);
85+
// vTaskDelay(5 / portTICK_RATE_MS);
86+
// printf("Driver deleted? %d\n", success);
8587

8688
// initialize the UART interface
8789
uart_config_t config;
@@ -93,25 +95,29 @@ void connect_lte_uart (void) {
9395
config.rx_flow_ctrl_thresh = 64;
9496
uart_param_config(LTE_UART_ID, &config);
9597

96-
//deassign LTE Uart pins
97-
pin_deassign(MICROPY_LTE_TX_PIN);
98-
gpio_pullup_dis(MICROPY_LTE_TX_PIN->pin_number);
99-
100-
pin_deassign(MICROPY_LTE_RX_PIN);
101-
gpio_pullup_dis(MICROPY_LTE_RX_PIN->pin_number);
102-
103-
pin_deassign(MICROPY_LTE_CTS_PIN);
104-
gpio_pullup_dis(MICROPY_LTE_CTS_PIN->pin_number);
105-
106-
pin_deassign(MICROPY_LTE_RTS_PIN);
107-
gpio_pullup_dis(MICROPY_LTE_RTS_PIN->pin_number);
98+
// //deassign LTE Uart pins
99+
// pin_deassign(MICROPY_LTE_TX_PIN);
100+
// gpio_pullup_dis(MICROPY_LTE_TX_PIN->pin_number);
101+
//
102+
// pin_deassign(MICROPY_LTE_RX_PIN);
103+
// gpio_pullup_dis(MICROPY_LTE_RX_PIN->pin_number);
104+
//
105+
// pin_deassign(MICROPY_LTE_CTS_PIN);
106+
// gpio_pullup_dis(MICROPY_LTE_CTS_PIN->pin_number);
107+
//
108+
// pin_deassign(MICROPY_LTE_RTS_PIN);
109+
// gpio_pullup_dis(MICROPY_LTE_RTS_PIN->pin_number);
110+
//
111+
// vTaskDelay(5 / portTICK_RATE_MS);
108112

109113
// configure the UART pins
110114
pin_config(MICROPY_LTE_TX_PIN, -1, U2TXD_OUT_IDX, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 1);
111115
pin_config(MICROPY_LTE_RX_PIN, U2RXD_IN_IDX, -1, GPIO_MODE_INPUT, MACHPIN_PULL_NONE, 1);
112116
pin_config(MICROPY_LTE_RTS_PIN, -1, U2RTS_OUT_IDX, GPIO_MODE_OUTPUT, MACHPIN_PULL_NONE, 1);
113117
pin_config(MICROPY_LTE_CTS_PIN, U2CTS_IN_IDX, -1, GPIO_MODE_INPUT, MACHPIN_PULL_NONE, 1);
114118

119+
vTaskDelay(5 / portTICK_RATE_MS);
120+
115121
// install the UART driver
116122
uart_driver_install(LTE_UART_ID, LTE_UART_BUFFER_SIZE, LTE_UART_BUFFER_SIZE, 0, NULL, 0, NULL);
117123
lteppp_uart_reg = &UART2;
@@ -230,7 +236,7 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m
230236
//printf("%s\n", lteppp_trx_buffer);
231237
if (expected_rsp != NULL) {
232238
if (strstr(lteppp_trx_buffer, expected_rsp) != NULL) {
233-
//printf("Found %s\n", lteppp_trx_buffer);
239+
//printf("RESP: %s\n", lteppp_trx_buffer);
234240
return true;
235241
}
236242
}
@@ -394,7 +400,7 @@ static bool lteppp_send_at_cmd_exp (const char *cmd, uint32_t timeout, const cha
394400
uint32_t cmd_len = strlen(cmd);
395401
// char tmp_buf[128];
396402

397-
//printf("cmd: %s\n", cmd);
403+
//printf("at_cmd_exp: %s\n", cmd);
398404

399405
// flush the rx buffer first
400406
uart_flush(LTE_UART_ID);

esp32/mods/modlte.c

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ extern TaskHandle_t svTaskHandle;
9393
#if defined(FIPY)
9494
extern TaskHandle_t xLoRaTaskHndl;
9595
extern TaskHandle_t xSigfoxTaskHndl;
96+
//extern TaskHandle_t xMeshTaskHndl;
9697
#endif
9798
extern TaskHandle_t xLTETaskHndl;
9899

@@ -168,55 +169,87 @@ static void lte_pause_ppp(void) {
168169
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
169170
if (!lte_push_at_command("+++", LTE_PPP_BACK_OFF_TIME_MS)) {
170171
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
171-
if (!lte_push_at_command("+++", LTE_RX_TIMEOUT_MAX_MS)) {
172-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
172+
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MIN_MS)) {
173+
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
174+
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MIN_MS)) {
175+
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
176+
if (!lte_push_at_command("+++", LTE_PPP_BACK_OFF_TIME_MS)) {
177+
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
178+
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MIN_MS)) {
179+
mp_hal_delay_ms(LTE_PPP_BACK_OFF_TIME_MS);
180+
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MIN_MS)) {
181+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_operation_failed));
182+
}
183+
}
184+
}
185+
}
173186
}
174187
}
175188
}
176189

177190
static bool lte_check_attached(void) {
178191
char *pos;
179192
bool attached = false;
193+
bool cgatt = false;
180194
if (lteppp_get_state() == E_LTE_PPP && lteppp_ipv4() > 0) {
181195
attached = true;
182196
} else {
197+
if (lteppp_get_state() == E_LTE_PPP) {
198+
lte_pause_ppp();
199+
while (true) {
200+
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
201+
if (lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
202+
break;
203+
}
204+
}
205+
}
183206
lte_push_at_command("AT", LTE_RX_TIMEOUT_MIN_MS);
184207
lte_push_at_command("AT+CGATT?", LTE_RX_TIMEOUT_MIN_MS);
185208
if (((pos = strstr(modlte_rsp.data, "+CGATT")) && (strlen(pos) >= 7) && (pos[7] == '1' || pos[8] == '1'))) {
186-
if (lteppp_get_state() <= E_LTE_PPP) {
187-
lteppp_set_state(E_LTE_ATTACHED);
209+
cgatt = true;
210+
}
211+
lte_push_at_command("AT+CEREG?", LTE_RX_TIMEOUT_MIN_MS);
212+
if (!cgatt) {
213+
if (((pos = strstr(modlte_rsp.data, "+CEREG: 2,1,")) || (pos = strstr(modlte_rsp.data, "+CEREG: 2,5,")))
214+
&& (strlen(pos) >= 31) && (pos[30] == '7' || pos[30] == '9')) {
215+
attached = true;
188216
}
189-
attached = true;
190217
} else {
191-
lte_push_at_command("AT+CEREG?", LTE_RX_TIMEOUT_MIN_MS);
192-
if (((pos = strstr(modlte_rsp.data, "+CEREG: 2,1,")) || (pos = strstr(modlte_rsp.data, "+CEREG: 2,5,")))
193-
&& (strlen(pos) >= 31) && pos[30] == '7') {
194-
if (lteppp_get_state() <= E_LTE_PPP) {
195-
lteppp_set_state(E_LTE_ATTACHED);
196-
}
197-
attached = true;
198-
}
199-
lte_push_at_command("AT+CFUN?", LTE_RX_TIMEOUT_MIN_MS);
200-
if (lteppp_get_state() == E_LTE_ATTACHING) {
201-
// for some reason the modem has crashed, enabled the radios again...
202-
if (!strstr(modlte_rsp.data, "+CFUN: 1")) {
203-
lte_push_at_command("AT+CFUN=1", LTE_RX_TIMEOUT_MIN_MS);
204-
}
218+
if ((pos = strstr(modlte_rsp.data, "+CEREG: 2,1,")) || (pos = strstr(modlte_rsp.data, "+CEREG: 2,5,"))) {
219+
attached = true;
205220
} else {
206-
if (strstr(modlte_rsp.data, "+CFUN: 1")) {
207-
lteppp_set_state(E_LTE_ATTACHING);
208-
} else {
209-
lteppp_set_state(E_LTE_IDLE);
210-
}
221+
attached = false;
222+
}
223+
}
224+
lte_push_at_command("AT+CFUN?", LTE_RX_TIMEOUT_MIN_MS);
225+
if (lteppp_get_state() == E_LTE_ATTACHING) {
226+
// for some reason the modem has crashed, enabled the radios again...
227+
if (!strstr(modlte_rsp.data, "+CFUN: 1")) {
228+
lte_push_at_command("AT+CFUN=1", LTE_RX_TIMEOUT_MIN_MS);
229+
}
230+
} else {
231+
if (strstr(modlte_rsp.data, "+CFUN: 1")) {
232+
lteppp_set_state(E_LTE_ATTACHING);
233+
} else {
234+
lteppp_set_state(E_LTE_IDLE);
211235
}
212236
}
213237
}
238+
if (attached && lteppp_get_state() <= E_LTE_PPP) {
239+
lteppp_set_state(E_LTE_ATTACHED);
240+
}
241+
//printf("This is our current LTE state: %d\n", lteppp_get_state());
242+
//printf("This is check_attached returning %d\n", attached);
214243
return attached;
215244
}
216245

217246
static bool lte_check_legacy_version(void) {
218-
lte_push_at_command("ATI1", LTE_RX_TIMEOUT_MAX_MS);
219-
return strstr(modlte_rsp.data, "LR5.1.1.0-33080");
247+
if (lte_push_at_command("ATI1", LTE_RX_TIMEOUT_MAX_MS)) {
248+
return strstr(modlte_rsp.data, "LR5.1.1.0-33080");
249+
} else {
250+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "LTE modem version not read"));
251+
}
252+
return true;
220253
}
221254

222255

@@ -257,6 +290,7 @@ static void TASK_LTE_UPGRADE(void *pvParameters){
257290
#if defined(FIPY)
258291
vTaskSuspend(xLoRaTaskHndl);
259292
vTaskSuspend(xSigfoxTaskHndl);
293+
// vTaskSuspend(xMeshTaskHndl);
260294
#endif
261295
vTaskSuspend(xLTETaskHndl);
262296

@@ -305,6 +339,11 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
305339
if (!lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
306340
lte_pause_ppp();
307341
}
342+
// disable PSM if enabled by default
343+
lte_push_at_command("AT+CPSMS?", LTE_RX_TIMEOUT_MAX_MS);
344+
if (!strstr(modlte_rsp.data, "+CPSMS: 0")) {
345+
lte_push_at_command("AT+CPSMS=0", LTE_RX_TIMEOUT_MIN_MS);
346+
}
308347

309348
lte_push_at_command("AT!=\"setlpm airplane=1 enable=1\"", LTE_RX_TIMEOUT_MIN_MS);
310349
lte_push_at_command("AT+CFUN?", LTE_RX_TIMEOUT_MIN_MS);
@@ -607,11 +646,15 @@ STATIC mp_obj_t lte_suspend(mp_obj_t self_in) {
607646
}
608647
lte_check_init();
609648
if (lteppp_get_state() == E_LTE_PPP) {
649+
//printf("Pausing ppp...\n");
610650
lte_pause_ppp();
651+
//printf("Pausing ppp done...\n");
611652
lteppp_set_state(E_LTE_SUSPENDED);
612653
while (true) {
613654
mp_hal_delay_ms(LTE_RX_TIMEOUT_MIN_MS);
655+
//printf("Sending AT...\n");
614656
if (lte_push_at_command("AT", LTE_RX_TIMEOUT_MAX_MS)) {
657+
//printf("OK\n");
615658
break;
616659
}
617660
}

esp32/pycom_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.18.1.r3"
13+
#define SW_VERSION_NUMBER "1.18.1.r4"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

0 commit comments

Comments
 (0)