... | @@ -215,35 +215,6 @@ void connectToMqtt() { |
... | @@ -215,35 +215,6 @@ void connectToMqtt() { |
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
|
|
|
// Setup MQTT server
|
|
|
|
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
|
|
|
|
|
|
|
// Connect to WiFi
|
|
|
|
connectToWifi();
|
|
|
|
|
|
|
|
// Connect to MQTT
|
|
|
|
connectToMqtt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// Ensure the client is connected
|
|
|
|
if (!mqttClient.connected()) {
|
|
|
|
connectToMqtt();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle MQTT client loop
|
|
|
|
mqttClient.loop();
|
|
|
|
|
|
|
|
// Publish message every 1 second
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
if (currentMillis - previousMillis >= interval) {
|
|
|
|
previousMillis = currentMillis;
|
|
|
|
publishMsgBasket();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String set_fruitbasketMsg() {
|
|
String set_fruitbasketMsg() {
|
|
// Create a JSON document
|
|
// Create a JSON document
|
... | @@ -286,6 +257,37 @@ void publishMsgBasket() { |
... | @@ -286,6 +257,37 @@ void publishMsgBasket() { |
|
String topic = "MYfancyTopic/Dummy/Data/Basket";
|
|
String topic = "MYfancyTopic/Dummy/Data/Basket";
|
|
mqttClient.publish(topic.c_str(), msg.c_str());
|
|
mqttClient.publish(topic.c_str(), msg.c_str());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
|
|
|
// Setup MQTT server
|
|
|
|
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
|
|
|
|
|
|
|
// Connect to WiFi
|
|
|
|
connectToWifi();
|
|
|
|
|
|
|
|
// Connect to MQTT
|
|
|
|
connectToMqtt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
// Ensure the client is connected
|
|
|
|
if (!mqttClient.connected()) {
|
|
|
|
connectToMqtt();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle MQTT client loop
|
|
|
|
mqttClient.loop();
|
|
|
|
|
|
|
|
// Publish message every 1 second
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
if (currentMillis - previousMillis >= interval) {
|
|
|
|
previousMillis = currentMillis;
|
|
|
|
publishMsgBasket();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
> Now the ESP32 should send the data packet every 1000ms (1 second) to the MQTT broker via your router. To verify this, you can use sniffer tools to subscribe to the topic or even monitor the entire broker (i.e., all topics). Here, we will show you our favorite tool, which allows you to do many additional things in an userfriendly No-Code/Low-Code Environment!
|
|
> Now the ESP32 should send the data packet every 1000ms (1 second) to the MQTT broker via your router. To verify this, you can use sniffer tools to subscribe to the topic or even monitor the entire broker (i.e., all topics). Here, we will show you our favorite tool, which allows you to do many additional things in an userfriendly No-Code/Low-Code Environment!
|
... | | ... | |