Skip to content

Commit 21d07be

Browse files
committed
Update 20201013
1 parent 04f69f0 commit 21d07be

File tree

10 files changed

+36
-11
lines changed

10 files changed

+36
-11
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
2727

2828

2929

30-
##### Rolling - (2020-10-04)
30+
##### Rolling - (2020-10-13)
31+
32+
* Implementation of user and password for MQTT Authentication (see `config.ini`)
33+
34+
2020-10-04
3135

3236
* First simple MQTT Client - to be configured in `config.ini` (see example)
3337

code/lib/jomjol_flowcontroll/ClassFlowMQTT.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ ClassFlowMQTT::ClassFlowMQTT()
1414
topic = "";
1515
clientname = "watermeter";
1616
OldValue = "";
17-
flowpostprocessing = NULL;
17+
flowpostprocessing = NULL;
18+
user = "";
19+
password = "";
1820
}
1921

2022
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
@@ -24,6 +26,8 @@ ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
2426
clientname = "watermeter";
2527
OldValue = "";
2628
flowpostprocessing = NULL;
29+
user = "";
30+
password = "";
2731

2832
ListFlowControll = lfc;
2933

@@ -53,6 +57,14 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
5357
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
5458
{
5559
zerlegt = this->ZerlegeZeile(aktparamgraph);
60+
if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1))
61+
{
62+
this->user = zerlegt[1];
63+
}
64+
if ((toUpper(zerlegt[0]) == "PASSWORD") && (zerlegt.size() > 1))
65+
{
66+
this->password = zerlegt[1];
67+
}
5668
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
5769
{
5870
this->uri = zerlegt[1];
@@ -70,7 +82,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
7082

7183
if ((uri.length() > 0) && (topic.length() > 0))
7284
{
73-
MQTTInit(uri, clientname);
85+
MQTTInit(uri, clientname, user, password);
7486
}
7587

7688
return true;

code/lib/jomjol_flowcontroll/ClassFlowMQTT.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class ClassFlowMQTT :
1111
protected:
1212
std::string uri, topic, clientname;
1313
std::string OldValue;
14-
ClassFlowPostProcessing* flowpostprocessing;
14+
ClassFlowPostProcessing* flowpostprocessing;
15+
std::string user, password;
1516

1617

1718
public:

code/lib/jomjol_mqtt/interface_mqtt.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
6464
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
6565
}
6666

67-
void MQTTInit(std::string _mqttURI, std::string _clientid){
67+
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password){
6868
esp_mqtt_client_config_t mqtt_cfg = {
6969
.uri = _mqttURI.c_str(),
7070
.client_id = _clientid.c_str(),
7171
};
7272

73+
if (_user.length() && _password.length()){
74+
mqtt_cfg.username = _user.c_str();
75+
mqtt_cfg.password = _password.c_str();
76+
printf("Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
77+
};
78+
7379
client = esp_mqtt_client_init(&mqtt_cfg);
7480
esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client);
7581
esp_mqtt_client_start(client);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include <string>
22

3-
void MQTTInit(std::string _mqttURI, std::string _clientid);
3+
void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user = "", std::string _password = "");
44
void MQTTPublish(std::string _key, std::string _content);

code/src/version.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const char* GIT_REV="f8e8c75";
1+
const char* GIT_REV="04f69f0";
22
const char* GIT_TAG="";
33
const char* GIT_BRANCH="rolling";
4-
const char* BUILD_TIME="2020-10-04 08:06";
4+
const char* BUILD_TIME="2020-10-13 20:10";

code/version.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const char* GIT_REV="f8e8c75";
1+
const char* GIT_REV="04f69f0";
22
const char* GIT_TAG="";
33
const char* GIT_BRANCH="rolling";
4-
const char* BUILD_TIME="2020-10-04 08:06";
4+
const char* BUILD_TIME="2020-10-13 20:10";

firmware/bootloader.bin

0 Bytes
Binary file not shown.

firmware/firmware.bin

576 Bytes
Binary file not shown.

sd-card/config/config.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ CheckDigitIncreaseConsistency = False
4040

4141
;[MQTT]
4242
;Uri = mqtt://IP-MQTT-SERVER:1883
43-
;Topic = /watermeter/readout
43+
;Topic = watermeter/readout
4444
;ClientID = wasser
45+
;user = USERNAME
46+
;password = PASSWORD
4547

4648
[AutoTimer]
4749
AutoStart= True

0 commit comments

Comments
 (0)