An IoT product based on FreeRTOS, using CoAP for communication, changing a LED band's colors at 60Hz based on audio frequency and amplitude, captured using a microphone (at 44.1 kHz).
2023-05-31 20:10:24 +03:00
components improved frequency analysis and debug mode 2023-05-28 22:54:35 +03:00
main fixed memleak and modes 2023-05-29 22:36:40 +03:00
.gitignore updated to esp-idf v5, keeping deprecated usage 2023-05-16 16:03:23 +03:00
.gitmodules fixed fft-c module config 2021-07-13 11:49:58 +03:00
CMakeLists.txt initial commit 2021-07-13 11:41:25 +03:00
dependencies.lock improved frequency analysis and debug mode 2023-05-28 22:54:35 +03:00
LICENSE added License, updated Readme, minor refactoring 2021-07-13 16:56:50 +03:00
Makefile initial commit 2021-07-13 11:41:25 +03:00
README.md updated readme 2021-07-26 17:59:13 +03:00
sdkconfig.defaults optimized app flash usage and partition size increased 2023-05-31 20:10:24 +03:00
system_diagram added system diagram 2021-07-13 15:49:01 +03:00
system_diagram.png added system diagram 2021-07-13 15:49:01 +03:00

Algorythm

Free / Libre open source IoT product based on ESP32, using CoAP for communication, powering a RGB LED band with changing colors at 60 Hz based on audio frequency and changing color intensity based on amplitude, using a microphone with audio sampling at 44.1 kHz

Algorythm Project Presentation

You can download the android app's source code here

Installing

System Diagram

Software Prerequisites

  • ESP-IDF environment: See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Hardware Prerequisites

  • If you're plugging this into a home socket, you will need an AC-DC 12V converter.
  • 12V-5V DC-DC converter (to power the esp32).
  • LED driver: See this schematic for setting up a LED driver. Specifically look at the LED Out section of the schematic. From that section eliminate the 1K resistors, those aren't needed.
  • Microphone with amp: Electret Microphone Amplifier - MAX9814 with Auto Gain Control or similar. (Auto Gain not necessary)
  • 12V RGB Led band.

Functioning modes

  • MANUAL: Has one color set manually
  • AUDIO_INTENSITY: Color intensity varies with audio amplitude
  • AUDIO_FREQ: Color changes with audio frequencies
  • AUDIO: Color changes with audio frequencies and intensity varies with audio amplitude
  • OFF: Leds will not light up
  • AUDIO_HOLD: Color changes with audio frequencies and intensity varies with audio amplitude. When amplitude is under the minimum, the last color set is shown.

Configure the project

idf.py menuconfig

Algorythm Project Configuration --->

  • If PSK enabled, Set CoAP Preshared Key to use in the connection to the server
  • Set WiFi SSID
  • Set WiFi Password
  • Set the mDNS hostname for the board to use in the internal WiFi network
  • Set the mDNS instance name for the board to use in the internal WiFi network (this is best left as it is, the android application uses this string to identify nodes)

Component config > CoAP Configuration --->

  • Set encryption method definition, PSK (default) or PKI
  • Enable CoAP debugging if required

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py build
idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

CoAP Endpoints

Currently both DTLS (port 5684) and insecure connections (port 5683) are available, however once development reaches release status the server will be changed to DTLS only.

These are the CoAP endpoints that the server makes available for clients:

  • /room (Fetch / change a room name to identify where you've placed the device)
  • /rgb (Fetch / change the RGB color in manual mode)
  • /mode (Fetch mode / set the device to function in one of multiple modes)
  • /prefs (Fetch configuration / set device configuration)

If you're using npm there is a command line tool which makes debugging CoAP easy: coap-cli

For example to change the room name using the CoAP endpoint:

$ echo -n 'desk' | coap put coap://10.0.0.120/room
(2.04)

To ensure the endpoint stores the new value:

$ coap get coap://10.0.0.120/room
(2.05)  desk

The IP 10.0.0.120 might not be the one your device was assigned, check the troubleshooting section below.

NOTE: Client sessions trying to use coaps+tcp:// are not currently supported, even though both libcoap and MbedTLS support it.

The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained networks in the Internet of Things.
The protocol is designed for machine-to-machine (M2M) applications such as smart energy and building automation.

Please refer to RFC7252 for more details.

libcoap Documentation

This can be found at https://libcoap.net/doc/reference/4.2.0/

Troubleshooting

  • You should be able to find the IP of the esp32 board by watching the serial output with:
idf.py -p PORT monitor
  • You can also find the IP of the esp32 board using dig:
$ dig @224.0.0.251 -p 5353 -t ptr +short _http._tcp.local
LEDSINSTANCEMDNS._http._tcp.local.
0 0 80 LEDSHOST-A0B000.local.
"prefs=Undefined" "mode=Undefined" "rgb=Undefined" "room=Undefined"
$ dig @224.0.0.251 -p 5353 +short LEDSHOST-A0B000.local
10.0.0.120
  • Please make sure CoAP client fetches or puts data under path: /room or fetches /.well-known/core

  • CoAP logging can be enabled by running 'idf.py menuconfig -> Component config -> CoAP Configuration' and setting appropriate log level

  • You can debug the microphone input by changing DEBUG_MIC_INPUT to 1

TODO

  • Setup CoAP DTLS only