Пример #1
1
void WEBINTERFACE_CLASS::WebServer()
{
  // Routing Table
  server.on("/wifisetup.html", handleWifi);
  server.on("/scan.json",handleScan);
  server.on("/", handleWifi);

  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("HTTP server started");
}
Пример #2
0
void setup() {

  Serial.begin(115200);
  Serial.println();
  Serial.println("Starting WiFi...");

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() == WL_CONNECTED) {
    Serial.printf("OK\n");
    Serial.printf("Starting UPnP...");
    UPnPDevice device;

    device.setFriendlyName("Gateway LUPS");
    device.setDeviceVersion("1.0");
    device.setDeviceType("GatewayNativo");
    device.setManufacturer("LUPS");
    device.setManufacturerURL("http://lups.inf.ufpel.edu.br/");
    device.setModelDescription("versao 1");
    device.setModelName("Gateway Nativo");
    device.setModelNumber("1.0");
    device.setModelURL("http://lups.inf.ufpel.edu.br/");
    device.setSerialNumber("12002983");
    device.setPresentationURL("http://lups.inf.ufpel.edu.br/");

    // device.addDevice(UPnPDevice inputDevice);
    // device.addService(UPnPService inputService);
    // device.addIcon(UPnPIcon inputIcon);

    HTTP.on("/index.html", HTTP_GET, []() {
      HTTP.send(
          200, "text/plain",
          "ESP8266 - Gateway EXEHDA-IoT \n\n -> "
          "IP/temp?sensor=1 a 7 para "
          "ler temperatura DS18B20; \n -> IP/temp2438?sensor=1 a 7 para "
          "ler temperatura DS2438; \n -> IP/umidade?sensor=1 a 7 para ler "
          "umidade com HIH4000 e DS2438 \n -> IP/luz?sensor=1 a 7 para ler "
          "presenca de luz com LDR e DS2438.");
    });
    HTTP.on("/description.xml", HTTP_GET, []() { UPnP.schema(HTTP.client()); });
    HTTP.begin();

    UPnP.setDevice(device);
    UPnP.setSchemaURL("description.xml");
    UPnP.setHTTPPort(80);
    UPnP.begin();

    Serial.printf("OK");
    Serial.printf("Starting HTTP Server...");

    Serial.printf("OK\n");
  } else {
    Serial.printf("Failed\n");
    while (1)
      delay(100);
  }
}
Пример #3
0
void SmartWifi::createWebServer(int webtype){
  printer->println("starting web service");

  if ( webtype == 1 ) {
    printer->println("WebType: 1");
    server.on("/", [this]() {

        content="";
        IPAddress ip = WiFi.softAPIP();
        String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
        //content = "<!DOCTYPE HTML>\r\n<html>Hello from ESP8266 at ";
        //content += ipStr;
        //content += "<p>";
        //content += st;
        content += "<!DOCTYPE html> <html > <head> <meta charset='UTF-8'> <title>Setup</title> <meta name='viewport' content='width=device-width, initial-scale=1.0'>";
        content += "</head> <style> * { box-sizing: border-box; } html { height: 100%; } body { background-color: #2c3338; color: #606468; font: 400 0.875rem/1.5 'Open Sans', sans-serif; margin: 0";
        content += "min-height: 100%; } a { color: #eee; outline: 0; text-decoration: none; } a:focus, a:hover { text-decoration: underline; } h1{ text-align: center; font-size: 21px; color: #B5B5B5; } input { border: 0; color: inherit; font: inherit; margin: 0; outline: 0; padding: 0; -webkit-transition: background-color .3s; transition: background-color .3s; } .site__container { -webkit-box-flex: 1; -webkit-flex: 1; -ms-flex: 1; flex: 1; padding: 3rem 0; } .form input[type='password'], .form input[type='text'], .form input[type='submit'], select { width: 100%; } .form--login { color: #606468; } .form--login label, .form--login input[type='text'], .form--login input[type='password'], .form--login select, .form--login input[type='submit'] { border-radius: 0.25rem; padding: 1rem; } .form--login label { background-color: #363b41; border-bottom-right-radius: 0; border-top-right-radius: 0; padding-left: 1.25rem; padding-right: 1.25rem; } .form--login input[type='text'], .form--login input[type='password'], select { background-color: #3b4148; border-bottom-left-radius: 0; border-top-left-radius: 0; } select,.form--login input[type='text']:focus, .form--login input[type='text']:hover, .form--login input[type='password']:focus, .form--login input[type='password']:hover { background-color: #434A52; } .form--login input[type='submit'] { background-color: #ea4c88; color: #eee; font-weight: bold; text-transform: uppercase; } .form--login input[type='submit']:focus, .form--login input[type='submit']:hover { background-color: #d44179; } .form__field { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; margin-bottom: 1rem; } .form__input { -webkit-box-flex: 1; -webkit-flex: 1; -ms-flex: 1; flex: 1; } .align { -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -webkit-flex-direction: row; -ms-flex-direction: row; flex-direction: row; } select{ color:white; border:none; outline: none; color: #ABABAB; } option{ background-color:#434A52; color:#ABABAB; } .hidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } .text--center { text-align: center; } .grid__container { margin: 0 auto; max-width: 20rem; width: 90%; } </style> <body> <body class='align'> <div class='site__container'> <div class='grid__container'> <form method='get' action='setting' class='form form--login'> <h1>Wifi Setup</h1> <div class='form__field' id='ssidlist'> <select name='ssid'>"+st+" </select> </div> <div class='form__field'> <input name='pass' id='login__password' type='password' class='form__input' placeholder='Password' required> </div> <div class='form__field'> <input name='device' id='login__password' type='text' class='form__input' placeholder='DeviceId' required> </div> <div class='form__field'> <input type='submit' value='Connect'> </div> </form> <p class='text--center'>SSID not found? <a onclick='showSSID()'>Enter Manually</a> <span class='fontawesome-arrow-right'></span></p> </div> </div> </body> </body> </html> <script> function showSSID(){ document.getElementById('ssidlist').style.display = 'none'; document.getElementById('ssid').style.display = 'block'; } </script>";
        //content += "</p><form method='get' action='setting'><label>SSID: </label><input name='ssid' length=32><input name='pass' length=64><input type='submit'></form>";
         //content += "</html>";
        server.send(200, "text/html", content);  
    });
    server.on("/setting", [this]() {
        String qsid = server.arg("ssid");
        String qpass = server.arg("pass");
        String qid = server.arg("device");
        content ="";
        if (qsid.length() > 0 && qpass.length() > 0) {
          writeCredentials(qsid, qpass, qid);
   
        } else {
          content = "{\"Error\":\"404 not found\"}";
          statusCode = 404;
          printer->println("Sending 404");
        }

        server.send(200, "application/json", content);
        WiFi.disconnect();
        delay(2000);
        EEPROM.end();
        hardReboot();
    });
  } else if (webtype == 0) {
    server.on("/", [this]() {
      IPAddress ip = WiFi.localIP();
      String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
      server.send(200, "application/json", "{\"IP\":\"" + ipStr + "\"}");
    });
    server.on("/cleareeprom", [this]() {
      content = "<!DOCTYPE HTML>\r\n<html>";
      content += "<p>Clearing the EEPROM</p></html>";
      server.send(200, "text/html", content);
      clearEEPROM();
      hardReboot();
    });
  }
  
}
Пример #4
0
void setupAP(){
	WiFi.softAP(espssid);
  server.on("/", handleRoot);
  server.on("/config", handleConfig);
  server.on("/erase", handleErase);
	server.begin();
  Serial.println();
  Serial.print("connected as AP ");
  Serial.println(espssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP()); 	
}
Пример #5
0
void setup() {
  pinMode(LDR, INPUT);
  pinMode(BUTTON, INPUT);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

  delay(1000);
  Serial.begin(115200);

  Serial.println("Wifi Connecting");

  WiFi.begin(wifiSSID, wifiPassword);
  wifi_station_set_auto_connect(true);
  wifi_station_set_hostname(wiFiHostname);
  wifiConnectCounter = 1;
  while (WiFi.status() != WL_CONNECTED) {
    delay(wifiRepeatInterval);
    wifiConnectCounter++;
    if (wifiConnectCounter > wifiMaxTries) {
      delay(wifiRepeatInterval * 1000 * 1000);
      wifiConnectCounter = 0;
    }
  }
  Serial.println("Wifi Connected");

  server.on("/", handleRoot);
  server.begin();
}
Пример #6
0
void webServerSetup() {
  webServer.on("/status.json", handleStatus);
  webServer.serveStatic("/config.json", SPIFFS, "/config.json");
  webServer.serveStatic("/", SPIFFS, "/public/index.html");
  webServer.serveStatic("/assets/brewMonitor.js", SPIFFS, "/public/assets/brewMonitor.js");
  webServer.onNotFound(handleNotFound);

  webServer.begin();
}
Пример #7
0
void setup()
{
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT);
  if (digitalRead(BUTTON_PIN) == 0)
  {
    Serial.println("Factory Reset");
  }

  WiFiManager wifi;
  wifi.autoConnect(DEVICE_NAME);

  if (!mdns.begin(DEVICE_NAME, WiFi.localIP()))
  {
    Serial.println("Error setting up MDNS responder!");
  }
  else
  {
    Serial.println("mDNS responder started");
  }

  // Start TCP (HTTP) server
  server.begin();
  Serial.println("TCP server started");

  Serial.println("Listening on port 8266");

  Serial.print("Sketch size: ");
  Serial.println(ESP.getSketchSize());
  Serial.print("Free size: ");
  Serial.println(ESP.getFreeSketchSpace());
  
  server.on("/", handle_root);
  server.on("/on", handle_on);
  server.on("/off", handle_off);

  httpUpdater.setup(&server);

  state = OFF;
  Serial.println("State: OFF");
  pinMode(LED_PIN, OUTPUT);
}
Пример #8
0
void setup() {
	delay(1000);
	Serial.begin(115200);
	lightMeter.begin();
	delay(1000);
	Serial.println();
	Serial.print("Configuring access point...");
	/* You can remove the password parameter if you want the AP to be open. */
	WiFi.softAP(ssid, password);

	IPAddress myIP = WiFi.softAPIP();
	Serial.print("AP IP address: ");
	Serial.println(myIP);

	server.on("/",handleWebsite);
	server.on("/xml",handleXML);

	server.begin();
	Serial.println("HTTP server started");

}
Пример #9
0
void WifiServerinit(void){

  if (MDNS.begin(host)) {
    MDNS.addService("http", "tcp", 80);
    DBG_OUTPUT_PORT.println("MDNS responder started");
    DBG_OUTPUT_PORT.print("You can now connect to http://");
    DBG_OUTPUT_PORT.print(host);
    DBG_OUTPUT_PORT.println(".local");
  }

  // uri,HTTPメソッド,そのメソッドに対応する関数を指定する
  server.on("/list", HTTP_GET, printDirectory);
  server.on("/edit", HTTP_DELETE, handleDelete);
  server.on("/edit", HTTP_PUT, handleCreate);
  server.on("/edit", HTTP_POST, [](){ returnOK(); });
  server.onNotFound(handleNotFound); // ハンドラが割り当てられていない場合に呼び出す関数の設定
  server.onFileUpload(handleFileUpload); // ファイルアップロード

  server.begin();
  DBG_OUTPUT_PORT.println("HTTP server started");
}
Пример #10
0
void Wifi::begin(Stream &s) {
    _s = &s;
    //USE_SERIAL.begin(921600);
    USE_SERIAL.begin(115200);

    //USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    int n = WiFi.scanNetworks();
    Serial.println("[SETUP] SCANNING...");
    Serial.println("");
    if (n == 0)
      USE_SERIAL.println("no networks found");
    else
    {
      USE_SERIAL.print(n);
      USE_SERIAL.println(" networks found");
      for (int i = 0; i < n; ++i)
      {
        // Print SSID and RSSI for each network found
        USE_SERIAL.print(i + 1);
        USE_SERIAL.print(": ");
        USE_SERIAL.print(WiFi.SSID(i));
        USE_SERIAL.print(" (");
        USE_SERIAL.print(WiFi.RSSI(i));
        USE_SERIAL.print(")");
        USE_SERIAL.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
        delay(10);
      }
    }
    Serial.println("");

    WiFiMulti.addAP(NETWORKNAME, NETWORKPASS);

    while(WiFiMulti.run() != WL_CONNECTED) {
        delay(100);
    }

    USE_SERIAL.print("IP address: ");
    USE_SERIAL.println(WiFi.localIP());
    USE_SERIAL.flush();

    // start webSocket server
    webSocket.begin();
    webSocket.onEvent(webSocketEvent);

    if(MDNS.begin("esp8266")) {
        USE_SERIAL.println("MDNS responder started");
    }

    // handle index
    server.on("/", []() {
        // send index.html
        server.send(200, "text/html", "<html><head><script>var connection = new WebSocket('ws://'+location.hostname+':8899/', ['arduino']);connection.onopen = function () {  connection.send('Connect ' + new Date()); }; connection.onerror = function (error) {    console.log('WebSocket Error ', error);};connection.onmessage = function (e) {  console.log('Server: ', e.data);};function sendRGB() {  var r = parseInt(document.getElementById('r').value).toString(16);  var g = parseInt(document.getElementById('g').value).toString(16);  var b = parseInt(document.getElementById('b').value).toString(16);  if(r.length < 2) { r = '0' + r; }   if(g.length < 2) { g = '0' + g; }   if(b.length < 2) { b = '0' + b; }   var rgb = '#'+r+g+b;    console.log('RGB: ' + rgb); connection.send(rgb); }</script></head><body>LED Control:<br/><br/>R: <input id=\"r\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" onchange=\"sendRGB();\" /><br/>G: <input id=\"g\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" onchange=\"sendRGB();\" /><br/>B: <input id=\"b\" type=\"range\" min=\"0\" max=\"255\" step=\"1\" onchange=\"sendRGB();\" /><br/></body></html>");
    });

    server.begin();

    // Add service to MDNS
    MDNS.addService("http", "tcp", 80);
    MDNS.addService("ws", "tcp", 8899);

}
Пример #11
-1
void setup(void){
  pinMode(led, OUTPUT);
  digitalWrite(led, LED_OFF);
  // Note the serial rate - if you don't match it when connecting you'll get garbage.
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // This tells the network that you can access the ip address of the esp8266 via 'esp8266.local'
  // The first arg is the hostname - '.local' will be appended to it, the second arg is the ip address
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  
  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}