SHA256
Compare commits
6
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
9c21611c81 | ||
|
|
058aa39b9c | ||
|
|
5e55047884 | ||
|
|
20c3ecd30e | ||
|
|
082995d264 | ||
|
|
8a0cdd9b47 |
No files matched your search
@@ -1 +1,6 @@
|
|||||||
.pio
|
.pio
|
||||||
|
compile_commands.json
|
||||||
|
.clangd
|
||||||
|
.vscode
|
||||||
|
.cache
|
||||||
|
.venv
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include <WebSocketsServer.h>
|
||||||
|
|
||||||
|
void webSocketEvent( uint8_t num, WStype_t type, uint8_t * payload, size_t length );
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#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
|
||||||
|
);
|
||||||
|
};
|
||||||
+13
-1
@@ -9,6 +9,18 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:esp32-s3-devkitc-1]
|
[env:esp32-s3-devkitc-1]
|
||||||
platform = espressif32
|
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
|
build_type = debug
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
monitor_speed = 230400
|
||||||
|
board_build.arduino.memory_type = qio_opi
|
||||||
|
board_build.flash_mode = qio
|
||||||
|
board_build.psram_type = opi
|
||||||
|
board_upload.flash_size = 16MB
|
||||||
|
board_upload.maximum_size = 16777216
|
||||||
|
board_build.partitions = default_16MB.csv
|
||||||
|
board_build.extra_flags =
|
||||||
|
-DBOARD_HAS_PSRAM
|
||||||
|
-DCORE_DEBUG_LEVEL=5
|
||||||
|
lib_deps = links2004/WebSockets@^2.7.3
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#include "WiFiConf.h"
|
||||||
|
#include "WebSocketHandler.h"
|
||||||
|
|
||||||
|
#include <WebSocketsServer.h>
|
||||||
|
|
||||||
|
// 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() {
|
||||||
|
|
||||||
|
Serial.begin(230400);
|
||||||
|
|
||||||
|
sta_esp32.conectar(SSID, PASSWD, local_ip, gateway, subnet, dns1, dns2);
|
||||||
|
|
||||||
|
webSocket.begin();
|
||||||
|
webSocket.onEvent(webSocketEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
webSocket.loop();
|
||||||
|
|
||||||
|
uint8_t imagen = 0;
|
||||||
|
webSocket.broadcastBIN(&imagen, 1);
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
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