Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15427

Problem for run new code on esp32 based board

$
0
0

#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <ESPmDNS.h>
#else
#error "Board not found"
#endif

#define LED1 15
#define LED2 12

char webpage[] PROGMEM = R"=====(

My Home Automation

LED 1

OnOff

LED 2

OnOff

)=====";

// ipaddress/led1/on
//ipaddress/led1/off

// ipaddress/led2/on
//ipaddress/led2/off
#include <ESPAsyncWebServer.h>

AsyncWebServer server(80); // server port 80

void notFound(AsyncWebServerRequest *request)
{
request->send(404, "text/plain", "Page Not found");
}

void setup(void)
{

Serial.begin(115200);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

WiFi.softAP("techiesms", "");
Serial.println("softap");
Serial.println("");
Serial.println(WiFi.softAPIP());

if (MDNS.begin("ESP")) { //esp.local/
Serial.println("MDNS responder started");
}

server.on("/", [](AsyncWebServerRequest * request)
{

request->send_P(200, "text/html", webpage);
});

server.on("/led1/on", HTTP_GET, [](AsyncWebServerRequest * request)
{
digitalWrite(LED1,HIGH);
request->send_P(200, "text/html", webpage);
});

server.onNotFound(notFound);

server.begin(); // it will start webserver
}

void loop(void)
{
}

Uploading this code on my esp32 board. But it ran properly! Now if I upload any other code the upload works fine but, don't go The web server created by the above code runs. Is there any solution to this?

15 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15427

Trending Articles