With Homie, does not even print on serial.
Here is my sketch.
Thanks
#include <Homie.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define FW_NAME "temperature"
#define FW_VERSION "1.0.0"
const int TEMPERATURE_INTERVAL = 300;
unsigned long lastTemperatureSent = 0;
#define ONE_WIRE_BUS 2 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
HomieNode temperatureNode("temperature", "temperature");
void setupHandler() {
Homie.setNodeProperty(temperatureNode, "unit", "f", true);
}
void loopHandler() {
if (millis() - lastTemperatureSent >= TEMPERATURE_INTERVAL * 1000UL || lastTemperatureSent == 0) {
float temperature = 22; // Fake temperature here, for the example
DS18B20.requestTemperatures();
temperature = DS18B20.getTempFByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °F");
if (Homie.setNodeProperty(temperatureNode, "degrees", String(temperature), true)) {
lastTemperatureSent = millis();
} else {
Serial.println("Temperature sending failed");
}
}
}
void setup() {
Serial.begin(9600);
Serial.println(FW_NAME FW_VERSION);
DS18B20.begin();
Homie.setFirmware(FW_NAME, FW_VERSION);
Homie.registerNode(temperatureNode);
Homie.setSetupFunction(setupHandler);
Homie.setLoopFunction(loopHandler);
Homie.setup();
}
void loop() {
Homie.loop();
}