Merge branch 'rolling' into 534-influxdb

This commit is contained in:
jomjol
2022-04-15 14:39:09 +02:00
committed by GitHub
16 changed files with 121 additions and 48 deletions

View File

@@ -25,7 +25,8 @@ void ClassFlowMQTT::SetInitialParameter(void)
OldValue = "";
flowpostprocessing = NULL;
user = "";
password = "";
password = "";
SetRetainFlag = 0;
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
@@ -99,6 +100,12 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->uri = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "SETRETAINFLAG") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
SetRetainFlag = 1;
}
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
@@ -118,7 +125,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
mainerrortopic = maintopic + "/connection";
printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str());
MQTTInit(uri, clientname, user, password, mainerrortopic, 60);
MQTTPublish(mainerrortopic, "connected");
MQTTPublish(mainerrortopic, "connected", SetRetainFlag);
MQTTenable = true;
}
@@ -150,17 +157,17 @@ bool ClassFlowMQTT::doFlow(string zwtime)
zw = maintopic + "/" + "uptime";
char uptimeStr[11];
sprintf(uptimeStr, "%ld", (long)getUpTime());
MQTTPublish(zw, uptimeStr);
MQTTPublish(zw, uptimeStr, SetRetainFlag);
zw = maintopic + "/" + "freeMem";
char freeheapmem[11];
sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
MQTTPublish(zw, freeheapmem);
MQTTPublish(zw, freeheapmem, SetRetainFlag);
zw = maintopic + "/" + "wifiRSSI";
char rssi[11];
sprintf(rssi, "%d", get_WIFI_RSSI());
MQTTPublish(zw, rssi);
MQTTPublish(zw, rssi, SetRetainFlag);
if (flowpostprocessing)
@@ -183,23 +190,23 @@ bool ClassFlowMQTT::doFlow(string zwtime)
zw = namenumber + "value";
if (result.length() > 0)
MQTTPublish(zw, result);
MQTTPublish(zw, result, SetRetainFlag);
zw = namenumber + "error";
if (resulterror.length() > 0)
MQTTPublish(zw, resulterror, 1);
MQTTPublish(zw, resulterror, SetRetainFlag);
zw = namenumber + "rate";
if (resultrate.length() > 0)
MQTTPublish(zw, resultrate);
MQTTPublish(zw, resultrate, SetRetainFlag);
zw = namenumber + "raw";
if (resultraw.length() > 0)
MQTTPublish(zw, resultraw);
MQTTPublish(zw, resultraw, SetRetainFlag);
zw = namenumber + "timestamp";
if (resulttimestamp.length() > 0)
MQTTPublish(zw, resulttimestamp);
MQTTPublish(zw, resulttimestamp, SetRetainFlag);
std::string json = "";
@@ -218,7 +225,7 @@ bool ClassFlowMQTT::doFlow(string zwtime)
json += ",\"timestamp\":\""+resulttimestamp+"\"}";
zw = namenumber + "json";
MQTTPublish(zw, json);
MQTTPublish(zw, json, SetRetainFlag);
}
}
else
@@ -234,7 +241,7 @@ bool ClassFlowMQTT::doFlow(string zwtime)
result = result + "\t" + zw;
}
}
MQTTPublish(topic, result);
MQTTPublish(topic, result, SetRetainFlag);
}
OldValue = result;

View File

@@ -13,6 +13,7 @@ protected:
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
std::string user, password;
int SetRetainFlag;
bool MQTTenable;
std::string maintopic, mainerrortopic;

View File

@@ -10,7 +10,7 @@ void MQTTdestroy();
//void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = "");
void MQTTPublish(std::string _key, std::string _content, int retained_flag = 0);
void MQTTPublish(std::string _key, std::string _content, int retained_flag = 1); // retained Flag as Standart
bool MQTTisConnected();

View File

@@ -151,8 +151,24 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna
if ((_ipadr != NULL) && (_gw != NULL) && (_netmask != NULL))
{
/*
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_ip_info_t ip_info;
int a, b, c, d;
strinttoip4(_ipadr, a, b, c, d);
IP4_ADDR(&ip_info.ip, a, b, c, d);
strinttoip4(_gw, a, b, c, d);
IP4_ADDR(&ip_info.gw, a, b, c, d);
strinttoip4(_netmask, a, b, c, d);
IP4_ADDR(&ip_info.netmask, a, b, c, d);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
*/
ESP_LOGI(TAG, "set IP %s, GW %s, Netmask %s manual", _ipadr, _gw, _netmask);
esp_netif_dhcpc_stop(my_sta);
esp_netif_ip_info_t ip_info;
int a, b, c, d;
strinttoip4(_ipadr, a, b, c, d);
@@ -168,6 +184,22 @@ void wifi_init_sta(const char *_ssid, const char *_password, const char *_hostna
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
if ((_ipadr != NULL) && (_gw != NULL) && (_netmask != NULL))
{
if (_dns == NULL)
_dns = _gw;
ESP_LOGI(TAG, "set DNS manual");
esp_netif_dns_info_t dns_info;
ip4_addr_t ip;
ip.addr = esp_ip4addr_aton(_dns);
ip_addr_set_ip4_u32(&dns_info.ip, ip.addr);
ESP_ERROR_CHECK(esp_netif_set_dns_info(my_sta, ESP_NETIF_DNS_MAIN, &dns_info));
}
esp_event_handler_instance_t instance_any_id;
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,