ws works
This commit is contained in:
parent
c104a44f32
commit
b9f8e90dd7
@ -169,8 +169,11 @@ async def run(ws, path):
|
||||
elif (len(message) == 3 and message[1] == "3440"):
|
||||
client = await new_boat(message[0], message[2], ws)
|
||||
if client is not None:
|
||||
async for message in ws:
|
||||
print("boat" + client['id'] + " says '" + message + "'")
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
print("boat" + client['id'] + " says '" + message + "'")
|
||||
break
|
||||
|
||||
async def main():
|
||||
|
||||
@ -154,7 +154,6 @@ void app_main() {
|
||||
MainState = STATE_WS_WAIT_CONNECTION;
|
||||
}
|
||||
|
||||
// charIn = ws_getchar(ws_client);
|
||||
while ((charIn = ws_getchar(ws_client)) != 255)
|
||||
{
|
||||
CLI_charIn(&cli_ws_client, charIn);
|
||||
|
||||
@ -58,7 +58,7 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t
|
||||
else if (data->op_code == 0x01 && data->data_len > 0)
|
||||
{
|
||||
// LOG_D("ws_event_handler: cmd recieved (len: %d): '%.*s'", data->data_len, data->data_len, (char*) data->data_ptr);
|
||||
uint16_t sizeLeft = WS_RX_BUFFER_LEN + client->rxBuffer_rp - client->rxBuffer_wp;
|
||||
uint16_t sizeLeft = WS_RX_BUFFER_LEN + client->rxBuffer_rp - client->rxBuffer_wp - 1;
|
||||
if (sizeLeft > WS_RX_BUFFER_LEN)
|
||||
{
|
||||
sizeLeft -= WS_RX_BUFFER_LEN;
|
||||
@ -66,19 +66,20 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t
|
||||
|
||||
if (data->data_len <= sizeLeft)
|
||||
{
|
||||
if (WS_RX_BUFFER_LEN - client->rxBuffer_wp <= data->data_len)
|
||||
uint16_t leftOnEnd = WS_RX_BUFFER_LEN - client->rxBuffer_wp;
|
||||
if (leftOnEnd > data->data_len)
|
||||
{
|
||||
memcpy(&client->rxBuffer[client->rxBuffer_wp], data->data_ptr, data->data_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(&client->rxBuffer[client->rxBuffer_wp], data->data_ptr, sizeLeft);
|
||||
memcpy(&client->rxBuffer[0], data->data_ptr + sizeLeft, data->data_len - sizeLeft);
|
||||
memcpy(&client->rxBuffer[client->rxBuffer_wp], data->data_ptr, leftOnEnd);
|
||||
memcpy(&client->rxBuffer[0], data->data_ptr + leftOnEnd, data->data_len - leftOnEnd);
|
||||
}
|
||||
client->rxBuffer_wp += data->data_len;
|
||||
if (client->txBuffer_wp >= WS_RX_BUFFER_LEN)
|
||||
if (client->rxBuffer_wp >= WS_RX_BUFFER_LEN)
|
||||
{
|
||||
client->txBuffer_wp -= WS_RX_BUFFER_LEN;
|
||||
client->rxBuffer_wp -= WS_RX_BUFFER_LEN;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -120,6 +121,18 @@ ws_client_t ws_connect(char *url)
|
||||
|
||||
const esp_websocket_client_config_t ws_conf = {
|
||||
.uri = url
|
||||
// .disable_pingpong_discon = false,
|
||||
// .ping_interval_sec = 2,
|
||||
// .pingpong_timeout_sec = 1
|
||||
|
||||
// bool disable_auto_reconnect; /*!< Disable the automatic reconnect function when disconnected */
|
||||
// int buffer_size; /*!< Websocket buffer size */
|
||||
// bool keep_alive_enable; /*!< Enable keep-alive timeout */
|
||||
// int keep_alive_idle; /*!< Keep-alive idle time. Default is 5 (second) */
|
||||
// int keep_alive_interval; /*!< Keep-alive interval time. Default is 5 (second) */
|
||||
// int keep_alive_count; /*!< Keep-alive packet retry send count. Default is 3 counts */
|
||||
// int reconnect_timeout_ms; /*!< Reconnect after this value in miliseconds if disable_auto_reconnect is not enabled (defaults to 10s) */
|
||||
// int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
|
||||
};
|
||||
client->handle = esp_websocket_client_init(&ws_conf);
|
||||
esp_websocket_register_events(client->handle, WEBSOCKET_EVENT_ANY, ws_event_handler, (void *)client);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user