add code for websocker send

This commit is contained in:
Laila van Reenen 2024-08-08 19:18:06 +02:00
parent a83d4c70f4
commit 84ae8fdbdc
Signed by: LailaTheElf
GPG Key ID: 1F4E6EE3E6DDF769
4 changed files with 20 additions and 8 deletions

View File

@ -3,7 +3,7 @@ dependencies:
component_hash: null
source:
type: idf
version: 5.2.2
version: 5.4.0
manifest_hash: 0646c148cf0e35f84678cd2cb46e9929051a1c6db31905f3a584cca01fd1e49a
target: esp32c3
version: 1.0.0

View File

@ -6,13 +6,17 @@
// #define WIFI_SSID "UPC46273"
// #define WIFI_AUTH WIFI_AUTH_WPA_PSK
// #define WIFI_PASS "SPHZHKRY"
#define WIFI_SSID "Wifi Ding"
// #define WIFI_SSID "Wifi Ding"
// #define WIFI_AUTH WIFI_AUTH_WPA_WPA2_PSK
// #define WIFI_PASS "Weet ik niet."
#define WIFI_SSID "MBCBootjes"
#define WIFI_AUTH WIFI_AUTH_WPA_WPA2_PSK
#define WIFI_PASS "Weet ik niet."
#define WIFI_PASS "hetgrootedok"
#define UDP_PORT 1234
// #define UDP_PORT 1234
// static uint8_t BoatId = 1;
#define BOAT_NAME "Test boat"
static uint8_t BoatId = 1;
#define HISTORY // enable cli history
@ -25,7 +29,7 @@
#define SERVOS_CH6
#define WS_RX_BUFFER_LEN 512
#define WS_URL "ws://10.0.0.2:80/ws"
#define WS_URL "ws://10.254.0.2:8080/"
#define LOGGER_BUFFER_SIZE 65536

View File

@ -134,7 +134,7 @@ void app_main() {
case STATE_WS_CONNECTING:
ws_client = ws_connect(WS_URL);
cli_ws_client = CLI_init((CLI_charOutFn)&charOut_uart, cmdList);
cli_ws_client = CLI_init((CLI_charOutFn)&ws_putchar, cmdList);
MainState = STATE_WS_WAIT_CONNECTION;
break;
case STATE_WS_WAIT_CONNECTION:

View File

@ -17,6 +17,11 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t
case WEBSOCKET_EVENT_CONNECTED:
LOG_I("ws_event_handler: connected");
client->connected = true;
char str[100];
snprintf(&str[0], 100, "%04d;3440;" BOAT_NAME "\n", BoatId);
esp_websocket_client_send_text(client->handle, &str[0], strlen(str), 1000);
break;
case WEBSOCKET_EVENT_DISCONNECTED:
LOG_W("ws_event_handler: disconnected");
@ -125,4 +130,7 @@ int ws_getchar(ws_client_t client)
return out;
}
void ws_putchar(ws_client_t client, char c);
void ws_putchar(ws_client_t client, char c)
{
esp_websocket_client_send_text(client->handle, &c, 1, 1000); //TODO: convert RTOS tick in ms
}