refactoring

This commit is contained in:
simonox 2023-02-20 16:29:53 +01:00
parent e8938b3ae1
commit 386ae346a0
2 changed files with 5 additions and 5 deletions

View file

@ -33,8 +33,7 @@ void setup() {
Serial.setTimeout(500); Serial.setTimeout(500);
setup_energy_sensor(); setup_energy_sensor();
setup_wifi(); setup_wifi();
client.setServer(mqttServer, mqttPort); setup_mqtt();
reconnect();
} }
void setup_energy_sensor() { void setup_energy_sensor() {
@ -59,7 +58,8 @@ void setup_wifi() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
} }
void reconnect() { void setup_mqtt() {
client.setServer(mqttServer, mqttPort);
// Loop until we're reconnected // Loop until we're reconnected
while (!client.connected()) { while (!client.connected()) {
Serial.print("Attempting MQTT connection..."); Serial.print("Attempting MQTT connection...");

View file

@ -100,7 +100,7 @@ docker-compose --file software/container/docker-compose.yml up
##### Credentials ##### Credentials
To connect to your wifi and access your MQTT server you have to add this to an `environment` [header file](./02-energy-monitor-mqtt/environment.h): To connect to your Wifi and access your MQTT server you have to add this to an `environment` [header file](./02-energy-monitor-mqtt/environment.h):
```C ```C
// Replace with your network credentials // Replace with your network credentials
@ -134,7 +134,7 @@ Posting to MQTT is quite simple. After setting up Wifi and connection to the MQT
client.publish(concat(mqttPrefix, "/ampere"), irmsArray); client.publish(concat(mqttPrefix, "/ampere"), irmsArray);
``` ```
Have a look at the complete [exampe](./02-energy-monitor-mqtt/). Have a look at the complete [example](./02-energy-monitor-mqtt/).
## Links ## Links