0

i connect esp8266 to Arduino-Uno (WiFi Controlled LED using ESP8266 and Arduino) it's working well. but, when in browser i call (http://192.168.1.***/?led=ON) i want esp8266 respond and display message like that is (Ok/No) on that page, can we do that with AT Commands? or any other way ...

void loop() {
 if (esp8266.available()) {
  if (esp8266.find("+IPD,")) {

String msg;
esp8266.find("?");
msg = esp8266.readStringUntil(' ');
String command1 = msg.substring(0, 3);
String command2 = msg.substring(4);

if (DEBUG) {
  Serial.println(command1); // Must print "led"
  Serial.println(command2); // Must print "ON" or "OFF"
}

delay(100);

if (command2 == "ON") {
  digitalWrite(led_pin, HIGH);
  // here i want send led is on now
} else {
  digitalWrite(led_pin, LOW);
  // here i want send led is off now
}

  }
 }
}

2 Answers 2

0

I would recommend using ESP8266WebServer library for this project. You can create an HTML page with two separate input buttons with arguments On and Off, You can then change the status of your URL from on to off and vice-versa. On the ESP side, You can get the status of arguments like this

if(server.hasArg("ON")==true){
    digitalWrite(led_pin, HIGH);
}else if(server.hasArg("OFF")==true){
    digitalWrite(led_pin, HIGH);
}

I have done a similar kind of project https://ncd.io/thingspeak-weather-app-using-esp8266/ and https://github.com/vbshightime/ESPMeshServer

Sign up to request clarification or add additional context in comments.

Comments

0

this methode:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>

const int LED_PIN = 16;

IPAddress ip(192, 168, 0, 32);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

WebServer server(9999);    

void handleLED();

void setup(void){

  WiFi.config(ip, gateway, subnet);   
  WiFi.begin("ssid","pw");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }   

  server.on("/ON", HTTP_GET, handleLED_ON);  
  server.on("/OFF", HTTP_GET, handleLED_OFF);     
  server.begin();

  Serial.begin(115200);
  Serial.println("Start");
}

void loop(void){

  server.handleClient(); 

}

void handleLED_ON() {
    digitalWrite(LED_PIN, HIGH);
    server.send(200,"text/plan","OK");
}

void handleLED_OFF() {
    digitalWrite(LED_PIN, LOW);
    server.send(200,"text/plan","OK");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.