summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--esp32/main/Kconfig.projbuild.example1
-rw-r--r--esp32/main/main.c70
-rw-r--r--recv.py2
3 files changed, 40 insertions, 33 deletions
diff --git a/esp32/main/Kconfig.projbuild.example b/esp32/main/Kconfig.projbuild.example
index 9c03e2b..a3b2547 100644
--- a/esp32/main/Kconfig.projbuild.example
+++ b/esp32/main/Kconfig.projbuild.example
@@ -27,3 +27,4 @@ menu "Mimir Configuration"
endmenu
+
diff --git a/esp32/main/main.c b/esp32/main/main.c
index 7ddcf5e..d18b137 100644
--- a/esp32/main/main.c
+++ b/esp32/main/main.c
@@ -1,5 +1,4 @@
#include <errno.h>
-#include <sys/param.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
@@ -7,7 +6,6 @@
#include <esp_event.h>
#include <esp_log.h>
#include <esp_netif.h>
-#include <esp_system.h>
#include <nvs_flash.h>
#include <driver/gpio.h>
@@ -29,6 +27,10 @@
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)
@@ -37,39 +39,12 @@ static void i2s_read_task(void *args)
size_t n;
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) {
- rc = sendto(sock, buf, n, 0, (struct sockaddr *)&dest_addr,
- sizeof(dest_addr));
+ rc = sendto(sock, buf, n, 0, sock_addr, sock_addr_len);
if (rc < 0)
ESP_LOGE(TAG, "sendto() failed: %s", strerror(errno));
}
@@ -113,6 +88,39 @@ 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)
@@ -130,5 +138,3 @@ void app_main(void)
for (;;)
vTaskDelay(500 / portTICK_PERIOD_MS);
}
-
-
diff --git a/recv.py b/recv.py
index 900b765..66ad203 100644
--- a/recv.py
+++ b/recv.py
@@ -16,7 +16,7 @@ try:
while datetime.datetime.now() < read_until:
msg, _ = sock.recvfrom(1024)
- print(msg)
wav.writeframes(msg)
+ print("writing data")
finally:
wav.close()