SHA256
Compare commits
4
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
1c7f7fce4a | ||
|
|
13eeef7700 | ||
|
|
082995d264 | ||
|
|
8a0cdd9b47 |
No files matched your search
@@ -3,4 +3,3 @@ compile_commands.json
|
|||||||
.clangd
|
.clangd
|
||||||
.vscode
|
.vscode
|
||||||
.cache
|
.cache
|
||||||
.venv
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
|
||||||
#include <WebSocketsServer.h>
|
|
||||||
|
|
||||||
void webSocketEvent( uint8_t num, WStype_t type, uint8_t * payload, size_t length );
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
|
||||||
#include "Network.h"
|
|
||||||
#include <WiFi.h>
|
|
||||||
|
|
||||||
|
|
||||||
extern volatile bool websocket_connected;
|
|
||||||
|
|
||||||
class wifi_conf {
|
|
||||||
private:
|
|
||||||
const char* _ssid;
|
|
||||||
const char* _passwd;
|
|
||||||
|
|
||||||
void handler_WiFi(arduino_event_id_t event, arduino_event_info_t info);
|
|
||||||
|
|
||||||
public:
|
|
||||||
void conectar(
|
|
||||||
const char* ssid,
|
|
||||||
const char* passwd,
|
|
||||||
IPAddress local_ip,
|
|
||||||
IPAddress gateway,
|
|
||||||
IPAddress subnet,
|
|
||||||
IPAddress dns1,
|
|
||||||
IPAddress dns2
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -23,4 +23,3 @@ board_build.partitions = default_16MB.csv
|
|||||||
board_build.extra_flags =
|
board_build.extra_flags =
|
||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-DCORE_DEBUG_LEVEL=5
|
-DCORE_DEBUG_LEVEL=5
|
||||||
lib_deps = links2004/WebSockets@^2.7.3
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include "WebSocketHandler.h"
|
|
||||||
|
|
||||||
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
|
|
||||||
switch(type) {
|
|
||||||
case WStype_CONNECTED:
|
|
||||||
Serial.printf("[%u] Cliente conectado\n", num);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WStype_DISCONNECTED:
|
|
||||||
Serial.printf("[%u] Cliente desconectado\n", num);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WStype_TEXT:
|
|
||||||
Serial.printf("[%u] Mensaje: %s\n", num, payload);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include "WiFiConf.h"
|
|
||||||
|
|
||||||
extern volatile bool websocket_connected;
|
|
||||||
|
|
||||||
void wifi_conf::handler_WiFi(arduino_event_id_t event, arduino_event_info_t info) {
|
|
||||||
|
|
||||||
switch(event){
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
|
||||||
websocket_connected = true;
|
|
||||||
Serial.printf("Wi-Fi conectado\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
|
||||||
Serial.printf( "IP Address: %s\n", IPAddress(info.got_ip.ip_info.ip.addr).toString().c_str() );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
|
||||||
websocket_connected = false;
|
|
||||||
Serial.printf("WiFi: Desconectado\n");
|
|
||||||
Serial.printf("DEBUG: Reconectando...\n");
|
|
||||||
|
|
||||||
WiFi.STA.connect(_ssid,_passwd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wifi_conf::conectar(
|
|
||||||
const char* ssid,
|
|
||||||
const char* passwd,
|
|
||||||
IPAddress local_ip,
|
|
||||||
IPAddress gateway,
|
|
||||||
IPAddress subnet,
|
|
||||||
IPAddress dns1,
|
|
||||||
IPAddress dns2
|
|
||||||
) {
|
|
||||||
|
|
||||||
_ssid = ssid;
|
|
||||||
_passwd = passwd;
|
|
||||||
|
|
||||||
Network.begin();
|
|
||||||
|
|
||||||
Network.onEvent([this](arduino_event_id_t event, arduino_event_info_t info){
|
|
||||||
handler_WiFi(event, info);
|
|
||||||
});
|
|
||||||
|
|
||||||
WiFi.STA.begin();
|
|
||||||
|
|
||||||
WiFi.STA.config( local_ip, gateway, subnet, dns1, dns2);
|
|
||||||
|
|
||||||
WiFi.STA.connect(_ssid, _passwd);
|
|
||||||
}
|
|
||||||
+6
-81
@@ -1,101 +1,26 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "freertos/ringbuf.h"
|
|
||||||
|
|
||||||
#include "ADCconf.h"
|
#include "ADCconf.h"
|
||||||
#include "WiFiConf.h"
|
|
||||||
#include "WebSocketHandler.h"
|
|
||||||
|
|
||||||
#include <WebSocketsServer.h>
|
|
||||||
|
|
||||||
// API ESP-IDF para ADC modo continuo (uso de DMA)
|
// API ESP-IDF para ADC modo continuo (uso de DMA)
|
||||||
#define MS_BLOQUE 10
|
|
||||||
adc_channel_t CHANNEL = ADC_CHANNEL_3;
|
adc_channel_t CHANNEL = ADC_CHANNEL_3;
|
||||||
|
#define MS_BLOQUE 10
|
||||||
const uint32_t HZ_ADC = 1000; // Limitado a 611 - 83333 para el ESP32-S3
|
const uint32_t HZ_ADC = 1000; // Limitado a 611 - 83333 para el ESP32-S3
|
||||||
const uint32_t MUESTRAS_BLOQUE = (HZ_ADC * MS_BLOQUE) / 1000;
|
const uint32_t MUESTRAS_BLOQUE = (HZ_ADC * MS_BLOQUE) / 1000;
|
||||||
uint8_t dma_buffer[MUESTRAS_BLOQUE * SOC_ADC_DIGI_RESULT_BYTES] = {0};
|
uint8_t dma_buffer[MUESTRAS_BLOQUE * SOC_ADC_DIGI_RESULT_BYTES] = {0};
|
||||||
uint16_t samples_buffer[MUESTRAS_BLOQUE] = {0};
|
uint16_t samples_buffer[MUESTRAS_BLOQUE] = {0};
|
||||||
const uint32_t SIZE_BUFFER = MUESTRAS_BLOQUE*10;
|
|
||||||
|
|
||||||
ADC_BME adc1_3;
|
ADC_BME adc1_3;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
// Conf de ESP32-S3 en modo STA
|
|
||||||
const char* SSID="debian";
|
|
||||||
const char* PASSWD="aH2T9GFA";
|
|
||||||
IPAddress local_ip(10,42,0,100);
|
|
||||||
IPAddress gateway(40,42,0,1);
|
|
||||||
IPAddress subnet(255,255,255,0);
|
|
||||||
IPAddress dns1(10,42,0,1);
|
|
||||||
IPAddress dns2(1,1,1,1);
|
|
||||||
|
|
||||||
wifi_conf sta_esp32;
|
|
||||||
WebSocketsServer webSocket(81);
|
|
||||||
volatile bool websocket_connected = false;
|
|
||||||
|
|
||||||
// FreeRTOS
|
|
||||||
TaskHandle_t ADCTaskHandle = NULL;
|
|
||||||
TaskHandle_t WebSocketTaskHandle = NULL;
|
|
||||||
RingbufHandle_t bufferHandle = xRingbufferCreate(SIZE_BUFFER, RINGBUF_TYPE_NOSPLIT);
|
|
||||||
|
|
||||||
void ADCTask(void *parameter);
|
|
||||||
void WebSocketTask(void *parameter);
|
|
||||||
|
|
||||||
void setup(){
|
|
||||||
Serial.begin(230400);
|
Serial.begin(230400);
|
||||||
|
|
||||||
sta_esp32.conectar(SSID, PASSWD, local_ip, gateway, subnet, dns1, dns2);
|
|
||||||
|
|
||||||
webSocket.begin();
|
|
||||||
webSocket.onEvent(webSocketEvent);
|
|
||||||
|
|
||||||
adc1_3.config(MUESTRAS_BLOQUE, CHANNEL, HZ_ADC, dma_buffer);
|
adc1_3.config(MUESTRAS_BLOQUE, CHANNEL, HZ_ADC, dma_buffer);
|
||||||
adc1_3.setup();
|
adc1_3.setup();
|
||||||
|
|
||||||
//Iniciar el buffer circular
|
|
||||||
if (bufferHandle == NULL) {
|
|
||||||
Serial.printf("Failed to create ring buffer!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore( ADCTask, "ADCTask", 10000, NULL, 1, &ADCTaskHandle, 0);
|
|
||||||
xTaskCreatePinnedToCore( WebSocketTask, "WebSocketTask", 10000, NULL, 1, &WebSocketTaskHandle, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop() {
|
||||||
}
|
uint32_t count = adc1_3.read(samples_buffer);
|
||||||
|
|
||||||
void ADCTask(void *parameter){
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
for(;;) {
|
Serial.printf("%u\n",samples_buffer[i]);
|
||||||
|
|
||||||
if (!websocket_connected) {
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(100));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint32_t count = adc1_3.read(samples_buffer);
|
|
||||||
if (count > 0) {
|
|
||||||
if (xRingbufferSend(bufferHandle, samples_buffer, count * sizeof(uint16_t), pdMS_TO_TICKS(1000)) != pdTRUE) {
|
|
||||||
Serial.println("Failed to send message to ring buffer!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebSocketTask(void *parameter){
|
|
||||||
for(;;) {
|
|
||||||
|
|
||||||
webSocket.loop();
|
|
||||||
|
|
||||||
size_t receivedMessageSize;
|
|
||||||
uint16_t* receivedMessage = (uint16_t*)xRingbufferReceive(bufferHandle, &receivedMessageSize, pdMS_TO_TICKS(1000));
|
|
||||||
|
|
||||||
// 6. Check if the receive operation was successful
|
|
||||||
if (receivedMessage != NULL) {
|
|
||||||
webSocket.broadcastBIN((uint8_t*)receivedMessage, receivedMessageSize);
|
|
||||||
vRingbufferReturnItem(bufferHandle, (void*)receivedMessage);
|
|
||||||
} else {
|
|
||||||
Serial.println("Failed t+o receive message from ring buffer!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import struct
|
|
||||||
|
|
||||||
from websocket import create_connection
|
|
||||||
|
|
||||||
ws = create_connection("ws://10.42.0.100:81")
|
|
||||||
|
|
||||||
print("Conectado")
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
data = ws.recv()
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
if isinstance(data, bytes):
|
|
||||||
# Convertir bytes -> uint16_t
|
|
||||||
samples = struct.unpack(f"<{len(data) // 2}H", data)
|
|
||||||
|
|
||||||
print("ADC:", samples)
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("TXT:", data)
|
|
||||||
|
|
||||||
print(f"DEBUG {i}")
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Cerrando conexión")
|
|
||||||
ws.close()
|
|
||||||
Reference in new issue
Block a user