Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of BTHGN129 Sensor #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 37 additions & 66 deletions parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def computeChecksum(bits):
return value


def _parseBHTR968(data):
def _parseBTHGN129(data):
"""
Parse the data section of a BHTR968 indoor temperature/humidity/pressure
Parse the data section of a BTHGN129 outdoor temperature/humidity/pressure
sensor packet and return a dictionary of the values recovered.
"""

Expand Down Expand Up @@ -84,7 +84,8 @@ def _parseBHTR968(data):
baro = (baro[1] << 4) | (baro[0])
if baro >= 128:
baro -= 256
output['pressure'] = baro + 856
#output['pressure'] = baro + 856
output['pressure'] = baro + 1071

# Pressure-based weather forecast
fore = nibbles2value(data[40:44])[0]
Expand All @@ -101,9 +102,9 @@ def _parseBHTR968(data):

return output

def _parseRGR968(data):
def _parsePCR800(data):
"""
Parse the data section of a RGR968 rain gauge packet and return a dictionary
Parse the data section of a PCR800 rain gauge packet and return a dictionary
of the values recovered.
"""

Expand All @@ -119,7 +120,7 @@ def _parseRGR968(data):

return output

def _parseWGR968(data):
def _parseWGR800(data):
"""
Parse the data section of a WGR968 anemometer packet and return a dictionary
of the values recovered.
Expand All @@ -141,30 +142,9 @@ def _parseWGR968(data):

return output

def _parseTHGR268(data):
def _parseTHGN800(data):
"""
Parse the data section of a THGR268 temperature/humidity sensor packet and return a dictionary
of the values recovered.
"""

output = {'temperature': -99, 'humidity': -99}

# Temperature in C
temp = nibbles2value(data[0:12])
temp = 10*temp[2] + temp[1] + 0.1*temp[0]
if sum(data[64:68]) > 0:
temp *= -1
output['temperature'] = temp

# Relative humidity as a percentage
humi = nibbles2value(data[16:24])
output['humidity'] = 10*humi[1]+humi[0]

return output

def _parseTHGR968(data):
"""
Parse the data section of a THGR268 temperature/humidity sensor packet and return a dictionary
Parse the data section of a THGN800 temperature/humidity sensor packet and return a dictionary
of the values recovered.
"""

Expand Down Expand Up @@ -206,11 +186,11 @@ def parsePacketv21(packet, wxData=None, verbose=False):
values recovered.

Supported Sensors:
* 5D60 - BHTR968 - Indoor temperature/humidity/pressure
* 2D10 - RGR968 - Rain gauge
* 3D00 - WGR968 - Anemometer
* 1D20 - THGR268 - Outdoor temperature/humidity
* 1D30 - THGR968 - Outdoor temperature/humidity
* 5D53 - BTHGN129 - Outdoor temperature/humidity/pressure
* 1924 - PCR800 - Rain gauge
* 1984 - WGR800 - Anemometer
* FA28 - THGN800 - Outdoor temperature/humidity

* EC70 - UVR128 - UV sensor
"""

Expand All @@ -225,20 +205,17 @@ def parsePacketv21(packet, wxData=None, verbose=False):
# Try to figure out which sensor is present so that we can get
# the packet length
sensor = ''.join(["%x" % i for i in nibbles2value(packet[20:36])])
if sensor == '5d60':
nm = 'BHTR968'
if sensor == '5d53':
nm = 'BTHGN129'
ds = 96
elif sensor == '2d10':
nm = 'RGR968'
elif sensor == '2A19':
nm = 'PCR800'
ds = 84
elif sensor == '3d00':
nm = 'WGR968'
elif sensor == '1A89':
nm = 'WGR800'
ds = 88
elif sensor == '1d20':
nm = 'THGR268'
ds = 80
elif sensor == '1d30':
nm = 'THGR968'
elif sensor == 'FA28':
nm = 'THGN800'
ds = 80
elif sensor == 'ec70':
nm = 'UVR128'
Expand Down Expand Up @@ -275,16 +252,14 @@ def parsePacketv21(packet, wxData=None, verbose=False):
# Parse
data = packet[52:ds]
channel = nibbles2value(packet[36:40])[0]
if nm == 'BHTR968':
output = _parseBHTR968(data)
elif nm == 'RGR968':
output = _parseRGR968(data)
elif nm == 'WGR968':
output = _parseWGR968(data)
elif nm == 'THGR268':
output = _parseTHGR268(data)
elif nm == 'THGR968':
output = _parseTHGR968(data)
if nm == 'BTHGN129':
output = _parseBTHGN129(data)
elif nm == 'PCR800':
output = _parsePCR800(data)
elif nm == 'WGR800':
output = _parseWGR800(data)
elif nm == 'THGN800':
output = _parseTHGN800(data)
elif nm == 'UVR128':
output = _parseUVR128(data)
else:
Expand Down Expand Up @@ -343,21 +318,17 @@ def parseBitStream(bits, elevation=0.0, inputDataDict=None, verbose=False):
### Data reorganization and computed quantities
if valid:
#### Dew point - indoor and output
if sensorName in ('BHTR968', 'THGR268', 'THGR968'):
if sensorName in ('BTHGN129', 'THGN800', 'THGN800'):
sensorData['dewpoint'] = computeDewPoint(sensorData['temperature'], sensorData['humidity'])
#### Sea level corrected barometric pressure
if sensorName in ('BHTR968',) and elevation != 0.0:
sensorData['pressure'] = computeSeaLevelPressure(sensorData['pressure'], elevation)

#### Disentangle the indoor temperatures from the outdoor temperatures
if sensorName == 'BHTR968':
for key in ('temperature', 'humidity', 'dewpoint'):
newKey = 'indoor%s' % key.capitalize()
sensorData[newKey] = sensorData[key]
del sensorData[key]
#### Multiplex the THGR268 values
if sensorName == 'BTHGN129':
for key in ('temperature', 'humidity', 'dewpoint','pressure'):
output[key] = sensorData[key]
#### Multiplex the THGN800 values
for key in sensorData.keys():
if key in ('temperature', 'humidity', 'dewpoint'):
if sensorName == 'THGR968':
if sensorName == 'THGN800':
output[key] = sensorData[key]
else:
try:
Expand Down