Detect sound using ESP32 and notify over WiFi
esp32_sound_detector
- ESP32 code for detecting noise using KY-038 and sending a UDP packet over WiFinotifier
- Python server that waits for the UDP packet and sends a desktop notification
- Install esp-idf
- An AUR package for Arch Linux is available esp-idf
- Install toolchain
# By default installs to $HOME/.espressif /opt/esp-idf/install.sh esp32
- Load environment variables
. /opt/esp-idf/export.sh
- Build and flash using
idf.py
commandscd esp32_sound_detector # Set the basic esp32 as target device # Not required on an existing preconfigured project such as this one idf.py set-target esp32 # Configure the "WiFi Connection" and "Sound Notification" sections # Define the IP and Port to send the UDP packet to # Define secret to filter out stray unrelated packets # (If you're sending packets to a broadcast IP the secret can be easily discovered in the LAN) # Menuconfig is also be used for switching features and flags such as log level idf.py menuconfig # Build # Run the wrapper script instead of `idf.py build` for better LSP support ./build.sh # If you encounter a permission problems under Arch, make sure you are part of the uucp group sudo usermod -a -G uucp $USER newgrp uucp # or reboot # Connect the device and flash it, USB serial should be detected automatically # flashing will also rebuild automatically if files have changed idf.py flash # Read ESP32 serial output idf.py monitor
- Make sure
libnotify
is installed asnotify-send
is used - Make sure a notification server such as
dunst
is installed - Test the script with parameters you have configured in the ESP
# Listen on 192.168.1.1:12100 for packets with secret "ABC" and send the notification "GotIt" python notifier/notifier.py 192.168.1.1 12100 ABC GotIt # Listen on broadcast IP 192.168.1.255:10000 for packets with secret "Secret" and send the notification "OK" python notifier/notifier.py 192.168.1.255 10000 Secret OK
- To setup a SystemD service, copy the supplied template file
notifier/sound-notifier.service.template
and edit the parameters