mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 12:36:52 +03:00
Update 20201013
This commit is contained in:
@@ -27,7 +27,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### Rolling - (2020-10-04)
|
##### Rolling - (2020-10-13)
|
||||||
|
|
||||||
|
* Implementation of user and password for MQTT Authentication (see `config.ini`)
|
||||||
|
|
||||||
|
2020-10-04
|
||||||
|
|
||||||
* First simple MQTT Client - to be configured in `config.ini` (see example)
|
* First simple MQTT Client - to be configured in `config.ini` (see example)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ ClassFlowMQTT::ClassFlowMQTT()
|
|||||||
clientname = "watermeter";
|
clientname = "watermeter";
|
||||||
OldValue = "";
|
OldValue = "";
|
||||||
flowpostprocessing = NULL;
|
flowpostprocessing = NULL;
|
||||||
|
user = "";
|
||||||
|
password = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
|
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
|
||||||
@@ -24,6 +26,8 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
|
|||||||
clientname = "watermeter";
|
clientname = "watermeter";
|
||||||
OldValue = "";
|
OldValue = "";
|
||||||
flowpostprocessing = NULL;
|
flowpostprocessing = NULL;
|
||||||
|
user = "";
|
||||||
|
password = "";
|
||||||
|
|
||||||
ListFlowControll = lfc;
|
ListFlowControll = lfc;
|
||||||
|
|
||||||
@@ -53,6 +57,14 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|||||||
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
||||||
{
|
{
|
||||||
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
zerlegt = this->ZerlegeZeile(aktparamgraph);
|
||||||
|
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
|
||||||
|
{
|
||||||
|
this->user = zerlegt[1];
|
||||||
|
}
|
||||||
|
if ((toUpper(zerlegt[0]) == "PASSWORD") && (zerlegt.size() > 1))
|
||||||
|
{
|
||||||
|
this->password = zerlegt[1];
|
||||||
|
}
|
||||||
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
|
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
|
||||||
{
|
{
|
||||||
this->uri = zerlegt[1];
|
this->uri = zerlegt[1];
|
||||||
@@ -70,7 +82,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|||||||
|
|
||||||
if ((uri.length() > 0) && (topic.length() > 0))
|
if ((uri.length() > 0) && (topic.length() > 0))
|
||||||
{
|
{
|
||||||
MQTTInit(uri, clientname);
|
MQTTInit(uri, clientname, user, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ protected:
|
|||||||
std::string uri, topic, clientname;
|
std::string uri, topic, clientname;
|
||||||
std::string OldValue;
|
std::string OldValue;
|
||||||
ClassFlowPostProcessing* flowpostprocessing;
|
ClassFlowPostProcessing* flowpostprocessing;
|
||||||
|
std::string user, password;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -64,12 +64,18 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
|
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQTTInit(std::string _mqttURI, std::string _clientid){
|
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password){
|
||||||
esp_mqtt_client_config_t mqtt_cfg = {
|
esp_mqtt_client_config_t mqtt_cfg = {
|
||||||
.uri = _mqttURI.c_str(),
|
.uri = _mqttURI.c_str(),
|
||||||
.client_id = _clientid.c_str(),
|
.client_id = _clientid.c_str(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (_user.length() && _password.length()){
|
||||||
|
mqtt_cfg.username = _user.c_str();
|
||||||
|
mqtt_cfg.password = _password.c_str();
|
||||||
|
printf("Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
|
||||||
|
};
|
||||||
|
|
||||||
client = esp_mqtt_client_init(&mqtt_cfg);
|
client = esp_mqtt_client_init(&mqtt_cfg);
|
||||||
esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
|
esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
|
||||||
esp_mqtt_client_start(client);
|
esp_mqtt_client_start(client);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void MQTTInit(std::string _mqttURI, std::string _clientid);
|
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = "");
|
||||||
void MQTTPublish(std::string _key, std::string _content);
|
void MQTTPublish(std::string _key, std::string _content);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="f8e8c75";
|
const char* GIT_REV="04f69f0";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling";
|
const char* GIT_BRANCH="rolling";
|
||||||
const char* BUILD_TIME="2020-10-04 08:06";
|
const char* BUILD_TIME="2020-10-13 20:10";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const char* GIT_REV="f8e8c75";
|
const char* GIT_REV="04f69f0";
|
||||||
const char* GIT_TAG="";
|
const char* GIT_TAG="";
|
||||||
const char* GIT_BRANCH="rolling";
|
const char* GIT_BRANCH="rolling";
|
||||||
const char* BUILD_TIME="2020-10-04 08:06";
|
const char* BUILD_TIME="2020-10-13 20:10";
|
||||||
Binary file not shown.
Binary file not shown.
@@ -40,8 +40,10 @@ CheckDigitIncreaseConsistency = False
|
|||||||
|
|
||||||
;[MQTT]
|
;[MQTT]
|
||||||
;Uri = mqtt://IP-MQTT-SERVER:1883
|
;Uri = mqtt://IP-MQTT-SERVER:1883
|
||||||
;Topic = /watermeter/readout
|
;Topic = watermeter/readout
|
||||||
;ClientID = wasser
|
;ClientID = wasser
|
||||||
|
;user = USERNAME
|
||||||
|
;password = PASSWORD
|
||||||
|
|
||||||
[AutoTimer]
|
[AutoTimer]
|
||||||
AutoStart= True
|
AutoStart= True
|
||||||
|
|||||||
Reference in New Issue
Block a user