NorthernMan54 / homebridge-mcuiot

Homebridge platform plugin that support's a network of nodemcu's running nodemcu-dht-yl69-mdns to display Temperature and Humidity.
30 stars 12 forks source link

Entering altitude of measurement place didn't work #18

Closed chimcen closed 5 years ago

chimcen commented 5 years ago

Hi,

in bme.lua i've entered my correct altitude - for testing purposes i've changed the altidude to "0" and expected that the baro measurement will no be calculated at sea level.

But nothing has changed - baro value still stuck at ~ 965...

NorthernMan54 commented 5 years ago

Just looking at the code in BME.lua, and the altitude is not implemented. Looking at the code, line 12 local T,P,H,QNH = bme280.read()

would need to be

local T,P,H,QNH = bme280.read(alt)

chimcen commented 5 years ago

Made no diff - the Baro tells the same as without (alt)...

NorthernMan54 commented 5 years ago

Humm I have no clue, have you read the data sheet for the sensor around how it’s supposed to work.

On Oct 9, 2018, at 10:51 AM, chimcen notifications@github.com wrote:

Made no diff - the Baro tells the same as without (alt)...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

chimcen commented 5 years ago

I read some intersting in datasheet of the bmp180 (they should be similar at this point) on page 17. Eventually this could help? https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf

Some other do this this way: https://meteocercal.info/forum/Thread-How-to-get-the-sea-level-pressure-with-BMP280

NorthernMan54 commented 5 years ago

I just went back and reread the bme280/nodemcu programming interface, and they pass the sea level pressure in a different variable, QNH, which I’m not returning back to the interface.

Since your playing within bme.lua can you try adding

print(“Pressure,Sea Level”,P,QNH)

Around line 17, that should have it printed in esplorer. Then I will need to make a larger code change to pass it out the interface etc

On Oct 10, 2018, at 2:06 PM, chimcen notifications@github.com wrote:

I read some intersting in datasheet of the bmp180 (they should be similar at this point) on page 17. Eventually this could help? https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf Some other do this this way: https://meteocercal.info/forum/Thread-How-to-get-the-sea-level-pressure-with-BMP280 https://meteocercal.info/forum/Thread-How-to-get-the-sea-level-pressure-with-BMP280 — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NorthernMan54/homebridge-mcuiot/issues/18#issuecomment-428673011, or mute the thread https://github.com/notifications/unsubscribe-auth/AS5CmAfDZq-Crei9ojnsKcqstaeIBCYcks5ujjcjgaJpZM4XHpEs.

chimcen commented 5 years ago

Thank you - this works. I integrated it into bme & main.lua - see the pull https://github.com/NorthernMan54/homebridge-mcuiot/pull/22

chimcen commented 5 years ago

The pulled code changes are displaying both - preassure & preassure at sealevel (in ESPorer and in json output).

Actually at i use the eve app on my iphone to view the values - but the app doesn't recognize (or ignores) the second preasure value. Because of that i just use all of your last code lines and changed only these two lines in bme.lua:

local T,P,H,QNH = bme280.read(alt)

baro = QNH / 1000

After a restart of my homebridge the eve app reads the values correctly.

NorthernMan54 commented 5 years ago

If you update the pull request with your latest files I will review them. How do you think we should handle the sea level pressure?

chimcen commented 5 years ago

Ok - actually i've changed the code that the preassure at sealevel is the first and the local preassure ist the second one who will be spread out in json output.

image

Btw. why is when using module.Model = "BME" the moisture also be shown?

I'll test this at the evening and report the result.

I don't know wich one is the best way - for me its more interesting to see the preassure with corrections at sealevel.

I think it is good to provide to versions of bme/main.lua:

Another good idea is to integrate both meassurings and insert a new "switch" for changeing value sorting orders:

...if this is possible at lua script...

NorthernMan54 commented 5 years ago

I’m thinking have the lua code return all the possible values, then have the plugin chose the appropriate one thru config in the plugin. Does that make sense to you?

Regarding moisture, that is a bit a legacy in the code that hasn’t been refactored. The original ones I constructed were only moisture ie water leak detectors, so it was hard coded in. Then when I started switching the response based on model I missed that one.

For the second pressure, would it make sense to take over another HomeKit characteristic and have it be the sea level one? The naming would be off, but it should be display able then.

On Oct 12, 2018, at 9:21 AM, chimcen notifications@github.com wrote:

Ok - actually i've changed the code that the preassure at sealevel is the first and the local preassure ist the second one who will be spread out in json output.

Btw. why is when using module.Model = "BME" the moisture also be shown?

I'll test this at the evening and report the result.

I don't know wich one is the best way - for me its more interesting to see the preassure with corrections at sealevel.

I think it is good to provide to versions of bme/main.lua:

one set with only local preassure active another set with both, local and preassure at sealevel (with sealevel as first delivered one) Another good idea is to integrate both meassurings and insert a new "switch" for changeing value sorting orders:

if user enters nothing at local alt = only local preassure should be read and responsed if the users enters a local altitute and set an optional value (like module.ledState = 0/1/2 in config.lua), both preassure levels will be shown and could be switched wich one comes first... ...if this is possible at lua script...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

chimcen commented 5 years ago

Changed the code. It's great, when you can review it.

image image

Sounds great if the used setup (if local or sealevel) can be choosen in homebridge config.json. But read my comments about the value naming and the eve app usage of it... i can imagine other apps have the same problems (could be a limitation of homekit?)...

Otherwise if i was you i would only be implement pressure at sealevel "QNH" an make a comment behind the setting in bme.lua wich informs the user that using "P" instead of "QNH" and removing (alt) results in local pressure...

I'm understanding - can you recode the moisture meassurings the be also sticky to used model instead of hard coded?

It's also a possible way to go, but the best one is to config this in homebridge plugin config :)

NorthernMan54 commented 5 years ago

I just merged Pull request #22, which is the Lua side of this. Just need to complete the plugin changes.

chimcen commented 5 years ago

I use this actually at home and it works - but i've noticed in esplorer a panic message.

The message only appears after disconnecting and reconnecting the node at the first read attempt. After the following restart (or also manual reastarts by pressing the reset button) the code wirks at anytime without any problems.

Any idea why?

Error: PANIC: unprotected error in call to Lua API (bme.lua:18: attempt to perform arithmetic on a nil value)

NorthernMan54 commented 5 years ago

I have seen this as well, I believe it is minor issue with the BME280 code in the firmware, and it failing on the first try. As it only happens occasionally, it hasn’t hit my priority list.

On Oct 16, 2018, at 3:29 AM, chimcen notifications@github.com wrote:

I use this actually at home and it works - but i've noticed in esplorer a panic message.

The message only appears after disconnecting and reconnecting the node at the first read attempt. After the following restart (or also manual reastarts by pressing the reset button) the code wirks at anytime without any problems.

Any idea why?

Error: PANIC: unprotected error in call to Lua API (bme.lua:18: attempt to perform arithmetic on a nil value)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

chimcen commented 5 years ago

Yap - occourse only at the first try - after a reset it‘s working without any problems.