[Framework] Homie for ESP8266

Cool, thanks. Haven’t checked yet.

I have been trying this framework. And looks very good. But i have a strange problem reading an DHT11 sensor. The humdity seems good, but the temperature is a very high number. Connection to MQTT server is good and posts are the same as the serial console.

MQTT values

temperature:temperature,humidity:humidity
true
Temp
192.168.178.42
awesome-temperature
1.0.0
c
2490390.00
72
true
38.00
1769494.00
27.00
1769494.00
27.00
1507350.00
23.00

Arduino sketch

#include <Homie.h>
#include <DHT.h>

#define DHTPIN D1     // what pin we're connected to

const int TEMPERATURE_INTERVAL = 10;
unsigned long last_temperature_sent = 0;

const int HUMIDITY_INTERVAL = 10;
unsigned long last_humidity_sent = 0;

HomieNode temperatureNode("temperature", "temperature");
HomieNode humidityNode("humidity", "humidity");

DHT dht;

void setupHandler() {
  // Do what you want to prepare your sensor
  dht.setup(DHTPIN); 
}


void getSendTemperature() {
  if (millis() - last_temperature_sent >= TEMPERATURE_INTERVAL * 1000UL || last_temperature_sent == 0) {
    float temperature = dht.getTemperature();

    if (isnan(temperature)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");
    if (Homie.setNodeProperty(temperatureNode, "temperature", String(temperature), true)) {
      last_temperature_sent = millis();
    } else {
      Serial.println("Sending failed");
    }
  }
}

void getSendHumid() {
  if (millis() - last_humidity_sent >= HUMIDITY_INTERVAL * 1000UL || last_humidity_sent == 0) {
    float humidity = dht.getHumidity();

    if (isnan(humidity)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");
    if (Homie.setNodeProperty(humidityNode, "humidity", String(humidity), true)) {
      last_humidity_sent = millis();
    } else {
      Serial.println("Sending failed");
    }
  }
}


void loopHandler() {

  getSendTemperature();
  getSendHumid();   

}

void setup() {
  Homie.setFirmware("awesome-temperature", "1.0.0");
  Homie.registerNode(temperatureNode);
  Homie.registerNode(humidityNode);
  Homie.setSetupFunction(setupHandler);
  Homie.setLoopFunction(loopHandler);
  Homie.setup();
}

void loop() {
  Homie.loop();
}

I do not participate to your git but I read EVERYDAY all of your progress like I’m addicted! Look like serious caffeine progress!
Seriously fan of all your energy on the project!
Keep going on.
I’ve received my first 3 esp8266-1 yesterday and exited to work on my first flash with homie.

1 Like

Did the sensor ever work with the same code, without Homie?[quote=“qtronik, post:63, topic:8674”]
I do not participate to your git but I read EVERYDAY all of your progress like I’m addicted! Look like serious caffeine progress!
Seriously fan of all your energy on the project!
Keep going on.
[/quote]

Haha, thanks a lot! I have the chance to make flexible enough studies to work on my own projects. :slight_smile:

I connected the DHT sensor to a pro mini with the DHT Tester and that worked fine. Normal values for temperature and humdity.
Reconnected to the nodemcu 0.9 esp8266 loaded with sketch listed above it gives the garbage temperature reading. Also in the serial monitor there is the garbage temperature reading.

Just found this project… very cool and could help define the future of the ESP8266 in the IoT world :wink:

I have a small question… I plan to use the DS18B20 sensors on all modules and would like to use its unique address as the device ID. Would it be possible to use that as opposed to the internal (chip+flash) ID ?

like, set the divice ID manually ?

Thanks :slight_smile:

Please try with a sketch on the NodeMCU board without using Homie. Does it work well?

When #45 will be implemented, you will be able to set the device ID you want to use on the MQTT broker, from the config.json file. Would it fit with your requirement?

Yes and no… I just read the github request and understand what they mean…

But, i’m saying something in the lines of this:

homie.setDeviceID(newDeviceID) // before homie.setup()

a way to manually give a “divice ID / name” in the sketch itself.

Unfortunately, what you’re asking would conflict with the #45 request which I think is more important. However, you can create a node with, as its ID, the ID of your sensor. This is the most idomatic way to do it with Homie.

maybe… but if I do that, is there a reway to desable the device ID and only keep the device name ? AKA the DS18B20’s MAC address

Good way I think too.
I plan too to use a 1-wire ds18b20 with 5 of my sensors.
Maybe when #45 will be closed an 1-wire Dalas with #homie could be used to an exemple.ino file in your GitHub?

Small question…
Does the framework work on other ESP8266 boards ?

I’m trying to run it on a generic ESP8266-07 and all I get on the Serial interface is garbage… (connecting at 115200)
And, I dont have any AP poping in my wifi list.

anyone else tried this ?

ok, got it to work on the ESP8266-07 but, theres nothing on the serial line.

I do see actions on the MQTT topic and can make the GPIO pin go low/high from MQTT (and get a state back)

:slight_smile:

You said you were using a generic ESP8266. The “problem” with these board is the LED is connected to the serial line, so you cannot blink a LED and output text at the same time. You can do two things:

  • Disable the LED handling if you want output on the serial line:
Homie.enableBuiltInLedIndicator(false); // before Homie.setup();
  • Disable the logging if you want the LED to blink:
Homie.enableLogging(false); // before Homie.setup();

I am glad you got it working. :slight_smile:

Yes, good idea. :wink:

Ok, so, i’m playing around with manual configuration (JSON file).

I uploaded the following info and looks like the “base_topic” in the MQTT section is not used.

{
“name”: “osdomotics”,
“device_id”: “lights”,
“wifi”: {
“ssid”: “domotic01”,
“password”: “my passwd”
},
“mqtt”: {
“host”: “172.20.0.10”,
“port”: 1883,
“base_topic”: “/openhab/devices/”,
“auth”: false
},
“ota”: {
“enabled”: false
}
}

but I still get :

Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$online', ... (4 bytes))
true
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$name', ... (10 bytes))
osdomotics
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$localip', ... (11 bytes))
172.20.0.98
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$fwname', ... (13 bytes))
awesome-relay
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$fwversion', ... (5 bytes))
1.0.0
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/db2478e0/$signal', ... (2 bytes))
54
Client mosqsub/15772-openhab received PUBLISH (d0, q0, r0, m0, 'devices/d76943e0/$signal', ... (2 bytes))
78

On the MQTT server.

Is that variable used in the framework ?

My bad, the Wiki reflects the latest development version, not released one. This feature is implemented, but not yet released.

I’ll switch to a docs folder in the repo, so docs can be versionned.

Woups, I staid up till 1:40AM this morning to implement that part of the code…

Got it working too !

but looking at your code, there’s alot of changes (like the new MqttClient.cpp) that wasen’t there when a cloned the repo.

Will there be alot more changes ? I would like to add a method that you can manually add a device_id in code before setup… (I know that theres one in the JSON config file) but in my case, adding this method will help in using a DS18B20’s MAC address as a device ID :slight_smile:

What do you think ?

So sorry :confused:

I can’t promise there won’t be changes, with the flow of feature requests / bugs, the internal code is likely to change often. But I don’t understand why you would want to do this? I designed the framework in a way that allows you to define semantic topics. With the new device_id addition (yet to be released in 1.3.0), you can have something that looks like this:

devices/garden-esp8266/temperature/degrees → 20.35

As you can see, this cannot be more clear. If I understand you correctly, what you want to do would make it look like so:

devices/c9-16-70-8a-e0-c7/temperature/degrees → 20.35

May I ask how this would help for your installation? I don’t see the benefits.

Yes you understand correctly.
Well, every modules that I will design will have a DS18B20 in it… mainly because they will be in-wall modules so I want to monitor temperature so they dont overheat… and while at it, use it’s unique mac address as ident.

Is it clearer… maybe not… you use the last 4 bytes of the esp8266’s mac address and i’m starting to think that it would also be a good choice.

This was juste a “nice to have os be able to change in code”

as for benefits. not sure there are… except like I said above this line :slight_smile:

I also have another question.

My openhab server sends a message every x minutes the MQTT containing a datetime string.

Is it possible to access the subscribe method in the framework to react to that string ?
any pointers on code ?

Thanks