@@ -25,9 +25,19 @@ definition(
25
25
26
26
27
27
preferences {
28
- section(" Monitor These Devices" ) {
29
- input " t_devices" , " capability.temperatureMeasurement" , required : true , title : " Temperature" , multiple : true
30
- }
28
+ section(" Collect Metrics" ) {
29
+ input " co2_devices" , " capability.carbonDioxideMeasurement" , required : false , title : " Carbon Dioxide" , multiple : true
30
+ input " i_devices" , " capability.illuminanceMeasurement" , required : false , title : " Illuminance" , multiple : true
31
+ input " ph_devices" , " capability.phMeasurement" , required : false , title : " pH" , multiple : true
32
+ input " rh_devices" , " capability.relativeHumidityMeasurement" , required : false , title : " Relative Humidity" , multiple : true
33
+ input " t_devices" , " capability.temperatureMeasurement" , required : false , title : " Temperature" , multiple : true
34
+ input " v_devices" , " capability.voltageMeasurement" , required : false , title : " Voltage" , multiple : true
35
+ }
36
+
37
+ section(" Publish Metrics" ) {
38
+ input " datadrop_bin" , type : " text" , required : true , title : " Wolfram Data Drop Bin ID"
39
+ input " period" , type : " number" , required : true , title : " Period, min" , defaultValue : 15
40
+ }
31
41
}
32
42
33
43
def installed () {
@@ -52,28 +62,37 @@ def initialize() {
52
62
log. debug " [metrics] initialized"
53
63
}
54
64
55
- def publishMetrics () {
56
- log. debug " [metrics] publishMetrics"
57
-
58
- t_devices. each{ d ->
59
- def params = [
60
- uri : ' https://datadrop.wolframcloud.com/api/v1.0/Add' ,
61
- query : [bin :' lYr1BSA8' ,
62
- t : d. currentValue(" temperature" ),
63
- n : d. displayName]
64
- ]
65
+ def publishDevice (device , parameterName ) {
66
+ def params = [
67
+ uri : ' https://datadrop.wolframcloud.com/api/v1.0/Add' ,
68
+ query : [bin :datadrop_bin,
69
+ v : d. currentValue(parameterName),
70
+ n : device. displayName]
71
+ ]
65
72
66
- log. debug " [metrics] publishing ${ params} "
73
+ log. debug " [metrics] publishing ${ params} "
67
74
68
- try {
69
- httpGet(params) { resp ->
70
- resp. headers. each {
71
- log. debug " ${ it.name} : ${ it.value} "
72
- }
73
- log. debug " [metrics] response status: ${ resp.status} "
74
- }
75
- } catch (e) {
76
- log. error " [metrics] exception: $e "
75
+ try {
76
+ httpGet(params) { resp ->
77
+ log. debug " [metrics] response status: ${ resp.status} "
77
78
}
78
- }
79
+ } catch (e) {
80
+ log. error " [metrics] exception: $e "
81
+ }
82
+ }
83
+
84
+ def publishMetrics () {
85
+ log. debug " [metrics] publishMetrics binid: ${ datadrop_bin} ${ period} "
86
+
87
+ if (datadrop_bin == " " ) {
88
+ log. error " [metrics] error: datadrop bin not set"
89
+ return
90
+ }
91
+
92
+ co2_devices. each{ d -> publishDevice(d, " carbonDioxide" ) }
93
+ i_devices. each{ d -> publishDevice(d, " illuminance" ) }
94
+ ph_devices. each{ d -> publishDevice(d, " pH" ) }
95
+ rh_devices. each{ d -> publishDevice(d, " humidity" ) }
96
+ t_devices. each{ d -> publishDevice(d, " temperature" ) }
97
+ v_devices. each{ d -> publishDevice(d, " voltage" ) }
79
98
}
0 commit comments