Perform the MQTT connection during the setup
This commit is contained in:
@@ -23,7 +23,7 @@ void setup() {
|
|||||||
Serial.println("ERROR: The config file could not be loaded");
|
Serial.println("ERROR: The config file could not be loaded");
|
||||||
|
|
||||||
connect_wlan(config);
|
connect_wlan(config);
|
||||||
|
connect_mqtt(mqtt_client, config);
|
||||||
initialize_sensor(sensor, error_code, error_msg);
|
initialize_sensor(sensor, error_code, error_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ size_t construct_json(float *data, char *buffer, int buffer_size) {
|
|||||||
|
|
||||||
void mqtt_transfer(PubSubClient &client, Config *config, float *data) {
|
void mqtt_transfer(PubSubClient &client, Config *config, float *data) {
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
connect_mqtt(client, config);
|
|
||||||
size_t payload_size = construct_json(data, buffer, 100);
|
size_t payload_size = construct_json(data, buffer, 100);
|
||||||
client.publish(config->topic, buffer, payload_size);
|
client.publish(config->topic, buffer, payload_size);
|
||||||
Serial.println("Data transferred successfully");
|
Serial.println("Data transferred successfully");
|
||||||
|
|||||||
Reference in New Issue
Block a user