Hi everyone!
I am receiving packets from TinyTX node on my raspberry pi and they look like:
Got: 16 166 19 192 12 156 9
-> ack
Got: 16 116 19 164 12 146 9
-> ack
I would like to decode those but...
How?
Some informations are here:
http://jeelabs.org/2010/12/07/binary-packet-decoding/
I've found various way to decipher this encoding in python but I always get incredible (and obviously false) values:
def rread_data(rx):
data = rx.split(" ")
a = int(data[1])
b = int(data[2])
c = int(data[3])
d = int(data[4])
e = int(data[5])
f = int(data[6])
# node_id = str(int(data[0]) & 0x1f)
humidity = str((a+b*256)/100.0)
voltage = str(c+d*256)
temperature = str((e+f*256)/100.0)
# print "node:", node_id
print "humidity:", humidity, "%"
print "temperature:", temperature, "C"
print "voltage:", voltage, "mV"
This data is coming from a DHT22 sensor and it should include temp, humidity and voltage...
What can I read to understand better what to do?
Thanks to everyone reading.
Re: [SOLVED] Decode incoming packets from TinyTX to Raspberry Pi serial in Python
I'd start by reading and understanding the code loaded onto the TinyTx.
Re: [SOLVED] Decode incoming packets from TinyTX to Raspberry Pi serial in Python
Here is, for anyone interested, the working function in python:
import serial
import string
from time import sleep
import MySQLdb
import MySQLdb as Database
from warnings import filterwarnings
filterwarnings('ignore', category = Database.Warning)
import smtplib
from email.mime.text import MIMEText
# Specify your serial port path (/dev/ttyAMA0 is default for Raspberry Pi)
serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0)
# This function reads data from serial port and prints received values in human readable format
def read_data(rx):
data = rx.lstrip().split(" ")
a = int(data[1])
b = int(data[2])
c = int(data[3])
d = int(data[4])
e = int(data[5])
f = int(data[6])
node_id = str(int(data[0]) & 0x1f)
humidity = str((a+b*256)/100.0)
voltage = str(c+d*256)
temperature = str((e+f*256)/100.0)
print "node:", node_id
print "humidity:", humidity, "%"
print "temperature:", temperature, "C"
print "voltage:", voltage, "mV"
try_number = 0
while True:
data = serialport.read(9999)
if len(data) > 0:
print "Got data: "+data
read_data(data)
sleep(1)
try_number += 1
print 'Waiting data... '+str(try_number)
ser.close()