-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherStationJson.py
66 lines (47 loc) · 2.19 KB
/
WeatherStationJson.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
#!/usr/bin/env python
##
# @package weatherStationJson package contains the method to create the JSON payload or the weather station
#
import logging
from ModbusConsts import ModbusConsts
class WeatherStationJson:
LOG = logging.getLogger( __name__ )
##
#
def getJsonPayload( self, decodedData, recordTime ):
jsonPayload = {}
jsonPayload[ModbusConsts.SLAVE_ID] = decodedData.get( ModbusConsts.SLAVE_ID )
jsonPayload[ModbusConsts.DEVICE_TYPE] = decodedData.get( ModbusConsts.DEVICE_TYPE )
jsonPayload[ModbusConsts.DEVICE_CATEGORY] = 'WST'#decodedData.get( ModbusConsts.DEVICE_CATEGORY )
jsonPayload[ModbusConsts.DEVICE_ID] = decodedData.get( ModbusConsts.DEVICE_ID )
#jsonData = {}
try:
data = decodedData.get( ModbusConsts.DATA )
if ModbusConsts.WST_WSNSR in data:
value = data.get( ModbusConsts.WST_WSNSR )
jsonPayload['module_temp'] = value
if ModbusConsts.WST_TEMP in data:
value = data.get( ModbusConsts.WST_TEMP )
jsonPayload['ambient_temp'] = value
if ModbusConsts.WST_HUMI in data:
value = data.get( ModbusConsts.WST_HUMI )
jsonPayload['humidity'] = value
if ModbusConsts.WST_RELAY in data:
value = data.get( ModbusConsts.WST_RELAY )
jsonPayload['relay'] = value
if ModbusConsts.WST_RAIN in data:
value = data.get( ModbusConsts.WST_RAIN )
jsonPayload['rain'] = value
if ModbusConsts.WST_WINDS in data:
value = data.get( ModbusConsts.WST_WINDS )
jsonPayload['wind_speed'] = value
if ModbusConsts.WST_WINDD in data:
value = data.get( ModbusConsts.WST_WINDD )
jsonPayload['wind_dir'] = value
if ModbusConsts.WST_ANLG1 in data:
value = data.get( ModbusConsts.WST_ANLG1 )
jsonPayload['irradiation'] = value
except Exception as e:
self.LOG.error('Error constructing WST json payload: %s', e)
#jsonPayload[ModbusConsts.DATA] = jsonData
return jsonPayload