SHA256
Feature: Funcional
This commit is contained in:
1 parent
5e55047884
commit
058aa39b9c
6 files changed
+104
-57
No files matched your search
+5
-56
@@ -1,6 +1,8 @@
|
||||
#include "Arduino.h"
|
||||
#include "Network.h"
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "WiFiConf.h"
|
||||
#include "WebSocketHandler.h"
|
||||
|
||||
#include <WebSocketsServer.h>
|
||||
|
||||
// Conf de ESP32-S3 en modo STA
|
||||
@@ -13,59 +15,6 @@ IPAddress dns1(192,168,0,100);
|
||||
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;
|
||||
WebSocketsServer webSocket(81);
|
||||
|
||||
@@ -73,7 +22,7 @@ void setup() {
|
||||
|
||||
Serial.begin(230400);
|
||||
|
||||
sta_esp32.conectar(SSID, PASSWD);
|
||||
sta_esp32.conectar(SSID, PASSWD, local_ip, gateway, subnet, dns1, dns2);
|
||||
|
||||
webSocket.begin();
|
||||
webSocket.onEvent(webSocketEvent);
|
||||
|
||||
Reference in new issue
Block a user