summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-09-18 21:50:55 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-09-18 21:50:55 +0300
commita69344d91a7cb2a0121b48daf94503bbe8b390a5 (patch)
tree0babd7c46362d19bce25fa92bc146441b553afae
parent52544fdacd0d7dc24424c2aacaebe1c5df5577d8 (diff)
sound_sensor_node: add threshold configuration option
-rw-r--r--doc/sound_sensor_node.md10
-rw-r--r--src/home/soundsensor/node.py4
-rwxr-xr-xsrc/sound_sensor_node.py1
3 files changed, 14 insertions, 1 deletions
diff --git a/doc/sound_sensor_node.md b/doc/sound_sensor_node.md
new file mode 100644
index 0000000..0ec24e6
--- /dev/null
+++ b/doc/sound_sensor_node.md
@@ -0,0 +1,10 @@
+## Configuration
+
+`/etc/sound_sensor_node.toml`:
+```toml
+[node]
+name = "diana"
+pin = "PC0"
+server_addr = "192.168.1.2:8311"
+threshold = 10
+``` \ No newline at end of file
diff --git a/src/home/soundsensor/node.py b/src/home/soundsensor/node.py
index b4b8fbc..292452f 100644
--- a/src/home/soundsensor/node.py
+++ b/src/home/soundsensor/node.py
@@ -16,6 +16,7 @@ class SoundSensorNode:
name: str,
pinname: str,
server_addr: Optional[Addr],
+ threshold: int = 1,
delay=0.005):
if not hasattr(gpioport, pinname):
@@ -24,6 +25,7 @@ class SoundSensorNode:
self.pin = getattr(gpioport, pinname)
self.name = name
self.delay = delay
+ self.threshold = threshold
self.server_addr = server_addr
@@ -43,7 +45,7 @@ class SoundSensorNode:
hits = self.hits
self.hits = 0
- if hits > 0:
+ if hits >= self.threshold:
try:
if self.server_addr is not None:
send_datagram(stringify([self.name, hits]), self.server_addr)
diff --git a/src/sound_sensor_node.py b/src/sound_sensor_node.py
index c5f21a3..d9a8999 100755
--- a/src/sound_sensor_node.py
+++ b/src/sound_sensor_node.py
@@ -27,6 +27,7 @@ if __name__ == '__main__':
node = SoundSensorNode(name=config['node']['name'],
pinname=config['node']['pin'],
+ threshold=config['node']['threshold'] if 'threshold' in config['node'] else 1,
server_addr=server_addr,
**kwargs)
node.run()