reworked topic structure added GROUP subtopic

This commit is contained in:
Bogdan Pilyugin 2022-09-29 14:16:25 +02:00
parent cce7f193f6
commit eaf9b47a8e
4 changed files with 86 additions and 93 deletions

View File

@ -43,22 +43,24 @@
<form name="conf2" method="post"> <form name="conf2" method="post">
<div class="mlhdr">MQTT</div> <div class="mlhdr">MQTT</div>
<table class='cntr'> <table class='cntr'>
<script>PrintCheckBox('Включить MQTT 1','mqttenb1','~mqtten1~',null); <script>PrintCheckBox('Enable MQTT 1','mqen1','~mqen1~',null);
PrintTextInput('URL шлюза сообщений','cld1','~ipcld1~',3,31); PrintTextInput('MQTT broker URL','mqurl1','~mqurl1~',3,31);
PrintInt('Порт шлюза сообщений','mprt1','~mport1~',1000,65534); PrintInt('MQTT broker port','mqport1','~mqport1~',1000,65534);
PrintTextInput('ID станции','idd1','~idcld1~',3,31); PrintTextInput('Global system name','mqsys1','~mqsys1~',3,31);
PrintTextInput('Корневая тема','top1','~topic1~',3,31); PrintTextInput('Group name','mqgrp1','~mqgrp1~',3,31);
PrintTextInput('Логин','clnm1','~clname1~',3,31); PrintTextInput('Device ID prefix','mqid1','~mqid1~',3,31);
PrintTextInput('Пароль','clps1','~clpass1~',3,31); PrintTextInput('Login','mqname1','~mqname1~',3,31);
PrintTextInput('Password','mqpass1','~mqpass1~',3,31);
PrintSep(); PrintSep();
if(~ifc_mq2~){ if(~ifc_mq2~){
PrintCheckBox('Включить MQTT 2','mqttenb2','~mqtten2~',null); PrintCheckBox('Enable MQTT 2','mqen2','~mqen2~',null);
PrintTextInput('URL шлюза сообщений','cld2','~ipcld2~',3,31); PrintTextInput('MQTT broker URL','mqurl2','~mqurl2~',3,31);
PrintInt('Порт шлюза сообщений','mprt2','~mport2~',1000,65534); PrintInt('MQTT broker port','mqport2','~mqport2~',1000,65534);
PrintTextInput('ID станции','idd2','~idcld2~',3,31); PrintTextInput('Global system name','mqsys2','~mqsys2~',3,31);
PrintTextInput('Корневая тема','top2','~topic2~',3,31); PrintTextInput('Group name','mqgrp2','~mqgrp2~',3,31);
PrintTextInput('Логин','clnm2','~clname2~',3,31); PrintTextInput('Device ID prefix','mqid2','~mqid2~',3,31);
PrintTextInput('Пароль','clps2','~clpass2~',3,31);}</script> PrintTextInput('Login','mqname2','~mqname2~',3,31);
PrintTextInput('Password','mqpass2','~mqpass2~',3,31);}</script>
</table> </table>
<script>PrintSaveFail('~status_fail~'); <script>PrintSaveFail('~status_fail~');
PrintSaveBtn('mqtt'); PrintApplyBtn('mqtt')</script> PrintSaveBtn('mqtt'); PrintApplyBtn('mqtt')</script>

@ -1 +1 @@
Subproject commit f9576486d104b0e84bedb6f0a7f7c2913548cb73 Subproject commit a813d33168458e4d0492f72b1c1e679dcbe1e084

View File

@ -32,11 +32,7 @@ esp_err_t UserMQTTSendExample(int idx)
{ {
memcpy(buf, resp, strlen(resp)); memcpy(buf, resp, strlen(resp));
DATA_SEND_STRUCT DSS; DATA_SEND_STRUCT DSS;
ComposeTopic(DSS.topic, ComposeTopic(DSS.topic, idx, "USER", "UPLINK");
GetSysConf()->mqttStation[idx].RootTopic,
"UPLINK",
GetSysConf()->mqttStation[idx].ClientID,
"USER");
DSS.raw_data_ptr = buf; DSS.raw_data_ptr = buf;
DSS.data_length = strlen(resp); DSS.data_length = strlen(resp);
if (xQueueSend(GetMQTTHandlesPool(idx)->mqtt_queue, &DSS, pdMS_TO_TICKS(1000)) == pdPASS) if (xQueueSend(GetMQTTHandlesPool(idx)->mqtt_queue, &DSS, pdMS_TO_TICKS(1000)) == pdPASS)
@ -61,22 +57,14 @@ void UserMQTTEventHndlr(void *handler_args, esp_event_base_t base, int32_t event
switch ((esp_mqtt_event_id_t) event_id) switch ((esp_mqtt_event_id_t) event_id)
{ {
case MQTT_EVENT_CONNECTED: case MQTT_EVENT_CONNECTED:
ComposeTopic(topic, ComposeTopic(topic, ctx->mqtt_index, "USER", "DWLINK");
GetSysConf()->mqttStation[ctx->mqtt_index].RootTopic,
"DWLINK",
GetSysConf()->mqttStation[ctx->mqtt_index].ClientID,
"USER");
//Subscribe to the service called "USER" //Subscribe to the service called "USER"
msg_id = esp_mqtt_client_subscribe(client, (const char*) topic, 0); msg_id = esp_mqtt_client_subscribe(client, (const char*) topic, 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id); ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
break; break;
case MQTT_EVENT_DATA: case MQTT_EVENT_DATA:
ComposeTopic(topic, ComposeTopic(topic, ctx->mqtt_index, "USER", "DWLINK");
GetSysConf()->mqttStation[ctx->mqtt_index].RootTopic,
"DWLINK",
GetSysConf()->mqttStation[ctx->mqtt_index].ClientID,
"USER");
if (!memcmp(topic, event->topic, event->topic_len)) if (!memcmp(topic, event->topic, event->topic_len))
{ {
//Here data for service called "USER" //Here data for service called "USER"

View File

@ -1232,6 +1232,8 @@ CONFIG_WEBGUIAPP_PROJECT_VER="0.0.0.0003"
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"
CONFIG_MAIN_FUNCTIONAL_BUTTON_GPIO=15
# CONFIG_DEBUG_MODE_ENABLE is not set
# #
# SPI settings # SPI settings
@ -1310,7 +1312,8 @@ CONFIG_WEBGUIAPP_MQTT_SERVER_URL="myfirstmqttserver.com"
CONFIG_WEBGUIAPP_MQTT_SERVER_PORT=1883 CONFIG_WEBGUIAPP_MQTT_SERVER_PORT=1883
CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_1="DEVID1" CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_1="DEVID1"
CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_2="DEVID2" CONFIG_WEBGUIAPP_MQTT_CLIENT_ID_2="DEVID2"
CONFIG_WEBGUIAPP_MQTT_ROOT_TOPIC="ROOTTOPIC" CONFIG_WEBGUIAPP_MQTT_SYSTEM_NAME="SYSTEMNAME"
CONFIG_WEBGUIAPP_MQTT_GROUP_NAME="GROUPNAME"
CONFIG_WEBGUIAPP_MQTT_USERNAME="username" CONFIG_WEBGUIAPP_MQTT_USERNAME="username"
CONFIG_WEBGUIAPP_MQTT_PASSWORD="password" CONFIG_WEBGUIAPP_MQTT_PASSWORD="password"
# end of MQTT settings # end of MQTT settings