Tenho duas plcas esp, uma 8266 e uma 32 (devkit v1).

A placa Esp 8266 funciona perfeitamente. Ja a 32 não consegue se conectar a minha rede wifi. Detalhe: o código é o mesmo para as duas (o código é adaptado para funcionar com as duas, então o erro não é este). Tentei compilar um código diferente com o uso de wifi, mas esbarro em outro erro. Blink funciona normalmente. O problema é a conexao.

Código que não conecta:

*******************************************************************************************************************

// Import required libraries
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#else
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>

// Replace with your network credentials
char* ssid = "CleanNet_9651";
char* password = "95473725";

const char* PARAM_INPUT_1 = "state";

const int output = 10;
const int buttonPin = 4;

// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<title>ESP Web Server</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html {font-family: Arial; display: inline-block; text-align: center;}
h2 {font-size: 3.0rem;}
p {font-size: 3.0rem;}
body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}
.switch {position: relative; display: inline-block; width: 120px; height: 68px}
.switch input {display: none}
.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 34px}
.slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 68px}
input:checked+.slider {background-color: #2196F3}
input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}
</style>
</head>
<body>
<h2>ESP Web Server</h2>
%BUTTONPLACEHOLDER%
<script>function toggleCheckbox(element) {
var xhr = new XMLHttpRequest();
if(element.checked){ xhr.open("GET", "/update?state=1", true); }
else { xhr.open("GET", "/update?state=0", true); }
xhr.send();
}

setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var inputChecked;
var outputStateM;
if( this.responseText == 1){
inputChecked = true;
outputStateM = "On";
}
else {
inputChecked = false;
outputStateM = "Off";
}
document.getElementById("output").checked = inputChecked;
document.getElementById("outputState").innerHTML = outputStateM;
}
};
xhttp.open("GET", "/state", true);
xhttp.send();
}, 1000 ) ;
</script>
</body>
</html>
)rawliteral";

// Replaces placeholder with button section in your web page
String processor(const String& var){
//Serial.println(var);
if(var == "BUTTONPLACEHOLDER"){
String buttons ="";
String outputStateValue = outputState();
buttons+= "<h4>Output - GPIO 2 - State <span id=\"outputState\"><span></h4><label class=\"switch\"><input type=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"output\" " + outputStateValue + "><span class=\"slider\"></span></label>";
return buttons;
}
return String();
}

String outputState(){
if(digitalRead(output)){
return "checked";
}
else {
return "";
}
return "";
}

void setup(){
// Serial port for debugging purposes
Serial.begin(115200);

pinMode(output, OUTPUT);
digitalWrite(output, LOW);
pinMode(buttonPin, INPUT);

// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}

// Print ESP Local IP Address
Serial.println(WiFi.localIP());

// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});

// Send a GET request to <ESP_IP>/update?state=<inputMessage>
server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) {
String inputMessage;
String inputParam;
// GET input1 value on <ESP_IP>/update?state=<inputMessage>
if (request->hasParam(PARAM_INPUT_1)) {
inputMessage = request->getParam(PARAM_INPUT_1)->value();
inputParam = PARAM_INPUT_1;
digitalWrite(output, inputMessage.toInt());
ledState = !ledState;
}
else {
inputMessage = "No message sent";
inputParam = "none";
}
Serial.println(inputMessage);
request->send(200, "text/plain", "OK");
});

// Send a GET request to <ESP_IP>/state
server.on("/state", HTTP_GET, [] (AsyncWebServerRequest *request) {
request->send(200, "text/plain", String(digitalRead(output)).c_str());
});
// Start server
server.begin();
}

void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);

// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:

// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;

// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}

// set the LED:
digitalWrite(output, ledState);

// save the reading. Next time through the loop, it'll be the lastButtonState:
lastButtonState = reading;
}

*******************************************************************************************************************

Qualquer outro código apresenta este erro:

Arduino: 1.8.13 (Windows 10), Placa:"WEMOS LOLIN32, 80MHz, Default, 240MHz (WiFi/BT), 115200"

C:\Users\Lael Ramos\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\AsyncUDP\examples\AsyncUDPServer\AsyncUDPServer.ino: In function 'void setup()':
AsyncUDPServer:12:10: error: 'class WiFiClass' has no member named 'mode'
WiFi.mode(WIFI_STA);
^
AsyncUDPServer:12:15: error: 'WIFI_STA' was not declared in this scope
WiFi.mode(WIFI_STA);
^
AsyncUDPServer:13:30: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
WiFi.begin(ssid, password);
^
In file included from C:\Users\Lael Ramos\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\AsyncUDP\examples\AsyncUDPServer\AsyncUDPServer.ino:1:0:
C:\Program Files (x86)\Arduino\libraries\WiFi\src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'
int begin(char* ssid, const char *passphrase);
^
AsyncUDPServer:14:14: error: 'class WiFiClass' has no member named 'waitForConnectResult'
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
^
exit status 1
'class WiFiClass' has no member named 'mode'


Este relatório teria mais informações com
"Mostrar a saida detalhada durante a compilação"
opção pode ser ativada em "Arquivo -> Preferências"

Exibições: 2195

Responder esta

Respostas a este tópico

Boa tardeSr. LR, (se não gosta que te chame pelas iniciais, avise),

gostaria muito de te ajudar, mas para isto recomendo as seguintes ações:


1. Remova seu sketch da área de texto do seu tópico;

2Clique em : " Arquivos "  e depois anexe o arquivo  com o seu sketch;


3. Leia http://labdegaragem.com/forum/topics/sugest-o-de-como-postar


4. Comente as linhas do seu sketch. Fica mais fácil entender o que vc quer fazer

     com cada linha e facilita a ajuda.

RV

Boa tarde, 

Analisando as mensagens :

AsyncUDPServer:12:10: error: 'class WiFiClass' has no member named 'mode'

AsyncUDPServer:12:15: error: 'WIFI_STA' was not declared in this scope

AsyncUDPServer:14:14: error: 'class WiFiClass' has no member named 'waitForConnectResult'

A Biblioteca <AsyncTCP.h> esta incompatível com o ESP32. 

Ou ela não foi instalada corretamente. 

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço