update webguiapp component, in root project implemented example of mqtt event handler
This commit is contained in:
parent
c1e637bcb3
commit
47d40b321f
|
|
@ -1 +1 @@
|
||||||
Subproject commit 935854966712986baf3eab6d5b8bb57e5e1d63f6
|
Subproject commit 8914422aac9c95e2373f21270be24b70afc67ad3
|
||||||
|
|
@ -22,10 +22,46 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MQTT.h"
|
#include "MQTT.h"
|
||||||
|
#include "SystemConfiguration.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#define TAG "MQTTCustom"
|
||||||
|
|
||||||
void UserDataHndlr(char *data, uint32_t len, int idx)
|
|
||||||
|
void UserMQTTEventHndlr(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
|
||||||
{
|
{
|
||||||
// Here do something with incoming mqtt data
|
esp_mqtt_event_handle_t event = event_data;
|
||||||
|
esp_mqtt_client_handle_t client = event->client;
|
||||||
|
mqtt_client_t *ctx = (mqtt_client_t*) event->user_context;
|
||||||
|
int msg_id;
|
||||||
|
char topic[CONFIG_WEBGUIAPP_MQTT_MAX_TOPIC_LENGTH];
|
||||||
|
switch ((esp_mqtt_event_id_t) event_id)
|
||||||
|
{
|
||||||
|
case MQTT_EVENT_CONNECTED:
|
||||||
|
ComposeTopic(topic,
|
||||||
|
GetSysConf()->mqttStation[ctx->mqtt_index].RootTopic,
|
||||||
|
"DOWNLINK",
|
||||||
|
GetSysConf()->mqttStation[ctx->mqtt_index].ClientID,
|
||||||
|
"USER");
|
||||||
|
//Subscribe to the service called "USER"
|
||||||
|
msg_id = esp_mqtt_client_subscribe(client, (const char*) topic, 0);
|
||||||
|
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case MQTT_EVENT_DATA:
|
||||||
|
ComposeTopic(topic,
|
||||||
|
GetSysConf()->mqttStation[ctx->mqtt_index].RootTopic,
|
||||||
|
"DOWNLINK",
|
||||||
|
GetSysConf()->mqttStation[ctx->mqtt_index].ClientID,
|
||||||
|
"USER");
|
||||||
|
if (!memcmp(topic, event->topic, event->topic_len))
|
||||||
|
{
|
||||||
|
//Here data for service called "USER"
|
||||||
|
ESP_LOGI(TAG, "USER data handler on client %d", ctx->mqtt_index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ESP_LOGI(TAG, "Other event id:%d", event->event_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,14 @@
|
||||||
|
|
||||||
int HTTPPrintCustom(httpd_req_t *req, char *buf, char *var);
|
int HTTPPrintCustom(httpd_req_t *req, char *buf, char *var);
|
||||||
HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData);
|
HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData);
|
||||||
void UserDataHndlr(char *data, uint32_t len, int idx);
|
void UserMQTTEventHndlr(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
WebGuiAppInit();
|
|
||||||
regHTTPPrintCustom(&HTTPPrintCustom);
|
regHTTPPrintCustom(&HTTPPrintCustom);
|
||||||
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
||||||
regUserDataHandler(&UserDataHndlr);
|
regUserEventHandler(&UserMQTTEventHndlr);
|
||||||
|
WebGuiAppInit();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
20
sdkconfig
20
sdkconfig
|
|
@ -1215,7 +1215,7 @@ CONFIG_WPA_MBEDTLS_CRYPTO=y
|
||||||
#
|
#
|
||||||
# WebGuiApp configuration
|
# WebGuiApp configuration
|
||||||
#
|
#
|
||||||
CONFIG_WEBGUIAPP_PROJECT_VER="0.0.0.0001"
|
CONFIG_WEBGUIAPP_PROJECT_VER="0.0.0.0002"
|
||||||
CONFIG_WEBGUIAPP_HOSTNAME="DEVICE_HOSTNAME"
|
CONFIG_WEBGUIAPP_HOSTNAME="DEVICE_HOSTNAME"
|
||||||
CONFIG_WEBGUIAPP_USERNAME="user"
|
CONFIG_WEBGUIAPP_USERNAME="user"
|
||||||
CONFIG_WEBGUIAPP_USERPASS="password"
|
CONFIG_WEBGUIAPP_USERPASS="password"
|
||||||
|
|
@ -1290,14 +1290,16 @@ CONFIG_ETH_SPI_PHY_ADDR0=1
|
||||||
# MQTT settings
|
# MQTT settings
|
||||||
#
|
#
|
||||||
CONFIG_WEBGUIAPP_MQTT_ENABLE=y
|
CONFIG_WEBGUIAPP_MQTT_ENABLE=y
|
||||||
CONFIG_MQTT_CLIENTS_NUM=1
|
CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM=2
|
||||||
CONFIG_MQTT_ON=y
|
CONFIG_WEBGUIAPP_MQTT_ON=y
|
||||||
CONFIG_MQTT_SERVER_URL="iotronic.cloud"
|
CONFIG_WEBGUIAPP_MQTT_MAX_TOPIC_LENGTH=64
|
||||||
CONFIG_MQTT_SERVER_PORT=1883
|
CONFIG_WEBGUIAPP_MQTT_SERVER_URL="myfirstmqttserver.com"
|
||||||
CONFIG_MQTT_CLIENT_ID_1="DEVID1"
|
CONFIG_WEBGUIAPP_MQTT_SERVER_PORT=1883
|
||||||
CONFIG_MQTT_ROOT_TOPIC="CHARGEPOINT"
|
CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_1="DEVID1"
|
||||||
CONFIG_MQTT_USERNAME="chargepoint"
|
CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_2="DEVID2"
|
||||||
CONFIG_MQTT_PASSWORD="chargepoint"
|
CONFIG_WEBGUIAPP_MQTT_ROOT_TOPIC="ROOTTOPIC"
|
||||||
|
CONFIG_WEBGUIAPP_MQTT_USERNAME="username"
|
||||||
|
CONFIG_WEBGUIAPP_MQTT_PASSWORD="password"
|
||||||
# end of MQTT settings
|
# end of MQTT settings
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -1290,12 +1290,11 @@ CONFIG_ETH_SPI_PHY_ADDR0=1
|
||||||
# MQTT settings
|
# MQTT settings
|
||||||
#
|
#
|
||||||
CONFIG_WEBGUIAPP_MQTT_ENABLE=y
|
CONFIG_WEBGUIAPP_MQTT_ENABLE=y
|
||||||
CONFIG_MQTT_CLIENTS_NUM=2
|
CONFIG_MQTT_CLIENTS_NUM=1
|
||||||
CONFIG_MQTT_ON=y
|
CONFIG_MQTT_ON=y
|
||||||
CONFIG_MQTT_SERVER_URL="iotronic.cloud"
|
CONFIG_MQTT_SERVER_URL="iotronic.cloud"
|
||||||
CONFIG_MQTT_SERVER_PORT=1883
|
CONFIG_MQTT_SERVER_PORT=1883
|
||||||
CONFIG_MQTT_CLIENT_ID_1="DEVID1"
|
CONFIG_MQTT_CLIENT_ID_1="DEVID1"
|
||||||
CONFIG_MQTT_CLIENT_ID_2="DEVID2"
|
|
||||||
CONFIG_MQTT_ROOT_TOPIC="CHARGEPOINT"
|
CONFIG_MQTT_ROOT_TOPIC="CHARGEPOINT"
|
||||||
CONFIG_MQTT_USERNAME="chargepoint"
|
CONFIG_MQTT_USERNAME="chargepoint"
|
||||||
CONFIG_MQTT_PASSWORD="chargepoint"
|
CONFIG_MQTT_PASSWORD="chargepoint"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user