Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- #include <SPI.h>
- #include <Adafruit_GFX.h>
- #include <Max72xxPanel.h>
- #include <ArduinoOTA.h>
- #include <ESP8266mDNS.h>
- #include <DNSServer.h>
- #include <ESP8266WebServer.h>
- // Helps with connecting to internet
- #include <WiFiManager.h>
- // HOSTNAME for OTA update
- #define HOSTNAME "ESP8266-OTA-"
- void configModeCallback (WiFiManager *myWiFiManager);
- void setup(void) {
- //ESP.wdtDisable(); // used to debug, disable wachdog timer,
- Serial.begin(115200); // full speed to monitor
- //WiFiManager
- //Local intialization. Once its business is done, there is no need to keep it around
- WiFiManager wifiManager;
- // Uncomment for testing wifi manager
- // wifiManager.resetSettings();
- wifiManager.setAPCallback(configModeCallback);
- //or use this for auto generated name ESP + ChipID
- wifiManager.autoConnect();
- // OTA Setup
- String hostname(HOSTNAME);
- hostname += String(ESP.getChipId(), HEX);
- WiFi.hostname(hostname);
- ArduinoOTA.setHostname((const char *)hostname.c_str());
- ArduinoOTA.begin();
- while (WiFi.status() != WL_CONNECTED) { // Wait for connection
- delay(500);
- Serial.print(".");
- }
- // Set up the endpoints for HTTP server, Endpoints can be written as inline functions:
- server.on("/", []() {
- server.send(200, "text/html", form);
- });
- server.on("/msg", handle_msg); // And as regular external functions:
- server.begin(); // Start the server
- char result[255];
- sprintf(result, "WebServer ready! Send Message using http://%1d.%1d.%1d.%1d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]);
- Serial.println();
- Serial.println(result);
- Serial.println(WiFi.localIP()); // Serial monitor prints localIP
- }
- // Called if WiFi has not been configured yet
- void configModeCallback (WiFiManager *myWiFiManager) {
- Serial.println("Wifi Manager");
- Serial.println("Please connect to AP");
- Serial.println(myWiFiManager->getConfigPortalSSID());
- Serial.println("To setup Wifi Configuration");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement