Published: 21 Dec 2019 › Updated: 21 Dec 2019
Teaching myself Python Day 12
Today's learning consisted of learning how to parse the data stream from the USB attached wireless node collecting remote temperature data. The next step will be to store it to my MySQL temperature database.
Here is the code from today's learning:
import serial
# Open USB serial port attached to wireless receiver
serport = serial.Serial('/dev/ttyUSB0',115200)
while True:
# Read a line of data from wireless module
serdata = serport.readline()
# convert bytetype data to string data
sensordata = serdata.decode('UTF-8')
# if sensor data string starts with '#' symbol parse line of data
if sensordata[0] == '#':
# find start of sensor id
sidpos = sensordata.find('][') + 2
# find end of sensor id
sidend = sensordata.find(']', sidpos)
# find end of temp data
stpos = sensordata.find('[', sidend)
# get sensor id from string
senid = sensordata[sidpos: sidend]
if senid == '2':
senidname = 'Master'
elif senid == '10':
senidname = 'diningrm'
else:
senidname = 'None'
# get sensor temperature as float
sentemp = float(sensordata[sidend + 1: stpos])
print(sensordata)
print(senidname + ' ' + str(sentemp))
And here is a screen capture of the output from the program:
Leave Teaching myself Python Day 12 to:
Read more #ulog posts
Best Posts From My Technology Trail
We have not curated any of mytechtrail's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From My Technology Trail
- A walk on the Beach
- Mounting my QRP transceiver
- Field Day 2022
- Kit build - QRPGuys Digital FSK Transceiver III
- Antenna Tuner kit build
- Next kit build, QRPGuys power/SWR/dummy load
- Improved Ham Shack layout
- Second power pole distribution board
- My first Ham Radio Fox Hunt
- Putting first kit build to use
- First Contact
- Kit build session 2
- Kit build session 1
- A pile of Ham Radio projects
- Pi Day 3.14 Win
- Oh woe is me
- Homemade pizza for a quiet Sunday supper
- Reuse, Repair and Recycle
- Snow Day yesterday
- RFI testing my Ham Radio rig