Sample Python code to read from Weather-board

Moderators: mdrjr, odroid

Sample Python code to read from Weather-board

Unread postby glenno » Sat Apr 25, 2015 4:04 pm

Hi all,
Im a novice with Python 3, however I thought others might benefit from my snippet of code showing how to read the sensor feed on the USB port.

For those interested, im hoping to have multiple sensors around the office posting their sensor readings back via a RESTful API to a central Odroid-XU which is running Python 3 and Cherrypy and will have graphing and historical logging etc. All running ArchlinuxARM.

This code just shows how im reading the data every ~5secs. Hope it helps someone with their project.

Code: Select all
import serial
import time
x=0
while x<1:
    ser = serial.Serial('/dev/ttyUSB0', 500000, timeout=2)
    line = ser.readline(75)
    ser.close()
    tempreading=str(line.decode('utf-8'))
    print('Decoded String=',tempreading)
    print('BMP Temp =      ',tempreading[2:7],'Deg C')
    print('Pressure =      ',tempreading[10:16],'Pa')
    print('Altitude =      ',tempreading[19:25],'Meters')
    print('Si7020 Temp =   ',tempreading[28:33],'Deg C')
    print('Humidity =      ',tempreading[36:42],' %')
    print('UV Index =      ',tempreading[44:49],)
    print('Visible Light = ',tempreading[51:54],'Lux')
    print('IR Light =      ',tempreading[56:59],'Lux')
    deltatemp=round(float(tempreading[2:7])-float(tempreading[28:33]),2)
    print('Difference between Temp sensors',str(deltatemp))
    time.sleep(4)
glenno
 
Posts: 9
Joined: Sun Nov 23, 2014 8:34 am
languages_spoken: english
ODROIDs: Odroid X, XU, XU4, SHOW2, Weather

Re: Sample Python code to read from Weather-board

Unread postby miller5083 » Wed Oct 25, 2017 8:47 pm

Looking forward to trying this out, have you run this with multiple weatherboards?
miller5083
 
Posts: 3
Joined: Wed Oct 25, 2017 8:45 pm
languages_spoken: english
ODROIDs: XU4

Re: Sample Python code to read from Weather-board

Unread postby glenno » Sat Nov 25, 2017 10:48 am

No I havent as yet. I wrote the server side component that received the API call from the remote unit and saved it to a database. Making it scalable from there isnt hard ie each remote unit just needs to post its ID as part of the API call. And if you wanted to have multiple sensors per device they just show up as different USB ports.
glenno
 
Posts: 9
Joined: Sun Nov 23, 2014 8:34 am
languages_spoken: english
ODROIDs: Odroid X, XU, XU4, SHOW2, Weather


Return to SHOW

Who is online

Users browsing this forum: No registered users and 1 guest