mirror of
https://github.com/alexhopeoconnor/arduino-home-assistant.git
synced 2026-10-04 02:48:13 +10:00
docs: correct MQTT example and ESP8266 guidance
This commit is contained in:
@@ -8,7 +8,11 @@ ArduinoHA lets an Arduino, ESP8266, or ESP32 application publish MQTT discovery
|
||||
## Start with a sensor
|
||||
|
||||
```cpp
|
||||
#if defined(ESP8266)
|
||||
#include <ESP8266WiFi.h>
|
||||
#elif defined(ESP32)
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <ArduinoHA.h>
|
||||
|
||||
WiFiClient client;
|
||||
@@ -24,11 +28,11 @@ void setup() {
|
||||
// Your application connects Wi-Fi before MQTT begins.
|
||||
temperature.setName("Temperature");
|
||||
temperature.setUnitOfMeasurement("°C");
|
||||
mqtt.begin("mqtt.local", "mqtt_user", "mqtt_password");
|
||||
mqtt.begin("mqtt.local", "mqtt_user", "mqtt_password"); // Connection work begins in mqtt.loop().
|
||||
}
|
||||
|
||||
void loop() {
|
||||
mqtt.loop();
|
||||
mqtt.loop(); // Maintains MQTT and publishes discovery after connecting.
|
||||
// Call temperature.setValue(...) when your reading changes.
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user