Im working on a project, where a ESP32-S3 is configured to pop up as a RNDIS device when it's plugged in to the computer. THe device is set to a IP-adress of 2.2.2.2 and a mac-adress based on the EFUSE mac adress is set. After that a webserver is configured, that i can access from a browser. From the webserver im sending a array[512], which "works". But after some time the error accurs. I have tried adding the terminal as well as som code snippets.<br/>
<br/>
Heres the terminal<br/>
<IMG src="%5Battachment=0%5DCapture_terminal.PNG%5B/attachment%5D"><s></e></IMG><br/>
<br/>
The websocket written is initialised like the following:
<CODE><s>
Code: Select all
document.addEventListener("DOMContentLoaded", function () {
var ws;
function connect() {
//ws = new WebSocket('ws://' + window.location.hostname + '/ws');
ws = new WebSocket('ws://' + "2.2.2.2:80" + '/ws');
ws.onopen = function () {
// subscribe to some channels
ws.send(' ');
};
ws.onmessage = function (event) {
var emp = JSON.parse(event.data);
if (emp.hasOwnProperty('pct')) {
$('#display').html('<p>Uptime D:H:M:S : ' + dhm(emp.pct) + '</p>' + emp.time + '</p>Current DMX Adress: ' + Number(emp.cold).toFixed(1) + ' </p>Current DMX Mode:' + Number(emp.warm).toFixed(1) + '</p>');
$('#mainFooter').html('<p>Build : ' + emp.builddate + ' ' + emp.buildtime + '</p>');
}
if (emp.hasOwnProperty('log')) {
if (emp.log.charAt(0) === 'I') {
$('#log').append('<p class="log">' + emp.log + '</p>');
} else if (emp.log.charAt(0) === 'E') {
$('#log').append('<p class="logred">' + emp.log + '</p>');
} else {
$('#log').append('<p class="log">' + emp.log + '</p>');
}
var objDiv = document.getElementById("log");
objDiv.scrollTop = objDiv.scrollHeight;
}
if (emp.hasOwnProperty('progressFirmware')) {
$('#uploadfirmwareProgress').val(emp.progressFirmware);
}
//alert("I got data: " + evt.data)
}
ws.onclose = function (e) {
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function () {
connect();
}, 1000);
};
ws.onerror = function (err) {
console.error('Socket encountered error: ', err.message, 'Closing socket');
ws.close();
};
}
connect();
showTab(event, 'display');
}
<e>
<br/>
The webserver handle is the following, the ldeCore, is just like a SQL thing:
<CODE><s>
Code: Select all
</s>static esp_err_t ws_handler(httpd_req_t *req) {
uint8_t *buf = NULL;
if (req->method == HTTP_GET) {
ESP_LOGI(TAG, "Handshake done, the new connection was opened");
return ESP_OK;
}
/* Set max_len = 0 to get the frame len */
esp_err_t ret; // = httpd_ws_recv_frame(req, &ws_pkt, 2000);
httpd_ws_frame_t ws_pkt;
memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t));
ws_pkt.type = HTTPD_WS_TYPE_TEXT;
ws_pkt.payload = (uint8_t*) readBufWS;
/* Set max_len = 0 to get the frame len */
ret = httpd_ws_recv_frame(req, &ws_pkt, 0);
//ESP_LOGI(TAG, "frame len is %d", ws_pkt.len);
if(ws_pkt.len){
buf = calloc(1,ws_pkt.len +1);
if(buf == NULL){
ESP_LOGE(TAG, "Failed to calloc memory for buf");
free(buf);
return ESP_ERR_NO_MEM;
}
ws_pkt.payload = buf;
ret = httpd_ws_recv_frame(req, &ws_pkt,ws_pkt.len);
if(ret != ESP_OK){
free(buf);
return ret;
}
//ESP_LOGI(TAG, "Got packet with message: %s %d", ws_pkt.payload, ws_pkt.len);
}
if (ws_pkt.len < readBufSize && ws_pkt.len > 0) {
//if(ws_pkt.len)
if (ldeCore_ItemCount(socks) == 0) {
//esp_log_set_vprintf(vprintf_dvt);
}
int count = jsmn_parse(&parser,(char*)ws_pkt.payload, strlen((char*)ws_pkt.payload), t, 256); // "s" is the char array holding the json content
int i = 0;
//ESP_LOGE(TAG, "json: %d", count);
if(count < 0){
// ESP_LOGE(TAG, "json: %s", ws_pkt.payload);
}
if(count > 0){
for (i = 1; i < count; i++) {
if (jsoneq((char*)ws_pkt.payload, &t[i], "dhcp") == 0) {
// ESP_LOGE(TAG, "dhcp: %s", ((char*)ws_pkt.payload) + t[i + 1].start);
}
}
}
if (!ldeCore_IdxHasItem(socks->idx_Socket, req->handle)) {
websock_instance *dev;
dev = ldeCore_ItemAdd(socks);
dev->descriptor = httpd_req_to_sockfd(req);
dev->handle = req->handle;
req->sess_ctx = dev; // Set to nonzero otherwise free_ctx won't get called.
req->free_ctx = socket_close_cleanup;
ldeCore_IdxIns(socks->idx_Socket, dev);
//ESP_LOGE(TAG, "Added socket");
}
readBufWS[ws_pkt.len] = 0; // null termination
if(memcmp(ws_pkt.payload,"settime_",8) == 0){
uint32_t time = atoi((char*)&ws_pkt.payload[8]);
ESP_LOGI(TAG, "time: %s %d %d", &ws_pkt.payload[8], ws_pkt.len-8,time);
/*
struct rtc_time timeToSet;
char subbuff[5];
uint8_t *content;
content = &ws_pkt.payload[8];
memcpy( subbuff, &content[0], 4 );
subbuff[4] = '\0';
timeToSet.tm_year = atoi(subbuff);
memcpy( subbuff, &content[5], 2 );
subbuff[2] = '\0';
timeToSet.tm_mon = atoi(subbuff);
memcpy( subbuff, &content[8], 4 );
subbuff[2] = '\0';
timeToSet.tm_mday = atoi(subbuff);
memcpy( subbuff, &content[11], 4 );
subbuff[2] = '\0';
timeToSet.tm_hour = atoi(subbuff);
memcpy( subbuff, &content[14], 4 );
subbuff[2] = '\0';
timeToSet.tm_min = atoi(subbuff);
memcpy( subbuff, &content[17], 4 );
subbuff[2] = '\0';
timeToSet.tm_sec = atoi(subbuff);
//rtc_RV_set(&timeToSet);
*/
// rtc_RV_set_unix(time + (60*60));
}else if(memcmp(ws_pkt.payload,"testData_",9) == 0){
if(memcmp(&ws_pkt.payload[9],"1",1)){
Test = 0;
}else{
Test = 1;
}
char subbuff[8];
memcpy( subbuff, &ws_pkt.payload[11], 5 );
subbuff[5] = '\0';
TestValueWarm = strtod(subbuff,NULL);
memcpy( subbuff, &ws_pkt.payload[17], 5 );
subbuff[5] = '\0';
TestValueCold = strtod(subbuff,NULL);
}else if(memcmp(ws_pkt.payload,"btn_",4) == 0){
//ESP_LOGI(TAG, "btn pushed:");
if(memcmp(ws_pkt.payload,"btn_1",5) == 0){
testBtnUp = 1;
ESP_LOGI(TAG, "1");
}
if(memcmp(ws_pkt.payload,"btn_2",5)== 0){
testBtnDown = 1;
//ESP_LOGI(TAG, "2");
}
if(memcmp(ws_pkt.payload,"btn_3",5)==0){
testBtnOnOff = 1;
//ESP_LOGI(TAG, "3");
}
}
else if(memcmp(ws_pkt.payload,"DMXdata",7)==0){
uint8_t dmx_data[512];
int temp_dmx_data = 0;
for(int i = 0; i <512;i++){
sscanf((char*)&ws_pkt.payload[9 + (i*3)], ",%x", &temp_dmx_data);
dmx_data[i] = temp_dmx_data;
}
dmx_packet_t dPack;
dPack.PacketSize = 512;
dPack.StartCode = 0;
memcpy(dPack.DMX,dmx_data,512);
dmx_SendDMXPacket(DMX_NUM_1, &dPack);
}
//ESP_LOGI(TAG, "Got packet with message: %s %d", ws_pkt.payload, ws_pkt.len);
}
free(buf);
return ret;
}<e>
<CODE><s>
Code: Select all
</s>void tud_network_init_cb(void) {
/* if the network is re-initializing and we have a leftover packet, we must do a cleanup */
ESP_LOGI(TAG, "tud_network_init_cb.");
tud_rx_len = 0;
return;
}
}<e>