Advertisement
NittyGritty

ESP8266_Setup

Mar 15th, 2017
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266WebServer.h>
  3. #include <SPI.h>
  4. #include <Adafruit_GFX.h>
  5. #include <Max72xxPanel.h>
  6.  
  7. #include <ArduinoOTA.h>
  8. #include <ESP8266mDNS.h>
  9. #include <DNSServer.h>
  10. #include <ESP8266WebServer.h>
  11.  
  12. // Helps with connecting to internet
  13. #include <WiFiManager.h>
  14.  
  15. // HOSTNAME for OTA update
  16. #define HOSTNAME "ESP8266-OTA-"
  17.  
  18. void configModeCallback (WiFiManager *myWiFiManager);
  19.  
  20. void setup(void) {
  21.  
  22. //ESP.wdtDisable();                               // used to debug, disable wachdog timer,
  23.   Serial.begin(115200);                           // full speed to monitor
  24.                                
  25.  
  26.     //WiFiManager
  27.   //Local intialization. Once its business is done, there is no need to keep it around
  28.   WiFiManager wifiManager;
  29.   // Uncomment for testing wifi manager
  30.   // wifiManager.resetSettings();
  31.   wifiManager.setAPCallback(configModeCallback);
  32.  
  33.   //or use this for auto generated name ESP + ChipID
  34.   wifiManager.autoConnect();
  35.  
  36.   // OTA Setup
  37.   String hostname(HOSTNAME);
  38.   hostname += String(ESP.getChipId(), HEX);
  39.   WiFi.hostname(hostname);
  40.   ArduinoOTA.setHostname((const char *)hostname.c_str());
  41.   ArduinoOTA.begin();
  42.  
  43.   while (WiFi.status() != WL_CONNECTED) {         // Wait for connection
  44.     delay(500);
  45.     Serial.print(".");
  46.   }
  47.  
  48.     // Set up the endpoints for HTTP server,  Endpoints can be written as inline functions:
  49.   server.on("/", []() {
  50.     server.send(200, "text/html", form);
  51.   });
  52.   server.on("/msg", handle_msg);                  // And as regular external functions:
  53.   server.begin();                                 // Start the server
  54.  
  55.   char result[255];
  56.   sprintf(result, "WebServer ready! Send Message using http://%1d.%1d.%1d.%1d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
  57.   Serial.println();
  58.   Serial.println(result);
  59.   Serial.println(WiFi.localIP());                 // Serial monitor prints localIP
  60.  
  61. }
  62.  
  63. // Called if WiFi has not been configured yet
  64. void configModeCallback (WiFiManager *myWiFiManager) {
  65.   Serial.println("Wifi Manager");
  66.   Serial.println("Please connect to AP");
  67.   Serial.println(myWiFiManager->getConfigPortalSSID());
  68.   Serial.println("To setup Wifi Configuration");
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement