Skip to content

Instantly share code, notes, and snippets.

@zerog2k
Last active August 29, 2015 14:04
Show Gist options
  • Save zerog2k/577aec37c9a97078c1c3 to your computer and use it in GitHub Desktop.
Save zerog2k/577aec37c9a97078c1c3 to your computer and use it in GitHub Desktop.
parsing script for rtl_433 analyze mode for acurite 5n1 vn1tx weather station
#!/usr/bin/python
""" parse rtl_433 output for acurite 5n1 sensor """
# http://www.acurite.com/acurite-5-in-1-sensor
import re
import fileinput
samples = """
[04] {66} c6 84 38 80 65 00 4f 94 00 : 11000110 10000100 00111000 10000000 01100101 00000000 01001111 10010100 00000000
[09] {66} d6 88 71 00 ca 00 4f 9c 00 : 11010110 10001000 01110001 00000000 11001010 00000000 01001111 10011100 00000000
[14] {65} e6 88 71 00 ca 00 9f 48 00 : 11100110 10001000 01110001 00000000 11001010 00000000 10011111 01001000 00000000
[04] {65} c6 88 78 00 c9 28 33 ea 00 : 11000110 10001000 01111000 00000000 11001001 00101000 00110011 11101010 00000000
[09] {65} d6 88 78 00 c9 28 33 fa 00 : 11010110 10001000 01111000 00000000 11001001 00101000 00110011 11111010 00000000
[14] {65} e6 88 78 00 c9 28 33 0a 00 : 11100110 10001000 01111000 00000000 11001001 00101000 00110011 00001010 00000000
[09] {66} d6 88 78 00 69 28 b1 0c 80 : 11010110 10001000 01111000 00000000 01101001 00101000 10110001 00001100 10000000
[14] {65} e6 88 78 00 69 28 b2 29 00 : 11100110 10001000 01111000 00000000 01101001 00101000 10110010 00101001 00000000
[04] {65} c6 88 71 00 3a 00 9f 98 00 : 11000110 10001000 01110001 00000000 00111010 00000000 10011111 10011000 00000000
[09] {65} d6 88 71 00 3a 00 9f a8 00 : 11010110 10001000 01110001 00000000 00111010 00000000 10011111 10101000 00000000
[14] {65} e6 88 71 00 3a 00 9f b8 00 : 11100110 10001000 01110001 00000000 00111010 00000000 10011111 10111000 00000000
"""
# TODOs
# dedup/verify triple lines?
# verify parity bits on data bytes
# parse id and channel bits for info?
WIND_DIRECTIONS_CARDINAL = [
"NNW",
"NW",
"WNW",
"W",
"WSW",
"SW",
"SSW",
"S",
"SSE",
"SE",
"ESE",
"E",
"ENE",
"NE",
"NNE",
"N" ]
def checksum(bytes):
""" verify checksum """
# sum of first seven bytes modulo 256 should equal eighth byte
total = 0
checksum = bytes[7]
for i in range(7):
total += bytes[i]
if total % 256 == checksum:
return True
else:
return False
def getTemp(bytes):
# range: -40 to 158 F
highbits = ( bytes[4] & 0x0F ) << 7
lowbits = bytes[5] & 0x7F
rawtemp = highbits | lowbits
temp = (rawtemp - 400) / 10.0
return temp
def getWindSpeed(bytes):
# range: 0 to 159 kph
highbits = ( bytes[3] & 0x1F ) << 3
lowbits = ( bytes[4] & 0x70 ) >> 4
speed = highbits | lowbits
return speed
def getWindDirection(bytes):
# range: 16 compass points, ccw from (NNW) to 15 (N)
direction = bytes[4] & 0x0F
return WIND_DIRECTIONS_CARDINAL[direction]
def getHumidity(bytes):
# range: 1% to 99% RH
humidity = bytes[6] & 0x7F
return humidity
def getRainfall(bytes):
# rolling? counter increments 0.01 in
# 0 to 99.99 in range
raincounter = bytes[6] & 0x7F
return raincounter
for line in fileinput.input(bufsize=1):
match = re.search('\[\d+\] {6\d} ([^:]+)', line)
if match:
bytestring = match.group(1).split() # payload
bytes = [ int(b, 16) for b in bytestring ]
if checksum(bytes):
if bytes[2] & 0x0F == 1:
# wind speed, wind direction, rainfall
print "wind speed, kph:", getWindSpeed(bytes)
print "wind direction:", getWindDirection(bytes)
print "rain counter (0.01 in incr):", getRainfall(bytes)
elif bytes[2] & 0x0F == 8:
# wind speed, temp, rh
print "wind speed, kph:", getWindSpeed(bytes)
print "temp, F:", getTemp(bytes)
print "humidity, %:", getHumidity(bytes)
print "----"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment