Advertisement
Guest User

basicotadiag

a guest
Jan 18th, 2016
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266mDNS.h>
  3. #include <WiFiUdp.h>
  4. #include <ArduinoOTA.h>
  5. #include <Base64.h>
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8.  
  9. #define ONE_WIRE_BUS 0  // DS18B20 pin
  10. const char* ssid = "Tell my WiFi I love her";
  11. const char* password = "xxxxxxxxxxxx";
  12.  
  13. OneWire oneWire(ONE_WIRE_BUS);
  14. DallasTemperature DS18B20(&oneWire);
  15.  
  16. void setup() {
  17.   Serial.begin(115200);
  18.   Serial.println();
  19.   Serial.println();
  20.   Serial.println("Booting");
  21.  
  22.   WiFi.mode(WIFI_STA);
  23.   WiFi.begin(ssid, password);
  24.   while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  25.     Serial.println("Connection Failed! Rebooting...");
  26.     delay(5000);
  27.     ESP.restart();
  28.   }
  29.  
  30.   // Port defaults to 8266
  31.   // ArduinoOTA.setPort(8266);
  32.  
  33.   // Hostname defaults to esp8266-[ChipID]
  34.   // ArduinoOTA.setHostname("mc01");
  35.  
  36.   // No authentication by default
  37.   // ArduinoOTA.setPassword((const char *)"123");
  38.  
  39.   ArduinoOTA.onStart([]() {
  40.     Serial.println();
  41.     Serial.println();
  42.     Serial.println("Receiving OTA update");
  43.   });
  44.   ArduinoOTA.onEnd([]() {
  45.     Serial.println("done!");
  46.     Serial.println();
  47.     Serial.println();
  48.   });
  49.   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  50.     Serial.print(".");
  51.   });
  52.   ArduinoOTA.onError([](ota_error_t error) {
  53.     Serial.printf("Error[%u]: ", error);
  54.     if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  55.     else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  56.     else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  57.     else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  58.     else if (error == OTA_END_ERROR) Serial.println("End Failed");
  59.   });
  60.   ArduinoOTA.begin();
  61.   Serial.println("Ready");
  62.   Serial.print("IP address: ");
  63.   Serial.println(WiFi.localIP());
  64.  
  65.   DS18B20.begin();
  66. }
  67.  
  68. void loop() {
  69.   float temp;
  70.  
  71.   //do {
  72.     DS18B20.requestTemperatures();
  73.     temp = DS18B20.getTempCByIndex(0);
  74.     Serial.print("Temperature: ");
  75.     Serial.println(temp);
  76.   //} while (temp == 85.0 || temp == (-127.0));
  77.  
  78.   int cnt = 30; // 15 seconds to catch updates / commands
  79.   while (cnt--) {
  80.     ArduinoOTA.handle();
  81.     delay(100);  
  82.   }
  83. }
Advertisement
RAW Paste Data Copied
Advertisement