[Framework] Homie for ESP8266

maybe your delay is with reading the sensor…

You have to take readings at a minimum of 2 seconds or the DHT will heatup and you will get false values.

maybe i’m wrong… giving my 2¢ here :slight_smile:

Thanks for providing suggestions. “Unfortunately” I am reading the DHT11 only every 15 seconds so I believe this part should be OK.

Actually, now that I think about it, the above is not entirely correct, and you may actually be on to something:

Although the DHT11 is clearly one physical sensor device, I am treating it as two different sensors; one temperature sensor and one humidity sensor. Each of these sensors have their own intervals for reading. Now, both of them are set for read every 15 seconds - which should be OK - however, they are read more or less back-to-back (meaning as fast as the code can execute). Obviously this means that the DHT11 device is actually being read twice very quickly and it is resting for 15 seconds before being read twice again, and so on.

I will try to change this and see what happens.

you can get both values in the same reading…

I would be just a matter of calling both value and seding them to the MQTT server, one after the other…

that could save some cpu cycles.

BTW, could I use your sensor class ? I asked marvinroger to add something similar but closed the request… your class does what i need… (aka, send state back to the MQTT at a pre-determined interval).
:slight_smile:

I know, however, I wanted my sensor class to represent a value/property and be generic/independent on the physical implementation of the sensor device. This is obviously one case where that approach could cause some problems. I have just restarted my node with read interval 15 seconds for temperature and 20 seconds for humidity. I chose 15 and 20 to make sure they never get to a point where they are read at “the same time”. I’ll let it run for some hours and publish the result.

Absolutely! I am in the process of moving it to github. I’ll let you know when it is available there in case I do some modifications or extensions.

On a side note, i’ve seen somewhere on the forums that, its even better to shutdown the DHT while its not in use. i’ve done that on a raspberry pi because the DHT was sometime crashing (but the DHT +VCC to a digital output +3.3V GPIO and pull high to read then, pull LOW wjile idle) that helps in kiiping the device cool…

Actually this will happen every minute (60 seconds).
60s = 4 x 15s
60s = 3 x 20s

Ah, shoot! I am not very good at math, am I? :slight_smile:
Thanks for pointing out this obvious flaw in my reasoning.

I should probably find some other numbers that will not “converge” with such regularity, but I am starting to see that by using fixed numbers I can not guarantee that they will never “converge”.

I looked at the code for the DHT library that I am using, and it turns out the read function actually implements a safeguard for this. If it is less than 2 seconds since the last time the read function was called, it will simply return the last value read from the sensor (and not actually read the sensor).

Yes, on the lowest level where data is clocked in from the sensor you get both temperature and humidity in one read. With the library I am using, however, you need to call two different class methods to get the temperature and the humidity.

Might be a newbie question here !!
got the ESP 8266/12e up and running via arduino etc

install openhab on a pc (windows 10)

Run the JSON configuration function and set up the WIFI logon and MQTT details
ESP8266 boots up fine but can not logon to the MQTT server . Fails to connect !

Tested the MQTT server from another PC (via a browser) all ok
I have set up one switch on the OPenHad server with the device ID etc

I notice that the default port on OpenHab Was 8080 , so i changed that in the JSON configure
and still fails to correct to MQTT server .
I using the IP address for the server , the port 8080 and nothing else.
I’ve noticed the code (c++) calls the MQTT Client with user ID and password , but that’s not in the Jason Config

i have checked the doco too
Have i missed something very basic

Ta
Lee

Is this based on debug messages on the serial console of the NodeMCU, or how do you determine that it fails to connect?

What kind of MQTT server are you using? Is it configured in an specific way, or used with default settings (at time of install)?

The standard port for MQTT is 1883. Port 8080 is the port that openHAB uses for it’s UI (and REST API). Please keep in mind that the MQTT broker and openHAB are two different programs/applications.

openHAB is simply a client of the MQTT broker, in the same way that your NodeMCU is a client. Or will be, when you get the connection working, :slight_smile:

So do i need to install MQTT server and if so what do you recommend ?

Correct! You need to install an MQTT broker that can “sit between” openHAB and your NodeMCU.

My personal preference is Mosquitto.

ok thanks … it’s just clicked !! :slight_smile: just installed mosquitto and got a connection :slight_smile:

@KjetilA to be honest, I have no idea of what is the issue. The workload of the ESP8266 should be lighter on the v1.3.0 than previous versions. Have you measured the time between two Homie.loop()?

BTW, I also got the online-false

Client mosqsub/12546-openhab received PUBLISH (d0, q0, r0, m0, ‘/openhab/devices/d76943e0/$online’, … (5 bytes))
false

As I see it, I reflashed the same sketch with the latest 1.3 framework. the chip flushed the config.json file on the flash partition…

but before the file was erased, it connected, sent the line above, then erased the file and rebooted in config mode.

i’m thinking out loud here, I could very well be wrong :wink:

Edit:

I would like to add, when sending a $reset = true, I get theses lines:

Client mosqsub/12546-openhab received PUBLISH (d0, q0, r0, m0, ‘/openhab/devices/d76943e0/$reset’, … (4 bytes))
true
Client mosqsub/12546-openhab received PUBLISH (d0, q0, r0, m0, ‘/openhab/devices/d76943e0/$reset’, … (5 bytes))
false
Client mosqsub/12546-openhab received PUBLISH (d0, q0, r0, m0, ‘/openhab/devices/d76943e0/$online’, … (5 bytes))
false

So, there could be something there… look like, the board still connects to wifi and is able to send data to the MQTT server before erasing the config.json file

Sometimes it happens during flashing if you change the SPIFFS size, but this is not an Homie issue.

This is normal! You probably had a retained $reset set to true pending. So when the device receives a true, it sends false, then resets and goes to configuration mode. Otherwise, the device would reset everytime because the $reset MQTT topic would always be true.

@marvinroger: I know there’s a $reset to return the device to config mode but, is there a way to reboot de device via mqtt ?

There is none. What would be the interest?

reboot the device to reset de state… useful when the device is not accessible (in wall project)

Reset the state? What do you mean? Every state interaction must be handled in your code, you should not reboot your device in normal use.