Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By billm9
#53745 trying to flash ESP8266-01 and connect to DS18B20.

Here is my sketch and doesnt seem to pull the temperature. Works fine with ESPEasy or barebones without Homie

Please help!

Thanks,

Bill

Code: Select all#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();
}
User avatar
By billm9
#53780 I would like working in Homie connected with Homie Server.

I finally got it to update on MQTT, but not updating on homie server.

Thanks
User avatar
By kylegordon
#56960 How far dd you get with this? I was just investigating doing the same with Homie, and spotted that in the documents it says "Very important: As a rule of thumb, never block the device with blocking code for more than 50ms or so."

Is your code doing the DS18B20 polling in non-blocking way? I suspect I'll need to do that in order to make my DS18B20 string work with Homie.