Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <Arduino.h> //https://www.youtube.com/watch?v=wG1I7JeEXE8&t=71s
  2.  
  3. /*
  4.   To upload through terminal you can use: curl -u admin:admin -F "image=@firmware.bin" esp8266-webupdate.local/firmware
  5. */
  6.  
  7. #include <ESP8266WiFi.h>
  8. #include <WiFiClient.h>
  9. #include <ESP8266WebServer.h>
  10. #include <ESP8266mDNS.h>
  11. #include <ESP8266HTTPUpdateServer.h>
  12.  
  13. const char* host = "esp8266-sanusb";
  14. const char* update_path = "/update";
  15. const char* update_username = "sanusb";
  16. const char* update_password = "sanusb";
  17. const char* ssid = "RFID";
  18. const char* password = "l43s3rf1d";
  19.  
  20. //IPAddress mystaticip(192, 168, 1, 195); //Configuração de IP estático
  21. //IPAddress mygateway(192, 168, 1, 1);
  22. //IPAddress mysubnet(255, 255, 255, 0);
  23.  
  24. ESP8266WebServer httpServer(80);
  25. ESP8266HTTPUpdateServer httpUpdater;
  26.  
  27. void setup(void){
  28.  
  29.   Serial.begin(115200);
  30.   Serial.println();
  31.   Serial.println("Booting Sketch...");
  32.   WiFi.mode(WIFI_AP_STA);
  33.   WiFi.begin(ssid, password);
  34.  
  35.   while(WiFi.waitForConnectResult() != WL_CONNECTED){
  36.     delay(500);
  37.     Serial.print(".");
  38.   }
  39.       delay(5000);
  40.   MDNS.begin(host);
  41.  
  42.   httpUpdater.setup(&httpServer, update_path, update_username, update_password);
  43.   httpServer.begin();
  44.  
  45.   MDNS.addService("http", "tcp", 80);
  46.  
  47.   Serial.print("Atualizacao remota (OTA) iniciada com sucesso! Abra http://");
  48.   Serial.print(WiFi.localIP());
  49.   Serial.println("/update no browser");
  50.   //Serial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and password '%s'\n", host, update_path, update_username, update_password);
  51. }
  52.  
  53. void loop(void){
  54.   httpServer.handleClient();
  55.  
  56.   digitalWrite(13, 0); digitalWrite(12, 1);// turn the LED on
  57.   delay(1500); // wait
  58.   digitalWrite(13, 1); digitalWrite(12, 0);// turn the LED off
  59.   delay(1500);
  60.   Serial.printf("SanUSBHERICSON\r\n");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement