Post topics, source code that relate to the Arduino Platform

User avatar
By vra
#90723 how are you?. I'm using an ESP-01 with platformIO wich is programmed using esptool.py to run an example of a web server that I found in a book called "NodeMCU ESP8266 Communication Methods and Protocols: programming with arduino IDE". The code is the following:

Code: Select all#include <Arduino.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>

const char *wifiName = "XXX";
const char *wifiPassword = "YYYY";

ESP8266WebServer server(80);

int ledPin = 1;

void handleRoot()
{
    //digitalWrite(ledPin,LOW);
    server.send(200,"text/plain","hello from esp8266");
    delay(1000);
    //digitalWrite(ledPin,HIGH);
}

void setup() {
// put your setup code here, to run once:
    Serial.begin(115200);
    delay(5000);
    //pinMode(ledPin,OUTPUT);
    Serial.print("Conectando");
    WiFi.begin(wifiName,wifiPassword);
    while (WiFi.status() != WL_CONNECTED)
    {
    /* code */
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.println("Conectado por WIFI");
    Serial.println("Dirección IP: ");
    Serial.println(WiFi.localIP());
    server.on("/", handleRoot);
    server.begin();
    Serial.println("Servidor HTTP iniciado");
}

void loop() {
// put your main code here, to run repeatedly:
   server.handleClient();
}


the problem that I have here is that if the wifi connections is initiated then the board doesn't send any data over serial but if the wifi connection is not initiated then the data is sent normally. As you noted I've commented the writing to the "ledPin" since it is the same pin where is TX but even by doing that the ESP-01 doesn't send the data over serial with wifi enabled.

I think the wifi is somehow disabling the serial port but I don't know for sure.

Can anyone help me with this?.

Thanks in advance for the help.
User avatar
By QuickFix
#90755 You aren't sending anything over serial in the handleRoot()-event. :idea:

Code: Select allvoid handleRoot()
{
    server.send(200,"text/plain","hello from esp8266");
    Serial.print("Hello sent"); // Or something similar
    delay(1000);
}