If the sensor emits Pascals, why would you multiply by
weewx.unit.INHG_PER_MBAR to convert to hPa? Why not just divide by 100?

I suspect that Matthew, as nice as he is, and as rarely as he is wrong,
used the wrong conversion factor.

-tk


On Mon, Apr 10, 2017 at 6:26 AM, Tommy Denton <[email protected]> wrote:

> Thanks for your response Gary!  I agree with you.. I have done some more
> digging and figuring (Texan for math) and can't figure out where the heck
> the number is coming from.....
>
> So here is what my sensor reads raw.. 95261.2968494 Pa...convert that to
> hPa (Pa/100) and you get 952.612968494...Convert that to mbar (hPa = mbar)
> and you get 952.612968494... convert that to inHg (mbar * .02953) and you
> get 28.1306609596... this is in the QA range and would be recorded..
>
> I did this in a text program I built using all of what MWall wrote for me
> in my driver.. and it looks like this...
>
> #!/usr/bin/python
>
> import time
> import Adafruit_BME280
> from datetime import datetime
> from time import strftime, localtime
>
> sensor = Adafruit_BME280.BME280(mode=Adafruit_BME280.BME280_OSAMPLE_8)
> pascals = sensor.read_pressure()
>
> #time
> start_time = time.time()
> datetime = strftime("%H:%M:%S %m-%d-%y")
>
> #Calcs
> hPa = pascals / 100
> mbar = hPa
> inHg = mbar * .02953
>
> #Print
> print 'dateTime,', datetime
> print 'Pa,',format(pascals)
> print 'hPa,',format(hPa)
> print 'mbar,',format(mbar)
> print 'inHg,',format(inHg)
>
> The output from my driver in what I think to be hPa is 2908.61213797.  I
> procured that reading by removing the * weewx.units.INHG_PER_MBAR from the
> statement packet['pressure'] = self._sensor1.read_pressure().
>
> I am stumped.. I will keep changing things till I get the right number..
> but maybe this will shake something loose.
>
> T
>
> On Friday, April 7, 2017 at 7:58:37 PM UTC-5, gjr80 wrote:
>>
>> Hi,
>>
>> Straight up I can see you running into a units problem. In your driver
>> you are using weewx.METRIC for field usUnits, so in other words all of the
>> obs in your loop packet should be from the weewx.METRIC unit system, for
>> barometer that is hPa. To calculate your barometer field you are taking
>> your sensor reading (I presume that is in Pa but I am not sure) and then
>> multiplying by a conversion factor that is in inHg/hPa, so the resulting
>> value will be in some sort of derivative of inHg, definitely not hPa.
>>
>> I think you need to go back and trace through your barometer units very
>> carefully, remember the conversion factor is not just a number, but it has
>> units itself ie inHg/hPa. If you put values in US customary units in a
>> METRIC packet they will be converted/stored /displayed incorrectly
>> somewhere.
>>
>> Gary
>>
>> On 08/04/2017 8:23 AM, "Tommy Denton" <[email protected]> wrote:
>>
>>> I have a custom hardware setup.. the DH22 and BME280 are outputting data
>>> las they should..(best I can tell)
>>>
>>> For my own quick and dirty webpage I did some maths to get pascals to
>>> inHg but now I want to do this in weewx and with some expert help on this
>>> forum I am like 98 percent there.. I have learned a lot but have hit the
>>> wall I always hit when I can't find some code to read or I don't know what
>>> code I am reading. Now I have read the manual and each time I get over one
>>> of these hurdles more of that manual changes from greek to english...but
>>> alas I am blocked by my own ignorance..
>>>
>>> So.. here is what I am doing for my own webpage..
>>>
>>> #Setup and pull data from the Sensor
>>> #bme280
>>> from Adafruit_BME280 import *
>>> sensor = BME280(mode=BME280_OSAMPLE_8)
>>> temperature = sensor.read_temperature()
>>> pascals = sensor.read_pressure()
>>>
>>> #Setup and pull data from the Sensor
>>> #AM2303
>>> import Adafruit_DHT
>>> sensor = Adafruit_DHT.AM2302
>>> pin = 17
>>> humidity, degrees = Adafruit_DHT.read_retry(sensor, pin)
>>>
>>> #Setup Time
>>> #time
>>> import time
>>> from datetime import datetime
>>> from time import strftime, localtime
>>>
>>> #Load up Converter
>>> #calcs
>>> from meteocalc import dew_point, heat_index
>>> temp = degrees*9/5+32
>>> baro = pascals/3386.389
>>> dewpoint = dew_point(temperature=degrees, humidity=humidity)
>>> heatindex = heat_index(temperature=degrees, humidity=humidity)
>>>
>>>
>>> My sensor puts out Pa
>>> I divide PA by 3386.839 and that gets me to inHg
>>>
>>> I output this to a file and it comes in to the right range and matches
>>> other weather stations around me plus or minus .10 inHg, so I feel like I
>>> have things setup correctly.
>>>
>>> Now this leads me to the error I am getting.
>>> The error I get is because the reading is outside the QA range limits..
>>> So I have to tried to back into the number some to figure out what is going
>>> on....engine: 2017-04-06 23:10:39 CDT (1491538239) LOOP value 'pressure'
>>> 85.32306 outside limits (24.0, 34.5)
>>>
>>> 85.32306... Where the heck did that number come from?  Well that
>>> is 85.32inHg/.029 = 2942.06896hPa*100 = 294206.8965517Pa
>>> Since hPa = mBAR there is no conversion there..
>>>
>>> The math is wrong in weewx.units?.. but I don't believe that either.. it
>>> has to be me messing up the math.. but I am not sure where to go from here
>>> to put in a custom conversion into extensions.py... I just have not been
>>> able to figure out the code to do so..
>>>
>>> or I am otherwise all wet..
>>>
>>> My driver looks like this.. (Expertly written by a very nice MWall)
>>>
>>> !/usr/bin/python
>>>
>>> import time
>>> import Adafruit_BME280
>>> import Adafruit_DHT
>>> import weewx.drivers
>>> from weewx.units import INHG_PER_MBAR
>>>
>>> DRIVER_NAME = 'PiHat'
>>> DRIVER_VERSION = '0.1'
>>>
>>> def loader(config_dict, engine):
>>>     return PiHatDriver(**config_dict[DRIVER_NAME])
>>>
>>> class PiHatDriver(weewx.drivers.AbstractDevice):
>>>     def __init__(self, **stn_dict):
>>>         self._sensor1 = Adafruit_BME280.BME280(mode=Ad
>>> afruit_BME280.BME280_OSAMPLE_8)
>>>         self._sensor2 = Adafruit_DHT.AM2302
>>>         self._pin = 17
>>>
>>>     def genLoopPackets(self):
>>>         while True:
>>>             try:
>>>                 packet = dict()
>>>                 packet['dateTime'] = int(time.time() + 0.5)
>>>                 packet['usUnits'] = weewx.METRIC
>>>                 packet['inTemp'] = self._sensor1.read_temperature()
>>>                 packet['pressure'] = self._sensor1.read_pressure() *
>>> weewx.units.INHG_PER_MBAR
>>>                 packet['outHumidity'], packet['outTemp'] =
>>> Adafruit_DHT.read_retry(self._sensor2, self._pin)
>>>                 yield packet
>>>             except IOError, e:
>>>                 syslog.syslog(syslog.LOG_ERR, "get data failed: %s" % e)
>>>             time.sleep(10) # wait 60 seconds before getting next set of
>>> data
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "weewx-user" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to