Re: [weewx-development] Pressure resolution and BMP280

2018-08-22 Thread gjr80
Looks good, one thing you can do to make your code a little more readable 
is to make use the available properties of ValueTuple objects. 
weewx.units.convertStd returns an object of type ValueTuple. ValueTuple 
objects have 3 useful properties; .value, .unit and .group. In your code 
you could replace pres_tuple[0] with pres_tuple.value. Likewise temp_tuple. 
Will make no difference to the execution of your code but it does make is a 
bit more readable. If you are interested you can read about ValueTuple 
objects here 
.

Gary

On Wednesday, 22 August 2018 20:04:11 UTC+10, David Moore wrote:
>
> So, thanks for all your help, here's what I finally have working.
>
> It's a little more generic, as in I can specify in weewx.conf where my BMP 
> library is, what my sea level modifier is, and where I want to store the 
> values, if at all
>
> weewx.conf
>
> [BMP280]
> col_pres = pressure
> col_temp = ''
> sl_denominator = 0.8708
> BME280_lib_location = '/home/pi/git/Adafruit_Python_BME280'
>
> data_services = user.bmp280a.bmp
>
>
> bmp280a.py
>
> import weewx
> from weewx.engine import StdService
> import sys
> import syslog
>
> # Inherit from the base class StdService:
> class bmp(StdService):
>
> def __init__(self, engine, config_dict):
> # Pass the initialization information on to my superclass:
> super(bmp, self).__init__(engine, config_dict)
>
> self.col_pres=   config_dict['BMP280']['col_pres']
> self.col_temp=   config_dict['BMP280']['col_temp']
> self.sl_denominator  = float(config_dict['BMP280'][
> 'sl_denominator'])
> self.BME280_lib_location =   config_dict['BMP280'][
> 'BME280_lib_location']
>
> # Bind to any new archive record events:
> self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_packet)
>
> def new_archive_packet(self, event):
> sys.path.insert(0, self.BME280_lib_location)
> from Adafruit_BME280 import *
>
> sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, 
> h_mode=BME280_OSAMPLE_8)
> degrees = sensor.read_temperature()
> pascals = sensor.read_pressure()
> hectopascals = pascals / 100
>
> ## convert to sea level pressure
> ## relativePressure/(1-alt_in_meters/44330)^5.255
> ##
> ## we can read altitude of station, convert to m, then run the 
> formala...
> ## for now I can just hard code that I have to divide by value in 
> weewx.conf in my case
> hectopascals = hectopascals/self.sl_denominator
>
> #pres_tuple = weewx.units.convertStd((hectopascals, "mbar", 
> "group_pressure"),weewx.US)
> pres_tuple = weewx.units.convertStd((hectopascals, "mbar", 
> "group_pressure"), event.record['usUnits'])
> temp_tuple = weewx.units.convertStd((degrees, "degree_C", 
> "group_temperature"), event.record['usUnits'])
>
> if self.col_pres:
> event.record[self.col_pres] = pres_tuple[0]
> if self.col_temp:
> event.record[self.col_temp] = temp_tuple[0]
>
>
>
>
>
>
> On Wednesday, 22 August 2018 00:12:24 UTC+2, gjr80 wrote:
>>
>> Generally speaking if your service is based on StdService and it's 
>> properly constructed then the 'event' parameter should have either 
>> event.packet or event.record (depending on whether it is bound to 
>> NEW_LOOP_PACKET or NEW_ARCHIVE_RECORD) which will give you access to the 
>> loop packet or event record just as Tim has done. There was no context in 
>> Tom's example and I suspect that is why there is the subtle difference.
>>
>> Gary
>>
>

Re: [weewx-development] Pressure resolution and BMP280

2018-08-22 Thread David Moore
So, thanks for all your help, here's what I finally have working.

It's a little more generic, as in I can specify in weewx.conf where my BMP 
library is, what my sea level modifier is, and where I want to store the 
values, if at all

weewx.conf

[BMP280]
col_pres = pressure
col_temp = ''
sl_denominator = 0.8708
BME280_lib_location = '/home/pi/git/Adafruit_Python_BME280'

