Able Varghese
Published

Build mobile App for all ESP8266 Projects

Build mobile app for all your ESP8266 projects using MIT App Inventor.

Beginner1 hour12,040
Build mobile App for all ESP8266 Projects

Things used in this project

Hardware components

UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1
UTSOURCE NODEMCU
×1
led
×1
jumper wire
×1

Software apps and online services

MIT App Inventor
MIT App Inventor

Story

Read more

Code

code

Arduino
 #include <ESP8266WiFi.h>

const char* ssid = "ssid";//your mobile hotspot name
const char* password = "password";

WiFiServer server(80);
void setup() {
 Serial.begin(115200);
 delay(10);
// prepare GPIO
 pinMode(D4, OUTPUT);
 digitalWrite(D4, 0);
   Serial.println();
 Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
   while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
  
  // Match the request
  int val;
  if (req.indexOf("/gpio/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio/1") != -1)
    val = 1;
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  // Set GPI0 according to the request
  digitalWrite(D4, val);
  
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
  s += (val)?"high":"low";
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}

Credits

Able Varghese

Able Varghese

3 projects • 11 followers
i am pursuing bachelor’s degree in Electronics Engineering .Happy with making irrespective of it’s nature,from coding to Welding
Thanks to .

Comments