Subversion Repositories yaws

Rev

Rev 6 | Rev 14 | 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
#
13 ron 24
cfgPath = './yaws.cfg'
25
 
6 ron 26
import database as db
27
from gpiozero import CPUTemperature
28
import time
29
import sensors
1 ron 30
 
6 ron 31
AirTemp = None
32
GndTemp = None
33
Pressure = None
34
Humidity = None
35
WindSpeed = None
36
WindDirection = None
37
Rain =  None
38
Rainfall = None
39
Sunlight = None
40
CPUTemp = None
1 ron 41
 
42
def main(args):
13 ron 43
    conn = db.samples.create_connection(dbPath)
6 ron 44
    while True:
45
        # get Air tph
46
        data = sensors.tph.read_tph()
47
        AirTemp = data[0]
48
        Pressure = data[1]
49
        Humidity = data[2]
50
 
51
        # get Ground temperature
52
 
53
        # get Rain info
54
        data = sensors.rain.read_rain()
55
        Rain = data[0]
56
        Rainfall = data[1]
57
 
58
        # get Wind info
59
        data = sensors.wind.read_wind()
60
        WindDirection = data[0]
61
        WindSpeed = data[1]
62
 
63
        # get light level
64
        Sunlight = sensors.light.read_light()
65
 
66
        # get CPU Temp
67
        CPUTemp = CPUTemperature()
68
 
69
        Sample = db.Samples(airtemp = AirTemp, gndtemp = GndTemp,
70
            pressure = Pressure, humidity = Humidity, windspeed = WindSpeed,
71
            direction = WindDirection, rain = Rain, rainfall = Rainfall,
72
            sunlight = Sunlight, cputemp = float(CPUTemp.temperature))
73
        db.session.add(Sample)
74
        db.session.commit()
75
        time.sleep(60)
76
    return 0
1 ron 77
 
78
if __name__ == '__main__':
79
    import sys, configparser
80
    cfg = configparser.ConfigParser()
81
    cfg.read(cfgPath)
82
    dbPath = cfg['global']['dbPath']
83
    sys.exit(main(sys.argv))