data_services = user.bmp280a.bmp


bmp280a.py

import weewx
from weewx.engine import StdService
import sys
import syslog

# Inherit from the base class StdService:
class bmp(StdService):

def __init__(self, engine, config_dict):
# Pass the initialization information on to my superclass:
super(bmp, self).__init__(engine, config_dict)

self.col_pres=   config_dict['BMP280']['col_pres']
self.col_temp=   config_dict['BMP280']['col_temp']
self.sl_denominator  = float(config_dict['BMP280'][
'sl_denominator'])
self.BME280_lib_location =   config_dict['BMP280'][
'BME280_lib_location']

# Bind to any new archive record events:
self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_packet)

def new_archive_packet(self, event):
sys.path.insert(0, self.BME280_lib_location)
from Adafruit_BME280 import *

sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, 
h_mode=BME280_OSAMPLE_8)
degrees = sensor.read_temperature()
pascals = sensor.read_pressure()
hectopascals = pascals / 100

## convert to sea level pressure
## relativePressure/(1-alt_in_meters/44330)^5.255
##
## we can read altitude of station, convert to m, then run the 
formala...
## for now I can just hard code that I have to divide by value in 
weewx.conf in my case
hectopascals = hectopascals/self.sl_denominator

#pres_tuple = weewx.units.convertStd((hectopascals, "mbar", 
"group_pressure"),weewx.US)
pres_tuple = weewx.units.convertStd((hectopascals, "mbar", 
"group_pressure"), event.record['usUnits'])
temp_tuple = weewx.units.convertStd((degrees, "degree_C", 
"group_temperature"), event.record['usUnits'])

if self.col_pres:
event.record[self.col_pres] = pres_tuple[0]
if self.col_temp:
event.record[self.col_temp] = temp_tuple[0]






On Wednesday, 22 August 2018 00:12:24 UTC+2, gjr80 wrote:
>
> Generally speaking if your service is based on StdService and it's 
> properly constructed then the 'event' parameter should have either 
> event.packet or event.record (depending on whether it is bound to 
> NEW_LOOP_PACKET or NEW_ARCHIVE_RECORD) which will give you access to the 
> loop packet or event record just as Tim has done. There was no context in 
> Tom's example and I suspect that is why there is the subtle difference.
>
> Gary
>


Re: [weewx-development] Pressure resolution and BMP280

2018-08-21 Thread Tim Urberg

Here's what I have working:

#!/usr/bin/env python

import syslog
import weewx

from weewx.wxengine import StdService
from Adafruit_BME280 import *

class PressureService(StdService):
    def __init__(self, engine, config_dict):
    super(PressureService, self).__init__(engine, config_dict)
    self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_sensors)

    def read_sensors(self, event):
    sensor = BME280(t_mode=BME280_OSAMPLE_8, 
p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)

    degrees = sensor.read_temperature()
    pascals = sensor.read_pressure()
    event.record['inTemp'] = float((degrees*9/5)+32)
    event.record['pressure'] = float(pascals * 0.00029530)

It is reporting both pressure and indoor temp, I don't have the one that 
has humidity.


On 8/21/2018 11:18 AM, David Moore wrote:

I am also interested in this, and here's what I've managed to do / not do.

I attached the sensor, and ran
|
sudo i2cdetect -y 1
|
to check it was there.

It was showing as position 0x77, which is decimal 119 just as in 
Craig's post above.


These parts were missing above, and I eventually figured out as he's 
running it as a service:


I then took his file, bmp280.py amd put it in /usr/share/weewx/user/
I then added to weewx.conf as above.

However i ALSO had to add this to the engine services part:

|
archive_services =weewx.engine.StdArchive,user.bmp280.bmp
|

(I was getting errors before that)

So, now weewx runs without error

In the logs I can see this:

|
Aug2117:27:38WeatherPiweewx[1589]:manager:Dailysummary version is2.0
Aug2117:27:38WeatherPiweewx[1589]:engine:Usingbinding 'wx_binding'to 
database 'weewx'
Aug2117:27:38WeatherPiweewx[1589]:manager:Startingbackfill of daily 
summaries
Aug2117:27:38WeatherPiweewx[1589]:engine:Finishedloading service 
weewx.engine.StdArchive

