-->
Page 1 of 1

Homie DS18B20

PostPosted: Wed Aug 24, 2016 6:27 pm
by billm9
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();
}

Re: Homie DS18B20

PostPosted: Thu Aug 25, 2016 5:21 am
by Orcanbull
http://www.elec-cafe.com/temperature-se ... d-ds18b20/


The got a working code there.
Google is your friend

Re: Homie DS18B20

PostPosted: Thu Aug 25, 2016 8:21 am
by billm9
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

Re: Homie DS18B20

PostPosted: Sat Oct 22, 2016 1:35 pm
by kylegordon
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.