Subversion Repositories yaws

Rev

Rev 1 | Rev 13 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#
4
#  yaws.py
5
#
6
#  Copyright 2020 Ron Wellsted <ron@wellsted.org.uk>
7
#
8
#  This program is free software; you can redistribute it and/or modify
9
#  it under the terms of the GNU General Public License as published by
10
#  the Free Software Foundation; either version 2 of the License, or
11
#  (at your option) any later version.
12
#
13
#  This program is distributed in the hope that it will be useful,
14
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
#  GNU General Public License for more details.
17
#
18
#  You should have received a copy of the GNU General Public License
19
#  along with this program; if not, write to the Free Software
20
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
#  MA 02110-1301, USA.
22
#
23
#
6 ron 24
import database as db
25
from gpiozero import CPUTemperature
26
import time
27
import sensors
1 ron 28
 
6 ron 29
AirTemp = None
30
GndTemp = None
31
Pressure = None
32
Humidity = None
33
WindSpeed = None
34
WindDirection = None
35
Rain =  None
36
Rainfall = None
37
Sunlight = None
38
CPUTemp = None
1 ron 39
 
40
def main(args):
41
    conn = create_connection(dbPath)
6 ron 42
    while True:
43
        # get Air tph
44
        data = sensors.tph.read_tph()
45
        AirTemp = data[0]
46
        Pressure = data[1]
47
        Humidity = data[2]
48
 
49
        # get Ground temperature
50
 
51
        # get Rain info
52
        data = sensors.rain.read_rain()
53
        Rain = data[0]
54
        Rainfall = data[1]
55
 
56
        # get Wind info
57
        data = sensors.wind.read_wind()
58
        WindDirection = data[0]
59
        WindSpeed = data[1]
60
 
61
        # get light level
62
        Sunlight = sensors.light.read_light()
63
 
64
        # get CPU Temp
65
        CPUTemp = CPUTemperature()
66
 
67
        Sample = db.Samples(airtemp = AirTemp, gndtemp = GndTemp,
68
            pressure = Pressure, humidity = Humidity, windspeed = WindSpeed,
69
            direction = WindDirection, rain = Rain, rainfall = Rainfall,
70
            sunlight = Sunlight, cputemp = float(CPUTemp.temperature))
71
        db.session.add(Sample)
72
        db.session.commit()
73
        time.sleep(60)
74
    return 0
1 ron 75
 
76
if __name__ == '__main__':
77
    import sys, configparser
78
    cfg = configparser.ConfigParser()
79
    cfg.read(cfgPath)
80
    dbPath = cfg['global']['dbPath']
81
    sys.exit(main(sys.argv))