Aug2117:27:38WeatherPiweewx[1589]:engine:Loadingservice user.bmp280.bmp
Aug2117:27:38WeatherPiweewx[1589]:engine:Finishedloading service 
user.bmp280.bmp
Aug2117:27:38WeatherPiweewx[1589]:engine:Loadingservice 
weewx.restx.StdStationRegistry

Aug2117:27:38WeatherPiweewx[1589]:restx:StationRegistry:Registrationnotrequested.
Aug2117:27:38WeatherPiweewx[1589]:engine:Finishedloading service 
weewx.restx.StdStationRegistry

|

However, nothing is getting written to db.

I tried this to check everything on the sensor was ok:

|
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git 


cd Adafruit_Python_GPIO
sudo python setup.py install
cd ../
git clone https://github.com/adafruit/Adafruit_Python_BME280.git 


cd Adafruit_Python_BME280
python ./Adafruit_BME280_Example.py


Temp=29.053deg C
Pressure=890.79hPa
Humidity=0.00%
|



So, I'm stumped now.  Will let you know if I get it working, however I 
feel I'm going to need some help...










On Tuesday, 26 June 2018 20:15:21 UTC+2, Tim Urberg wrote:

I know it's been a while, but just wondering if there's any update
on this, I was thinking of using this and wanted to make sure it
worked before buying one.

Thanks!
Tim

On Saturday, April 8, 2017 at 6:35:33 AM UTC-5, Craig Thom wrote:

col_pres should be "pressure. I read that part of the weewx
documentation, but I didn't remember it right.

The pressure from the BMP280 does not take elevation into account.





---
This email has been checked for viruses by AVG.
https://www.avg.com


Re: [weewx-development] Pressure resolution and BMP280

2018-08-21 Thread David Moore
Thanks. I read above that Tom suggested 

new_valueTuple = weewx.units.convertStd((22.5, "degree_C", 
"group_temperature"), packet['usUnits'])

However packet is undefined in eg, the electricity example. (I get an error)

So I am doing

pres_tuple = weewx.units.convertStd((hectopascals, "mbar", 
"group_pressure"),weewx.US)

As my DB is in default US units. However there is probably a way to read 
this from the weewx.conf

But then I'm not sure why that's defined at packet level in the example, 
unless I am reading lots of data (eg from different devices with SDR, that 
have different formats).
But then, I'm not *adding *to one of those, this is sort of "standalone".

So not quite sure what to replace weewx.US with that will always work.

Finally, I am converting data to sea level pressure, is that the correct 
value to be storing?
Finally Finally, is there some way to calibrate the pressure? it's 5HPa off 
my acurite 5n1 reading, but closer to what the local weather service is 
saying.



On Tuesday, 21 August 2018 22:48:30 UTC+2, gjr80 wrote:
>
> Yes, simple is best.
>
> Converting, calculating etc is ok, though as with a driver a data service 
> should really just be getting raw data from a sensor, decoding it as 
> required and then making sure it is in the correct units (ie observing the 
> usUnits field in the loop packet/archive record you are adding your data 
> to) before adding it to the current loop packet/archive record (a common 
> pitfall is to add temperature data in say F when all the temperatures in 
> the existing packet/record are in C, hence the need to observe usUnits). 
> That way StdConvert, StdCalibrate can do all their converting and 
> calibrating and produce sensible results.
>
> Gary
>
>

Re: [weewx-development] Pressure resolution and BMP280

2018-08-21 Thread David Moore
Right.. ok, makes sense now.

The file from Craig Thom seems to do a lot of processing, and converting, 
and filtering/massaging... so wasn't clear on that point

So I went back to the electricity example in the customizing guide, and it 
sort of makes sense now!

I am not sure what all that calibration and manipulation is in his file, 
so, given there's standard libraries for reading from BMP280 I will just 
use those and write a shorter, and hopfully simpler service.

Thanks!

Dave

