Open transistor1990 opened 4 years ago
I have managed to upload my code however an Error occurred on Serial Window.
Here is my Code: `#include "secrets.h"
// Button that will put device into Access Point mode to allow for re-entering WiFi and MQTT settings
WiFiMQTTManager wmm(RESET_BUTTON, AP_PASSWORD); // AP_PASSWORD is defined in the secrets.h file
void setup() { Serial.begin(115200); Serial.println(F("WiFiMQTTManager Basic Example")); // set debug to true to get verbose logging // wm.wm.setDebugOutput(true); // most likely need to format FS but only on first use // wmm.formatFS = true; // optional - define the function that will subscribe to topics if needed // wmm.subscribeTo = subscribeTo; // required - allow WiFiMQTTManager to do it's setup wmm.setup(__SKETCH_NAME__); // optional - define a callback to handle incoming messages from MQTT // wmm.client->setCallback(subscriptionCallback);
}
void loop() { // required - allow WiFiMQTTManager to check for new MQTT messages, // check for reset button push, and reconnect to MQTT if necessary wmm.loop();
// optional - example of publishing to MQTT a sensor reading once a 1 minute long now = millis(); if (now - wmm.lastMsg > 60000) { wmm.lastMsg = now; float temperature = 70; // read sensor here float pump = 50; float heater = 80; float stat = 1; String message = "[" + String(temperature) + "," + String(stat) + "," + String(heater) + "," + String(pump) + "]"; Serial.print("Temperature: "); Serial.println(temperature); char topic[100]; snprintf(topic, sizeof(topic), "%s%s%s", "sensor/", "d150", "/ctemperature"); wmm.client->publish(topic, String(message).c_str(), true); }
} `
and here is the Serial monitor:
Please Help me to convert multiple data into one and publish it to mqtt.
i have these data: Temperature: [0-120] Pump: [0-100] Heater: [0-100] Status: [0 or 1] the format to send must be [Temperature,Pump,Heater,Status]
the "[" and "]" must be included in the message.
will i have to create a variable to collect all data into one like
message= "[" + Temperature + "," + Pump ... "]" wmm.client->publish(topic, String(message).c_str(), true);
thanks