-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsensor_external.py
140 lines (104 loc) · 5.53 KB
/
sensor_external.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
###########################################################################
# Sint Wind PI
# Copyright 2012 by Tonino Tarsi <[email protected]>
#
# Please refer to the LICENSE file for conditions
# Visit http://www.vololiberomontecucco.it
#
##########################################################################
"""This module defines the base sensorssimulator ."""
import threading
import time
import config
import random
import datetime
import _strptime
import sqlite3
from TTLib import *
import sys
import subprocess
import globalvars
import meteodata
import sensor_thread
import sensor
class Sensor_External(sensor.Sensor):
def __init__(self,cfg ):
sensor.Sensor.__init__(self,cfg )
self.last_time = None;
def Detect(self):
return True,"","",""
def GetData(self):
#print "GetData"
mydata = getCurrentMeteoDataFromUrl(self.cfg.external_sensor_path)
thetime = mydata["last_measure_time"]
if ( self.last_time == None or self.last_time != thetime):
self.last_time = thetime
log( "Newdata from External meteo.txt %s" % mydata["last_measure_time"] )
if (mydata["offline"] == 1):
self.offline = True
if ( self.cfg.offline == "False" ):
self.cfg.setOffline("1")
else:
self.offline = False
if ( self.cfg.offline == "True" ):
self.cfg.setOffline("0")
globalvars.meteo_data.last_measure_time = datetime.datetime.strptime(mydata["last_measure_time"],"[%d/%m/%Y-%H:%M:%S]")
globalvars.meteo_data.idx = datetime.datetime.strptime(mydata["idx"],"[%d/%m/%Y-%H:%M:%S]")
globalvars.meteo_data.status = 0
globalvars.meteo_data.hum_out = mydata["hum_out"]
globalvars.meteo_data.temp_out = mydata["temp_out"]
globalvars.meteo_data.abs_pressure = mydata["abs_pressure"]
globalvars.meteo_data.wind_ave = mydata["wind_ave"]
globalvars.meteo_data.wind_gust = mydata["wind_gust"]
globalvars.meteo_data.wind_dir = mydata["wind_dir"]
globalvars.meteo_data.wind_dir_code = mydata["wind_dir_code"]
globalvars.meteo_data.battery = mydata["battery"]
globalvars.meteo_data.rssi = mydata["rssi"]
if ( self.cfg.sensor_type.upper() == "EXTERNAL"):
globalvars.meteo_data.hum_out = mydata["hum_out"]
globalvars.meteo_data.temp_out = mydata["temp_out"]
globalvars.meteo_data.rain = mydata["rain"]
globalvars.meteo_data.illuminance = mydata["illuminance"]
globalvars.meteo_data.uv = mydata["uv"]
globalvars.meteo_data.wind_dir_ave = mydata["wind_dir_ave"]
globalvars.meteo_data.rel_pressure = mydata["rel_pressure"]
globalvars.meteo_data.rain = mydata["rain"]
globalvars.meteo_data.rain_rate = mydata["rain_rate"]
globalvars.meteo_data.wind_chill = mydata["wind_chill"]
globalvars.meteo_data.temp_apparent = mydata["temp_apparent"]
globalvars.meteo_data.dew_point = mydata["dew_point"]
globalvars.meteo_data.cloud_base_altitude = mydata["cloud_base_altitude"]
globalvars.meteo_data.uv = mydata["uv"]
globalvars.meteo_data.illuminance = mydata["illuminance"]
globalvars.meteo_data.winDayMin = mydata["winDayMin"]
globalvars.meteo_data.winDayMax = mydata["winDayMax"]
globalvars.meteo_data.winDayGustMin = mydata["winDayGustMin"]
globalvars.meteo_data.winDayGustMax = mydata["winDayGustMax"]
globalvars.meteo_data.TempOutMin = mydata["TempOutMin"]
globalvars.meteo_data.TempOutMax = mydata["TempOutMax"]
globalvars.meteo_data.TempInMin = mydata["TempInMin"]
globalvars.meteo_data.TempInMax = mydata["TempInMax"]
globalvars.meteo_data.UmOutMin = mydata["UmOutMin"]
globalvars.meteo_data.UmOutMax = mydata["UmOutMax"]
globalvars.meteo_data.UmInMin = mydata["UmInMin"]
globalvars.meteo_data.UmInMax = mydata["UmInMax"]
globalvars.meteo_data.PressureMin = mydata["PressureMin"]
globalvars.meteo_data.PressureMax = mydata["PressureMax"]
globalvars.meteo_data.rain_rate_24h = mydata["rain_rate_24h"]
globalvars.meteo_data.rain_rate_1h = mydata["rain_rate_1h"]
globalvars.meteo_data.wind_trend = mydata["wind_trend"]
sensor.Sensor.GetData(self)
seconds = datetime.datetime.now().second
if ( seconds < 30 ):
time.sleep(30-seconds)
else:
time.sleep(90-seconds)
time.sleep(10)
else:
time.sleep(20)
if __name__ == '__main__':
configfile = 'swpi.cfg'
cfg = config.config(configfile)
ss = Sensor_External(cfg)
while ( 1 ) :
ss.GetData()