void setup() { Serial.begin(115200); delay(10); setup_wifi(); client.setServer(mqtt_server, 1883); Wire.begin(SDA, SCL); //sda,scl Serial.println("Sensor Test"); if (!bmp.begin()) { Serial.print("Ooops, no BMP180 detected ... Check your wiring or I2C ADDR!"); while (1); } else { Serial.println("BMP180 ready."); delay(1000); } /* OTA code */ ArduinoOTA.onStart([]() { Serial.println("Start"); }); ArduinoOTA.onEnd([]() { Serial.println("\nEnd"); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); ArduinoOTA.begin(); // Set up mDNS responder: // - first argument is the domain name, in this example // the fully-qualified domain name is "esp8266.local" // - second argument is the IP address to advertise // we send our IP address on the WiFi network if (!MDNS.begin(hostname, WiFi.localIP())) { Serial.println("Error setting up MDNS responder!"); while(1) { delay(1000); } } Serial.print("mDNS responder started: "); Serial.print(hostname); Serial.println(".local"); httpUpdater.setup(&httpServer); httpServer.begin(); MDNS.addService("http", "tcp", 80); }
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); }