Subversion Repositories yaws

Rev

Rev 19 | Details | Compare with Previous | Last modification | View Log | RSS feed

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