SHA256
Compare commits
2
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
1c7f7fce4a | ||
|
|
13eeef7700 |
No files matched your search
+1
-2
@@ -2,5 +2,4 @@
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
.clangd
|
.clangd
|
||||||
.vscode
|
.vscode
|
||||||
.cache
|
.cache
|
||||||
.venv
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "esp_adc/adc_continuous.h"
|
||||||
|
|
||||||
|
class ADC_BME {
|
||||||
|
private:
|
||||||
|
uint32_t _FRAME_SIZE;
|
||||||
|
uint32_t _POOL_SIZE;
|
||||||
|
uint32_t _HZ_ADC;
|
||||||
|
adc_channel_t _channel;
|
||||||
|
uint8_t* _dma_buffer;
|
||||||
|
volatile bool dma_data_ready = false;
|
||||||
|
adc_continuous_handle_t handle_ADC = NULL;
|
||||||
|
static bool IRAM_ATTR adc_dma_callback(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data);
|
||||||
|
public:
|
||||||
|
void config(const uint32_t muestras_bloque, adc_channel_t channel, const uint32_t hz_adc, uint8_t* dma_buffer);
|
||||||
|
void setup();
|
||||||
|
uint32_t read(uint16_t* samples_buffer);
|
||||||
|
};
|
||||||
@@ -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
|
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#include "ADCconf.h"
|
||||||
|
|
||||||
|
bool IRAM_ATTR ADC_BME::adc_dma_callback(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data){
|
||||||
|
ADC_BME* adc =static_cast<ADC_BME*>(user_data);
|
||||||
|
adc->dma_data_ready = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADC_BME::config(const uint32_t muestras_bloque, adc_channel_t channel, const uint32_t hz_adc, uint8_t* dma_buffer){
|
||||||
|
_FRAME_SIZE=muestras_bloque*4;
|
||||||
|
_POOL_SIZE=_FRAME_SIZE*4;
|
||||||
|
_channel=channel;
|
||||||
|
_HZ_ADC=hz_adc;
|
||||||
|
_dma_buffer=dma_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADC_BME::setup(){
|
||||||
|
adc_continuous_handle_cfg_t ADC_config = {
|
||||||
|
.max_store_buf_size = _POOL_SIZE,
|
||||||
|
.conv_frame_size = _FRAME_SIZE,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(adc_continuous_new_handle(&ADC_config, &handle_ADC));
|
||||||
|
|
||||||
|
adc_digi_pattern_config_t channel_config = {0};
|
||||||
|
channel_config.channel = _channel;
|
||||||
|
channel_config.atten = ADC_ATTEN_DB_12;
|
||||||
|
channel_config.bit_width = ADC_BITWIDTH_12;
|
||||||
|
channel_config.unit = ADC_UNIT_1;
|
||||||
|
|
||||||
|
adc_continuous_config_t adc_config = {
|
||||||
|
.pattern_num = 1,
|
||||||
|
.adc_pattern = &channel_config,
|
||||||
|
.sample_freq_hz = _HZ_ADC,
|
||||||
|
.conv_mode = ADC_CONV_SINGLE_UNIT_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(adc_continuous_config(handle_ADC, &adc_config));
|
||||||
|
|
||||||
|
adc_continuous_evt_cbs_t cb_config = {
|
||||||
|
.on_conv_done = adc_dma_callback,
|
||||||
|
.on_pool_ovf = NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle_ADC, &cb_config, this));
|
||||||
|
ESP_ERROR_CHECK(adc_continuous_start(handle_ADC));
|
||||||
|
Serial.println("DMA Iniciado con sistema de bandera.");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ADC_BME::read(uint16_t* samples_buffer) {
|
||||||
|
|
||||||
|
if (!dma_data_ready) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dma_data_ready = false;
|
||||||
|
uint32_t ret_num = 0;
|
||||||
|
|
||||||
|
// Leer datos DMA
|
||||||
|
esp_err_t ret = adc_continuous_read(handle_ADC,_dma_buffer,_FRAME_SIZE,&ret_num,0);
|
||||||
|
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// Buffer temporal parseado
|
||||||
|
adc_continuous_data_t parsed_data[_FRAME_SIZE/4];
|
||||||
|
|
||||||
|
uint32_t parsed_count = 0;
|
||||||
|
|
||||||
|
// Parsear datos
|
||||||
|
esp_err_t parse_ret =
|
||||||
|
adc_continuous_parse_data(
|
||||||
|
handle_ADC,
|
||||||
|
_dma_buffer,
|
||||||
|
ret_num,
|
||||||
|
parsed_data,
|
||||||
|
&parsed_count
|
||||||
|
);
|
||||||
|
|
||||||
|
if (parse_ret != ESP_OK) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t valid_samples = 0;
|
||||||
|
// Copiar muestras limpias
|
||||||
|
for (uint32_t i = 0; i < parsed_count; i++) {
|
||||||
|
if (!parsed_data[i].valid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
samples_buffer[valid_samples] = parsed_data[i].raw_data;
|
||||||
|
valid_samples++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid_samples;
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
+16
-28
@@ -1,38 +1,26 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "ADCconf.h"
|
||||||
|
|
||||||
#include "WiFiConf.h"
|
// API ESP-IDF para ADC modo continuo (uso de DMA)
|
||||||
#include "WebSocketHandler.h"
|
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 MUESTRAS_BLOQUE = (HZ_ADC * MS_BLOQUE) / 1000;
|
||||||
|
uint8_t dma_buffer[MUESTRAS_BLOQUE * SOC_ADC_DIGI_RESULT_BYTES] = {0};
|
||||||
|
uint16_t samples_buffer[MUESTRAS_BLOQUE] = {0};
|
||||||
|
|
||||||
#include <WebSocketsServer.h>
|
ADC_BME adc1_3;
|
||||||
|
|
||||||
// Conf de ESP32-S3 en modo STA
|
|
||||||
const char* SSID="Tenda_32C850";
|
|
||||||
const char* PASSWD="rhLcrMEcY^Xjvq66";
|
|
||||||
IPAddress local_ip(192,168,0,220);
|
|
||||||
IPAddress gateway(192,168,0,1);
|
|
||||||
IPAddress subnet(255,255,255,0);
|
|
||||||
IPAddress dns1(192,168,0,100);
|
|
||||||
IPAddress dns2(1,1,1,1);
|
|
||||||
volatile bool websocket_connected = false;
|
|
||||||
|
|
||||||
wifi_conf sta_esp32;
|
|
||||||
WebSocketsServer webSocket(81);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Serial.begin(230400);
|
||||||
Serial.begin(230400);
|
adc1_3.config(MUESTRAS_BLOQUE, CHANNEL, HZ_ADC, dma_buffer);
|
||||||
|
adc1_3.setup();
|
||||||
sta_esp32.conectar(SSID, PASSWD, local_ip, gateway, subnet, dns1, dns2);
|
|
||||||
|
|
||||||
webSocket.begin();
|
|
||||||
webSocket.onEvent(webSocketEvent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
webSocket.loop();
|
uint32_t count = adc1_3.read(samples_buffer);
|
||||||
|
|
||||||
uint8_t imagen = 0;
|
|
||||||
webSocket.broadcastBIN(&imagen, 1);
|
|
||||||
delay(10);
|
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
|
Serial.printf("%u\n",samples_buffer[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
from websocket import create_connection
|
|
||||||
|
|
||||||
ws = create_connection("ws://192.168.0.220:81")
|
|
||||||
i = 0
|
|
||||||
print("Conectado")
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
data = ws.recv()
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
if isinstance(data, bytes):
|
|
||||||
print(f"BIN: {list(data)}")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"TXT: {data}")
|
|
||||||
|
|
||||||
print(f"DEBUG {i}")
|
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Cerrando conexión")
|
|
||||||
|
|
||||||
ws.close()
|
|
||||||
Reference in new issue
Block a user