From 108f7c32e5c678d5edeff74e27ada4485ab8004b Mon Sep 17 00:00:00 2001 From: msp Date: Tue, 25 Oct 2022 17:07:50 -0400 Subject: [PATCH] try to improve net... might not have failed --- main/espd.c | 17 +++++++++++------ main/espd.h | 1 + main/pdmain.c | 1 - wifi/net.c | 11 ++++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/main/espd.c b/main/espd.c index 6978ef3..fcdcb76 100644 --- a/main/espd.c +++ b/main/espd.c @@ -126,14 +126,19 @@ void pd_pollhost( void) void pdmain_print( const char *s) { - char y[80]; + char y[81]; strncpy(y, s, 79); y[79]=0; + strcat(y, ";"); ESP_LOGI(TAG, "post %d: %s", strlen(y), y); #ifdef PD_USE_BLUETOOTH if (strlen(y) > 0) pd_bt_writeback((unsigned char *)y, strlen(y)); #endif +#ifdef PD_USE_WIFI + net_sendudp(y, strlen(y), CONFIG_ESP_WIFI_SENDPORT); + net_sendtcp(y, strlen(y)); +#endif } void trymem(int foo); @@ -178,6 +183,11 @@ void app_main(void) bt_init(); #endif sd_init(); +#ifdef PD_USE_WIFI + ESP_LOGI(TAG, "[ 1a ] start network"); + wifi_init(); + net_init(); +#endif ESP_LOGI(TAG, "[ 2 ] now write some shit"); @@ -209,10 +219,5 @@ void sd_init( void) // Initialize SD Card peripheral audio_board_sdcard_init(set, SD_MODE_1_LINE); -#ifdef PD_USE_WIFI - ESP_LOGI(TAG, "[ 1a ] start network"); - wifi_init(); - net_init(); -#endif ESP_LOGI(TAG, "[ 1b ] done starting network"); } diff --git a/main/espd.h b/main/espd.h index e7f31e7..5556f20 100644 --- a/main/espd.h +++ b/main/espd.h @@ -26,4 +26,5 @@ void wifi_init(void); /* wifi.c - manage 802.11 connection */ void net_init( void); /* init */ void net_alive( void); /* send keep-alive packet if needed */ void net_sendudp(void *msg, int len, int port); /* send whatev */ +void net_sendtcp(void *msg, int len); #endif diff --git a/main/pdmain.c b/main/pdmain.c index 279d40f..1ec1112 100644 --- a/main/pdmain.c +++ b/main/pdmain.c @@ -15,7 +15,6 @@ void pd_init(void); void glob_open(t_pd *ignore, t_symbol *name, t_symbol *dir, t_floatarg f); -extern t_printhook sys_printhook; void pdmain_print( const char *s); diff --git a/wifi/net.c b/wifi/net.c index 018aeae..031e6f7 100644 --- a/wifi/net.c +++ b/wifi/net.c @@ -86,6 +86,11 @@ void net_init( void) udp_out_addr.sin_port = htons(CONFIG_ESP_WIFI_SENDPORT); xTaskCreate(udpreceivertask, "udprcv", 6000, NULL, PRIORITY_WIFI, NULL); + while (!tcp_socket) + { + ESP_LOGE(TAG, "sendtcp: waiting for socket"); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } } static int64_t whensent; @@ -111,10 +116,10 @@ void net_sendudp(void *msg, int len, int port) void net_sendtcp(void *msg, int len) { int err; - while (!tcp_socket) + if (!tcp_socket) { - ESP_LOGE(TAG, "sendtcp: waiting for socket"); - vTaskDelay(1000 / portTICK_PERIOD_MS); + ESP_LOGE(TAG, "sendtcp: no socket yet"); + return; } err = send(tcp_socket, msg, len, 0); if (err < 0)