diff --git a/Kconfig b/Kconfig index 316e3d9..9d7cdd6 100644 --- a/Kconfig +++ b/Kconfig @@ -563,8 +563,8 @@ menu "WebGUIApp" if WEBGUIAPP_GPRS_ENABLE - config WEBGUIAPP_MQTT_AT_BRIDGE - bool "Enable modem to MQTT AT commantd bridge" + config WEBGUIAPP_MODEM_AT_ACCESS + bool "Enable modem AT commands access" default n config WEBGUIAPP_GPRS_ON diff --git a/include/NetTransport.h b/include/NetTransport.h index 94585ab..59ea727 100644 --- a/include/NetTransport.h +++ b/include/NetTransport.h @@ -80,6 +80,7 @@ void PPPModemStart(void); int PPPModemGetRSSI(void); void ModemSendSMS(void); void ModemSendAT(char *cmd, char *resp, int timeout); +void ModemSetATTimeout(int timeout); void MQTTRun(void); diff --git a/src/GSMTransport.c b/src/GSMTransport.c index d7de4d0..c9b7b33 100644 --- a/src/GSMTransport.c +++ b/src/GSMTransport.c @@ -42,6 +42,7 @@ static bool isPPPinitializing = false; #endif static bool isPPPConn = false; +static int attimeout = 300; TaskHandle_t initTaskhandle; #define PPP_MODEM_TIMEOUT 40 @@ -302,13 +303,17 @@ int PPPModemGetRSSI(void) { int rssi = -1, ber; esp_modem_get_signal_quality(dce, &rssi, &ber); - //ESP_LOGW(TAG, "Signal %d, ber %d", rssi, ber); return rssi; } +void ModemSetATTimeout(int timeout) +{ + attimeout = timeout; +} + void ModemSendAT(char *cmd, char *resp, int timeout) { - esp_modem_at(dce, cmd, resp, timeout); + esp_modem_at(dce, cmd, resp, attimeout); ESP_LOGI(TAG, "Command:%s", cmd); ESP_LOGW(TAG, "%s", resp); } diff --git a/src/MQTT.c b/src/MQTT.c index 1080e28..847a073 100644 --- a/src/MQTT.c +++ b/src/MQTT.c @@ -29,7 +29,6 @@ #define TAG "MQTT" #define SERVICE_NAME "SYSTEM" // Dedicated service name #define EXTERNAL_SERVICE_NAME "RS485" -#define MODEM_AT_SERVICE_NAME "ATMODEM" #define UPLINK_SUBTOPIC "UPLINK" // Device publish to this topic #define DOWNLINK_SUBTOPIC "DWLINK" // Device listen from this topic @@ -234,17 +233,6 @@ msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0); #endif } #endif - -#ifdef CONFIG_WEBGUIAPP_MQTT_AT_BRIDGE - { - ComposeTopic(topic, idx, MODEM_AT_SERVICE_NAME, DOWNLINK_SUBTOPIC); -msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0); -#if MQTT_DEBUG_MODE > 0 - ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); - ESP_LOGI(TAG, "Subscribe to %s", topic); -#endif - } -#endif break; case MQTT_EVENT_DISCONNECTED: @@ -317,15 +305,6 @@ msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0); } } #endif - -#ifdef CONFIG_WEBGUIAPP_MQTT_AT_BRIDGE - ComposeTopic(topic, idx, MODEM_AT_SERVICE_NAME, DOWNLINK_SUBTOPIC); - if (!memcmp(topic, event->topic, event->topic_len)) - { - - } -#endif - break; case MQTT_EVENT_ERROR: ESP_LOGE(TAG, "MQTT_EVENT_ERROR, client %d", idx); diff --git a/src/RestApiHandler.c b/src/RestApiHandler.c index b9d552b..9c0351d 100644 --- a/src/RestApiHandler.c +++ b/src/RestApiHandler.c @@ -232,6 +232,21 @@ void funct_gsm_imsi(char *argres, int rw) { snprintf(argres, VAR_MAX_VALUE_LENGTH, "\"%s\"", GetPPPModemInfo()->imsi); } +#ifdef CONFIG_WEBGUIAPP_MODEM_AT_ACCESS +void funct_gsm_at(char *argres, int rw) +{ + ModemSendAT(argres, argres, 0); +} +void funct_gsm_at_timeout(char *argres, int rw) +{ + ModemSetATTimeout(atoi(argres)); + snprintf(argres, VAR_MAX_VALUE_LENGTH, "\"DONE\""); +} +#endif +void funct_gsm_rssi(char *argres, int rw) +{ + snprintf(argres, VAR_MAX_VALUE_LENGTH, "%d", PPPModemGetRSSI()); +} #endif @@ -489,6 +504,11 @@ const rest_var_t SystemVariables[] = { 0, "gsm_dns2", &SysConfig.gsmSettings.DNSAddr2, VAR_IPADDR, RW, 0, 0 }, { 0, "gsm_dns3", &SysConfig.gsmSettings.DNSAddr3, VAR_IPADDR, RW, 0, 0 }, { 0, "gsm_stat", &funct_gsm_stat, VAR_FUNCT, R, 0, 0 }, +#ifdef CONFIG_WEBGUIAPP_MODEM_AT_ACCESS + { 0, "gsm_at_timeout", &funct_gsm_at_timeout, VAR_FUNCT, R, 0, 0 }, + { 0, "gsm_at", &funct_gsm_at, VAR_FUNCT, R, 0, 0 }, +#endif + { 0, "gsm_rssi", &funct_gsm_rssi, VAR_FUNCT, R, 0, 0 }, { 0, "gsm_visible", (bool*) (&VAR_TRUE), VAR_BOOL, R, 0, 1 }, #else { 0, "gsm_visible", (bool*) (&VAR_FALSE), VAR_BOOL, R, 0, 1 },