esp-ip-pdu-toggle/ESP32ippdutoggle.ino














(Only 1 Relay Project)
esp-ip-pdu-toggle/ESP32ippdutoggle.ino
99 lines (82 sloc)  1.97 KB
#include <WiFi.h>
#include "espipswitchtoggle.h"

const char* ssid = "Ermenegildo Zegna";
const char* password = "hhjw-ofvq-pafm";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);


void setup() {
  Serial.begin(115200);
  delay(10);
pinMode(12, OUTPUT);
  
  // Connect to WiFi network
  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 command1 = client.readStringUntil('/');
  String command = client.readStringUntil('/');
  Serial.println(command);

if (command == "12") {
  if(digitalRead(12))
  {
    digitalWrite(12, 0);
    client.print(F("12,0"));
  }
  else
  {
    digitalWrite(12, 1);
    client.print(F("12,1"));
  }
}
else if (command == "status") {
int pin, value;
client.print(F("status"));
value = digitalRead(12);
client.print(F("#12="));
client.print(value);
client.println("");
}
else {  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  s += file1;  
  client.flush();

  // Send the response to the client
while(s.length()>2000)
{
  String dummy = s.substring(0,2000);
  client.print(dummy);
  s.replace(dummy," ");
}
  
  client.print(s);
  delay(1);
  Serial.println("Client disconnected");

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

Comments

Popular posts from this blog

CHIRP SOFTWARE APP Downloads

OPENLINE MODEM AND UNLOCK&DEBRAND

PH.CRACKERS VPN FREENET