summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-09-08 16:01:40 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-09-08 16:01:40 +0800
commit65a58c9a20b87c630d617a472a4a84d3b794e665 (patch)
tree8622f70271686e2ca9748fdd5ddfcce736852608
parent9a3105d96c568c17a9e399a469100c4c84a5cb70 (diff)
downloadesp32-inmp441-driver-65a58c9a20b87c630d617a472a4a84d3b794e665.tar.gz
UDP is kind of working.
-rw-r--r--.gitignore4
-rw-r--r--esp32/CMakeLists.txt2
-rw-r--r--esp32/main/main.c73
-rw-r--r--recv.py3
4 files changed, 37 insertions, 45 deletions
diff --git a/.gitignore b/.gitignore
index c844696..dbc2745 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
+# Test artifacts
+**/*.wav
+
# Config
**/tickers.txt
**/Kconfig.projbuild
-
**/sdkconfig*
# Vim
diff --git a/esp32/CMakeLists.txt b/esp32/CMakeLists.txt
index 7de91bc..648cacb 100644
--- a/esp32/CMakeLists.txt
+++ b/esp32/CMakeLists.txt
@@ -3,4 +3,4 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-project(audtest)
+project(mimir)
diff --git a/esp32/main/main.c b/esp32/main/main.c
index 0c1b751..7ddcf5e 100644
--- a/esp32/main/main.c
+++ b/esp32/main/main.c
@@ -1,4 +1,4 @@
-#include <string.h>
+#include <errno.h>
#include <sys/param.h>
#include <freertos/FreeRTOS.h>
@@ -29,27 +29,49 @@
const char *TAG = "mimir";
-static int sock;
-static size_t sock_addr_len;
-static struct sockaddr *sock_addr;
-
static i2s_chan_handle_t chan;
static void i2s_read_task(void *args)
{
int rc;
size_t n;
- char *buf = calloc(1, BUFLEN + 1);
+ char *buf = calloc(1, BUFLEN);
+
+ char *ip_addr;
+ int family, port;
+ struct timeval timeout;
+ struct sockaddr_in dest_addr;
+
+ family = AF_INET;
+ port = CONFIG_UDP_PORT;
+ ip_addr = CONFIG_UDP_ADDR;
+
+ dest_addr.sin_addr.s_addr = inet_addr(ip_addr);
+ dest_addr.sin_family = family;
+ dest_addr.sin_port = htons(port);
+
+ int sock = socket(family, SOCK_DGRAM, IPPROTO_IP);
+
+ if (sock < 0) {
+ ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
+ return;
+ }
+
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+ setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout);
+
+ ESP_LOGI(TAG, "Socket created, sending to %s:%d", ip_addr, port);
ESP_ERROR_CHECK(i2s_channel_enable(chan));
for (;;) {
if (i2s_channel_read(chan, buf, BUFLEN, &n, 1000) == ESP_OK) {
if (n > 0) {
- buf[n] = '\0';
- rc = sendto(sock, buf, strlen(buf), 0, sock_addr, sock_addr_len);
+ rc = sendto(sock, buf, n, 0, (struct sockaddr *)&dest_addr,
+ sizeof(dest_addr));
if (rc < 0)
- ESP_LOGE(TAG, "sendto() failed: errno %d", errno);
+ ESP_LOGE(TAG, "sendto() failed: %s", strerror(errno));
}
} else
printf("Read Task: i2s read failed\n");
@@ -91,39 +113,6 @@ static inline void i2s_init(void)
static void udp_client_init(void)
{
- char *ip_addr;
- int family, port;
- struct timeval timeout;
- struct sockaddr_in *dest_addr;
-
- family = AF_INET;
- port = CONFIG_UDP_PORT;
- ip_addr = CONFIG_UDP_ADDR;
-
- sock = socket(family, SOCK_DGRAM, IPPROTO_IP);
-
- if (sock < 0) {
- ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
- return;
- }
-
- timeout.tv_sec = 10;
- timeout.tv_usec = 0;
- setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout);
-
- if (!(dest_addr = malloc(sizeof(dest_addr)))) {
- ESP_LOGE(TAG, "malloc() failed for destination address");
- return;
- }
-
- dest_addr->sin_addr.s_addr = inet_addr(ip_addr);
- dest_addr->sin_family = family;
- dest_addr->sin_port = htons(port);
-
- sock_addr = (struct sockaddr *) dest_addr;
- sock_addr_len = sizeof dest_addr;
-
- ESP_LOGI(TAG, "Socket created, sending to %s:%d", ip_addr, port);
}
void app_main(void)
diff --git a/recv.py b/recv.py
index d91a6d9..900b765 100644
--- a/recv.py
+++ b/recv.py
@@ -15,7 +15,8 @@ try:
sock.bind(('', 3333))
while datetime.datetime.now() < read_until:
- msg, _ = sock.recvfrom(1024)
+ msg, _ = sock.recvfrom(1024)
+ print(msg)
wav.writeframes(msg)
finally:
wav.close()