On Tuesday, 21 August 2018 22:24:59 UTC+2, gjr80 wrote:
>
> Hi,
>
> In this case order matters. The StdArchive service is the service that 
> does the final processing of archive records and ultimately saves the 
> archive record to database. You have placed your service after StdArchive 
> so by the time your service is obtaining data, and presumably adding it to 
> loop packets and/or archive records, data has already been saved to 
> database and hence your data is effectively lost. Your service needs to be 
> called before StdArchive.
>
> If you have a look at the [Engine] [[Services]] stanza in weewx.conf you 
> will see the are a number of config options that list the services WeeWX 
> will run. Have a read of the User's Guide covering this (
> http://www.weewx.com/docs/usersguide.htm#[Engine]). Whilst it does not 
> really matter, you would be better off including your service as a 'data' 
> service (hmm, just noticed data services are not covered in the User's 
> Guide - need  to fix that). Data services should be adding data to the 
> packets/records being produced by the driver, data services are called 
> before any of the process services (and archive services) that 
> calibrate/convert etc the data. Try something like:
>
> data_services = user.bmp280.bmp
>
> Gary
>
>

Re: [weewx-development] Pressure resolution and BMP280

2018-08-21 Thread gjr80
Hi,

In this case order matters. The StdArchive service is the service that does the 
final processing of archive records and ultimately saves the archive record to 
database. You have placed your service after StdArchive so by the time your 
service is obtaining data, and presumably adding it to loop packets and/or 
archive records, data has already been saved to database and hence your data is 
effectively lost. Your service needs to be called before StdArchive.

