added modem to mqtt bridge service
This commit is contained in:
parent
60f36fbf04
commit
0603610229
4
Kconfig
4
Kconfig
|
|
@ -563,6 +563,10 @@ menu "WebGUIApp"
|
||||||
|
|
||||||
if WEBGUIAPP_GPRS_ENABLE
|
if WEBGUIAPP_GPRS_ENABLE
|
||||||
|
|
||||||
|
config WEBGUIAPP_MQTT_AT_BRIDGE
|
||||||
|
bool "Enable modem to MQTT AT commantd bridge"
|
||||||
|
default n
|
||||||
|
|
||||||
config WEBGUIAPP_GPRS_ON
|
config WEBGUIAPP_GPRS_ON
|
||||||
bool "Default GPRS switched on"
|
bool "Default GPRS switched on"
|
||||||
default n
|
default n
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,6 @@ void ComposeTopic(char *topic, int idx, char *service_name, char *direct);
|
||||||
void SystemDataHandler(char *data, uint32_t len, int idx);
|
void SystemDataHandler(char *data, uint32_t len, int idx);
|
||||||
|
|
||||||
mqtt_app_err_t PublicTestMQTT(int idx);
|
mqtt_app_err_t PublicTestMQTT(int idx);
|
||||||
esp_err_t ExternalServiceMQTTSend(char *data, int len, int idx);
|
esp_err_t ExternalServiceMQTTSend(char *servname, char *data, int len, int idx);
|
||||||
|
|
||||||
#endif /* MAIN_INCLUDE_MQTT_H_ */
|
#endif /* MAIN_INCLUDE_MQTT_H_ */
|
||||||
|
|
|
||||||
28
src/MQTT.c
28
src/MQTT.c
|
|
@ -29,6 +29,7 @@
|
||||||
#define TAG "MQTT"
|
#define TAG "MQTT"
|
||||||
#define SERVICE_NAME "SYSTEM" // Dedicated service name
|
#define SERVICE_NAME "SYSTEM" // Dedicated service name
|
||||||
#define EXTERNAL_SERVICE_NAME "RS485"
|
#define EXTERNAL_SERVICE_NAME "RS485"
|
||||||
|
#define MODEM_AT_SERVICE_NAME "ATMODEM"
|
||||||
#define UPLINK_SUBTOPIC "UPLINK" // Device publish to this topic
|
#define UPLINK_SUBTOPIC "UPLINK" // Device publish to this topic
|
||||||
#define DOWNLINK_SUBTOPIC "DWLINK" // Device listen from this topic
|
#define DOWNLINK_SUBTOPIC "DWLINK" // Device listen from this topic
|
||||||
|
|
||||||
|
|
@ -138,7 +139,7 @@ esp_err_t SysServiceMQTTSend(char *data, int len, int idx)
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t ExternalServiceMQTTSend(char *data, int len, int idx)
|
esp_err_t ExternalServiceMQTTSend(char *servname, char *data, int len, int idx)
|
||||||
{
|
{
|
||||||
if (GetMQTTHandlesPool(idx)->mqtt_queue == NULL)
|
if (GetMQTTHandlesPool(idx)->mqtt_queue == NULL)
|
||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
|
|
@ -147,7 +148,7 @@ esp_err_t ExternalServiceMQTTSend(char *data, int len, int idx)
|
||||||
{
|
{
|
||||||
memcpy(buf, data, len);
|
memcpy(buf, data, len);
|
||||||
MQTT_DATA_SEND_STRUCT DSS = { 0 };
|
MQTT_DATA_SEND_STRUCT DSS = { 0 };
|
||||||
ComposeTopic(DSS.topic, idx, EXTERNAL_SERVICE_NAME, UPLINK_SUBTOPIC);
|
ComposeTopic(DSS.topic, idx, servname, UPLINK_SUBTOPIC);
|
||||||
DSS.raw_data_ptr = buf;
|
DSS.raw_data_ptr = buf;
|
||||||
DSS.data_length = len;
|
DSS.data_length = len;
|
||||||
if (xQueueSend(GetMQTTHandlesPool(idx)->mqtt_queue, &DSS, pdMS_TO_TICKS(0)) == pdPASS)
|
if (xQueueSend(GetMQTTHandlesPool(idx)->mqtt_queue, &DSS, pdMS_TO_TICKS(0)) == pdPASS)
|
||||||
|
|
@ -162,6 +163,8 @@ esp_err_t ExternalServiceMQTTSend(char *data, int len, int idx)
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define MAX_ERROR_JSON 256
|
#define MAX_ERROR_JSON 256
|
||||||
mqtt_app_err_t PublicTestMQTT(int idx)
|
mqtt_app_err_t PublicTestMQTT(int idx)
|
||||||
{
|
{
|
||||||
|
|
@ -216,7 +219,7 @@ static void mqtt_system_event_handler(int idx, void *handler_args, esp_event_bas
|
||||||
ComposeTopic(topic, idx, SERVICE_NAME, DOWNLINK_SUBTOPIC);
|
ComposeTopic(topic, idx, SERVICE_NAME, DOWNLINK_SUBTOPIC);
|
||||||
msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0);
|
msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0);
|
||||||
#if MQTT_DEBUG_MODE > 0
|
#if MQTT_DEBUG_MODE > 0
|
||||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||||
ESP_LOGI(TAG, "Subscribe to %s", topic);
|
ESP_LOGI(TAG, "Subscribe to %s", topic);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_WEBGUIAPP_UART_TRANSPORT_ENABLE
|
#ifdef CONFIG_WEBGUIAPP_UART_TRANSPORT_ENABLE
|
||||||
|
|
@ -231,6 +234,17 @@ msg_id = esp_mqtt_client_subscribe(client, (char*) topic, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#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;
|
break;
|
||||||
case MQTT_EVENT_DISCONNECTED:
|
case MQTT_EVENT_DISCONNECTED:
|
||||||
|
|
||||||
|
|
@ -304,6 +318,14 @@ 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);
|
||||||
|
if (!memcmp(topic, event->topic, event->topic_len))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_ERROR:
|
case MQTT_EVENT_ERROR:
|
||||||
ESP_LOGE(TAG, "MQTT_EVENT_ERROR, client %d", idx);
|
ESP_LOGE(TAG, "MQTT_EVENT_ERROR, client %d", idx);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user