|
@@ -15,6 +15,11 @@ import logging
|
|
|
from rpi_rf import RFDevice
|
|
from rpi_rf import RFDevice
|
|
|
VOLTAGE = 0
|
|
VOLTAGE = 0
|
|
|
AMPERE = 1
|
|
AMPERE = 1
|
|
|
|
|
+
|
|
|
|
|
+# min samples in a row stable to be accepted as new value
|
|
|
|
|
+STABLE_COUNT = 3
|
|
|
|
|
+# max diff which is considered stable between new values
|
|
|
|
|
+STABLE_DIFF_THRESHOLD = .1
|
|
|
rfdevice = None
|
|
rfdevice = None
|
|
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
# pylint: disable=unused-argument
|
|
@@ -30,10 +35,12 @@ parser.add_argument('-g', dest='gpio', type=int, default=27,
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, exithandler)
|
|
signal.signal(signal.SIGINT, exithandler)
|
|
|
-rfdevice = RFDevice(args.gpio)
|
|
|
|
|
|
|
+rfdevice = RFDevice(args.gpio, rx_tolerance=80)
|
|
|
rfdevice.enable_rx()
|
|
rfdevice.enable_rx()
|
|
|
timestamp = None
|
|
timestamp = None
|
|
|
logging.info("Listening for codes on GPIO " + str(args.gpio))
|
|
logging.info("Listening for codes on GPIO " + str(args.gpio))
|
|
|
|
|
+previous_values = {}
|
|
|
|
|
+counts = {}
|
|
|
while True:
|
|
while True:
|
|
|
if rfdevice.rx_code_timestamp != timestamp:
|
|
if rfdevice.rx_code_timestamp != timestamp:
|
|
|
timestamp = rfdevice.rx_code_timestamp
|
|
timestamp = rfdevice.rx_code_timestamp
|
|
@@ -42,24 +49,31 @@ while True:
|
|
|
value = (code >> 8) / 1000.
|
|
value = (code >> 8) / 1000.
|
|
|
U = 0
|
|
U = 0
|
|
|
I = 0
|
|
I = 0
|
|
|
- if codeType == VOLTAGE or True:
|
|
|
|
|
- logging.info("Voltage")
|
|
|
|
|
- U = value
|
|
|
|
|
- client.write_points([
|
|
|
|
|
- {
|
|
|
|
|
- "measurement": "solar",
|
|
|
|
|
- "tags": {
|
|
|
|
|
- "type": "U"
|
|
|
|
|
- },
|
|
|
|
|
- "fields": {
|
|
|
|
|
- "value": U
|
|
|
|
|
|
|
+ if value:
|
|
|
|
|
+ if codeType in previous_values and abs(previous_values[codeType]-value) <= STABLE_DIFF_THRESHOLD:
|
|
|
|
|
+ counts[codeType] += 1
|
|
|
|
|
+ else:
|
|
|
|
|
+ counts[codeType] = 0
|
|
|
|
|
+ previous_values[codeType] = value
|
|
|
|
|
+ logging.info("Data Received: " + str(code) + "/" + str(codeType) + " / " + str(value))
|
|
|
|
|
+ if codeType in counts and counts[codeType] >= STABLE_COUNT:
|
|
|
|
|
+ if codeType == VOLTAGE or True:
|
|
|
|
|
+ U = value
|
|
|
|
|
+ logging.info("Stable Voltage:" +str(U))
|
|
|
|
|
+ client.write_points([
|
|
|
|
|
+ {
|
|
|
|
|
+ "measurement": "solar",
|
|
|
|
|
+ "tags": {
|
|
|
|
|
+ "type": "U"
|
|
|
|
|
+ },
|
|
|
|
|
+ "fields": {
|
|
|
|
|
+ "value": U
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- ], time_precision='ms')
|
|
|
|
|
- if codeType == AMPERE:
|
|
|
|
|
- logging.info("Ampere")
|
|
|
|
|
- I = value
|
|
|
|
|
-
|
|
|
|
|
- logging.info(str(code) + "/" + str(codeType) + ", U=" + str(U))
|
|
|
|
|
- time.sleep(0.01)
|
|
|
|
|
|
|
+ ], time_precision='ms')
|
|
|
|
|
+ if codeType == AMPERE:
|
|
|
|
|
+ logging.info("Ampere")
|
|
|
|
|
+ I = value
|
|
|
|
|
+
|
|
|
|
|
+ time.sleep(0.05)
|
|
|
rfdevice.cleanup()
|
|
rfdevice.cleanup()
|