SHA256
Feature: Funcional
This commit is contained in:
1 parent
5e55047884
commit
058aa39b9c
6 files changed
+104
-57
No files matched your search
@@ -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,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "Network.h"
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -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,48 @@
|
|||||||
|
#include "WiFiConf.h"
|
||||||
|
|
||||||
|
void wifi_conf::handler_WiFi(arduino_event_id_t event, arduino_event_info_t info) {
|
||||||
|
|
||||||
|
switch(event){
|
||||||
|
|
||||||
|
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||||
|
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:
|
||||||
|
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);
|
||||||
|
}
|
||||||
+5
-56
@@ -1,6 +1,8 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Network.h"
|
|
||||||
#include <WiFi.h>
|
#include "WiFiConf.h"
|
||||||
|
#include "WebSocketHandler.h"
|
||||||
|
|
||||||
#include <WebSocketsServer.h>
|
#include <WebSocketsServer.h>
|
||||||
|
|
||||||
// Conf de ESP32-S3 en modo STA
|
// Conf de ESP32-S3 en modo STA
|
||||||
@@ -13,59 +15,6 @@ IPAddress dns1(192,168,0,100);
|
|||||||
IPAddress dns2(1,1,1,1);
|
IPAddress dns2(1,1,1,1);
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clase para manejo de Wi-Fi
|
|
||||||
class wifi_conf {
|
|
||||||
private:
|
|
||||||
const char* _ssid;
|
|
||||||
const char* _passwd;
|
|
||||||
|
|
||||||
void handler_WiFi(arduino_event_id_t event, arduino_event_info_t info) {
|
|
||||||
switch(event){
|
|
||||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
|
||||||
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:
|
|
||||||
Serial.printf("WiFi: Desconectado\n");
|
|
||||||
Serial.printf("DEBUG: Reconectando...\n");
|
|
||||||
WiFi.STA.connect(_ssid,_passwd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public:
|
|
||||||
void conectar(const char* ssid, const char* passwd){
|
|
||||||
_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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
wifi_conf sta_esp32;
|
wifi_conf sta_esp32;
|
||||||
WebSocketsServer webSocket(81);
|
WebSocketsServer webSocket(81);
|
||||||
|
|
||||||
@@ -73,7 +22,7 @@ void setup() {
|
|||||||
|
|
||||||
Serial.begin(230400);
|
Serial.begin(230400);
|
||||||
|
|
||||||
sta_esp32.conectar(SSID, PASSWD);
|
sta_esp32.conectar(SSID, PASSWD, local_ip, gateway, subnet, dns1, dns2);
|
||||||
|
|
||||||
webSocket.begin();
|
webSocket.begin();
|
||||||
webSocket.onEvent(webSocketEvent);
|
webSocket.onEvent(webSocketEvent);
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ import time
|
|||||||
from websocket import create_connection
|
from websocket import create_connection
|
||||||
|
|
||||||
ws = create_connection("ws://192.168.0.220:81")
|
ws = create_connection("ws://192.168.0.220:81")
|
||||||
|
i = 0
|
||||||
print("Conectado")
|
print("Conectado")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = ws.recv()
|
data = ws.recv()
|
||||||
|
i += 1
|
||||||
|
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
print(f"BIN: {list(data)}")
|
print(f"BIN: {list(data)}")
|
||||||
@@ -16,6 +17,8 @@ try:
|
|||||||
else:
|
else:
|
||||||
print(f"TXT: {data}")
|
print(f"TXT: {data}")
|
||||||
|
|
||||||
|
print(f"DEBUG {i}")
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Cerrando conexión")
|
print("Cerrando conexión")
|
||||||
|
|||||||
Reference in new issue
Block a user