If you have a look at the [Engine] [[Services]] stanza in weewx.conf you will 
see the are a number of config options that list the services WeeWX will run. 
Have a read of the User's Guide covering this 
(http://www.weewx.com/docs/usersguide.htm#[Engine]). Whilst it does not really 
matter, you would be better off including your service as a 'data' service 
(hmm, just noticed data services are not covered in the User's Guide - need  to 
fix that). Data services should be adding data to the packets/records being 
produced by the driver, data services are called before any of the process 
services (and archive services) that calibrate/convert etc the data. Try 
something like:

data_services = user.bmp280.bmp

Gary


Re: [weewx-development] Pressure resolution and BMP280

2018-08-21 Thread David Moore
I am also interested in this, and here's what I've managed to do / not do.

I attached the sensor, and ran

sudo i2cdetect -y 1

to check it was there.

It was showing as position 0x77, which is decimal 119 just as in Craig's 
post above.

These parts were missing above, and I eventually figured out as he's 
running it as a service:

I then took his file, bmp280.py amd put it in /usr/share/weewx/user/
I then added to weewx.conf as above.

However i ALSO had to add this to the engine services part:

archive_services = weewx.engine.StdArchive, user.bmp280.bmp

(I was getting errors before that)

So, now weewx runs without error

In the logs I can see this:

Aug 21 17:27:38 WeatherPi weewx[1589]: manager: Daily summary version is 2.0
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Using binding 'wx_binding' 
to database 'weewx'
Aug 21 17:27:38 WeatherPi weewx[1589]: manager: Starting backfill of daily 
summaries
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Finished loading service 
weewx.engine.StdArchive
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Loading service user.bmp280.
bmp
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Finished loading service user
.bmp280.bmp
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Loading service weewx.restx.
StdStationRegistry
Aug 21 17:27:38 WeatherPi weewx[1589]: restx: StationRegistry: Registration 
not requested.
Aug 21 17:27:38 WeatherPi weewx[1589]: engine: Finished loading service 
weewx.restx.StdStationRegistry

However, nothing is getting written to db.

I tried this to check everything on the sensor was ok:

git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO 
sudo python setup.py install 
cd ../ 
git clone https://github.com/adafruit/Adafruit_Python_BME280.git 
cd Adafruit_Python_BME280 
python ./Adafruit_BME280_Example.py 
 

Temp  = 29.053 deg C 
Pressure  = 890.79 hPa 
Humidity  = 0.00 %



So, I'm stumped now.  Will let you know if I get it working, however I feel 
I'm going to need some help...









On Tuesday, 26 June 2018 20:15:21 UTC+2, Tim Urberg wrote:
>
> I know it's been a while, but just wondering if there's any update on 
> this, I was thinking of using this and wanted to make sure it worked before 
> buying one.
>
> Thanks!
> Tim
>
> On Saturday, April 8, 2017 at 6:35:33 AM UTC-5, Craig Thom wrote:
>>
>> col_pres should be "pressure. I read that part of the weewx 
>> documentation, but I didn't remember it right.
>>
>> The pressure from the BMP280 does not take elevation into account.
>>
>

Re: [weewx-development] Pressure resolution and BMP280

2017-04-06 Thread Craig Thom
I know I saw, somewhere, a way to call an existing weewx method to convert 
units to whatever is needed, but I can't find it again.  It may have been 
in a service in the Wiki rather than in the documentation, because I can't 
find it there.

Is there such a thing? 

I didn't like how limited the Adafruit program was and the dependencies, so 
I have fixed my first ever Python program to read the sensor.  I'm ready to 
turn it into a service, with the options in weewx.conf and everything.  I 
think.

Anyway, I'd like to use the weewx conversion if necessary and possible.

On Saturday, April 1, 2017 at 5:38:31 PM UTC-4, mwall wrote:
>
> On Saturday, April 1, 2017 at 5:29:16 PM UTC-4, Craig Thom wrote:
>>
>> My goal is to use the existing SDR driver and to use a service to read 
>> the pressure from the BMP280 and add it to the data the SDR driver is 
>> collecting.
>
>
> craig,
>
> handling the units in a service is slightly different that in a driver.
>
> in the driver, you can specify the unit system of the packet to match the 
> units from the sensors (assuming they all emit values in the same unit 
> system).
>
> in a service, you must work with whatever unit system you find in the 
> packet.
>
> so be sure to check the value of usUnits, then convert your sensor value 
> (if necessary) to be in units that are appropriate for the unit system 
> specified by usUnits.
>
> m 
>


Re: [weewx-development] Pressure resolution and BMP280

2017-04-01 Thread Thomas Keffer
The only thing that matters is that the packet yielded by the driver use a
consistent unit system. Doesn't matter what that unit system is, but all
measurements in the packet have to use it.

See the Appendix *Units
* for the
definitions of the three unit systems, US, METRIC, and METRICWX.

-tk

On Sat, Apr 1, 2017 at 2:01 PM, Craig Thom  wrote:

> Thanks. In the MySQL database it's a double, so the resolution is there.
>
> My weewx is using American measures and putting inHg in the database. Do i
> need to convert from Pascals before handing the data back?


Re: [weewx-development] Pressure resolution and BMP280

2017-04-01 Thread Craig Thom
Thanks. In the MySQL database it's a double, so the resolution is there.

My weewx is using American measures and putting inHg in the database. Do i need 
to convert from Pascals before handing the data back?

Re: [weewx-development] Pressure resolution and BMP280

2017-04-01 Thread Thomas Keffer
Weewx doesn't round anything. It just passes values on to the database.

How the database handles it depends on the type of database, driver, and
how it's configured.

-tk

On Sat, Apr 1, 2017 at 11:03 AM, Craig Thom  wrote:

> I'm working an a RPi SPI service to read a BMP280.
>
> The BMP280 can produce 16 to 20 bit values for pressure, depending on how
> it's configured.  With the default 16 bits it says it is accurate to within
> 2.62 Pa.
>
> That's a lot finer resolution than anything I've seen reported.  Is weewx
> going to use the extra data going from 2.62 Pa to 0.16 Pa accuracy, or is
> it just going to be rounded off?
>


[weewx-development] Pressure resolution and BMP280

2017-04-01 Thread Craig Thom
I'm working an a RPi SPI service to read a BMP280.

The BMP280 can produce 16 to 20 bit values for pressure, depending on how 
it's configured.  With the default 16 bits it says it is accurate to within 
2.62 Pa.

That's a lot finer resolution than anything I've seen reported.  Is weewx 
going to use the extra data going from 2.62 Pa to 0.16 Pa accuracy, or is 
it just going to be rounded off?