void reconnectI() { if ( testWifi() ) { PlnSerial("Connected Successfully"); return; } // otherwise, set up an access point to input SSID and password else { PlnSerial(""); PlnSerial("Connect timed out, opening AP"); setupAP(); } } void writeReg(uint8_t reg_address, uint8_t data) { Wire.beginTransmission(BME280_ADDRESS); Wire.write(reg_address); Wire.write(data); Wire.endTransmission(); } void otaupdate() { if(WiFi.waitForConnectResult() == WL_CONNECTED){ Serial.println ("In the updating file"); Serial.print("updatestring = "); Serial.println(updatestring); // http://boatautomation.com/wsm/updatewsm1.php?macid=''&firmware='AP12'&versionnum='3.00'&whatis='T'&devicetodo=' // t_httpUpdate_return ret = ESPhttpUpdate.update("http://boatautomation.com/wsm/update/WebUpdate-jojo1.bin"); // t_httpUpdate_return ret = ESPhttpUpdate.update("http://boatautomation.com", 80, "/wsm/updatewsm1.php", who); t_httpUpdate_return ret = ESPhttpUpdate.update(updatestring, "test"); // t_httpUpdate_return ret = ESPhttpUpdate.update("http://boatautomation.com/wsm/updatewsm1.php"); //t_httpUpdate_return ret = ESPhttpUpdate.update("https://server/file.bin"); switch(ret) { case HTTP_UPDATE_FAILED: USE_SERIAL.printf("HTTP_UPDATE_FAILED Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); Serial.println("");Serial.println("No update available"); // Serial.println(""); // Serial.print("Mem left = "); Serial.println(ESP.getFreeSketchSpace()); break; case HTTP_UPDATE_NO_UPDATES: USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES"); Serial.println("");Serial.println("No update available"); // Serial.println("HTTP_UPDATE_NO_UPDATES"); break; case HTTP_UPDATE_OK: USE_SERIAL.println("HTTP_UPDATE_OK"); Serial.println("Updated"); // Serial.println("HTTP_UPDATE_OK"); break; } } // ESPhttpUpdate.update("75.103.94.221", 80, "/arduino.bin"); // ESPhttpUpdate.update("http://www.aacdata.net", 80, "/wsm/update/arduino.bin"); // Serial.println ("Done updating file"); // Serial.println("Rebooting"); // delay(500); // ESP.restart(); } void dowhatis() { thermostat = 0 ; aircond = 0 ; heater = 0 ; if (whatis == "B") { // devicetype = "temp-volt-baro"; // devicetodo = "t,v, , , , ,a, ,"; devicetype = "temp-volt"; devicetodo = "t,v, , , , , , ,"; } else if (whatis == "C") { devicetype = "temp-volt-switch"; devicetodo = "t,v,s, , , , , , "; } else if (whatis == "D") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; } else if (whatis == "d") { devicetype = "temp-volt-pump-rev"; devicetodo = "t,v, ,p, , , , , "; preverse = 1; } else if (whatis == "E") { devicetype = "temp-switch"; devicetodo = "t, ,s, , , , , , "; } else if (whatis == "F") { devicetype = "temp-switch-heater"; devicetodo = "t, ,s, , ,h, , , "; thermostat = 1 ; heater = 1 ; } else if (whatis == "G") { devicetype = "temp-switch-a/c"; devicetodo = "t, ,s, , ,a, , , "; thermostat = 1 ; aircond = 1 ; } else if (whatis == "H") { devicetype = "temp-switch-heater & A/C"; devicetodo = "t, ,s, , ,b, , , "; thermostat = 1 ; aircond = 1 ; heater = 1 ; } else if (whatis == "P") { devicetype = "pump"; devicetodo = " , , ,p, , , , , "; tempfreq = 2 ; } else if (whatis == "Q") { devicetype = "pump"; devicetodo = " , , ,p, , , , , "; preverse = 1; tempfreq = 2 ; } else if (whatis == "p") { // power failure devicetype = "power"; devicetodo = " , , , , , , , ,p"; tempfreq = 2 ; } else if (whatis == "o") { // power failure + temp devicetype = "power & temp"; devicetodo = "t, , , , , , , ,p"; dhttemp = 0; // ds18b20 sensor } else if (whatis == "R") { // device means reading 0 - 1023 on adc devicetype = "dev"; devicetodo = " , , ,d, , , , , "; } else if (whatis == "S") { devicetype = "switch"; devicetodo = " , ,s, , , , , , "; tempfreq = 2 ; } else if ( whatis == "T") { devicetype = "temp"; devicetodo = "t, , , , , , , , "; dhttemp = 0; // ds18b20 sensor } else if (whatis == "U") { devicetype = "push button"; devicetodo = " , , , ,b, , , "; tempfreq = 2 ; } else if (whatis == "V") { devicetype = "volt"; devicetodo = " ,v, , , , , , , "; } else if (whatis == "v") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; dhttemp = 1; // dht22 sensor } else if (whatis == "W") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; dhttemp = 1; // dht22 sensor preverse = 1; } else if (whatis == "w") { devicetype = "temp, volt, switch, pump & push button"; devicetodo = "t,v,s,p,b, , , "; } else if (whatis == "X") { devicetype = "temp & push button"; devicetodo = "t, , , ,b, , , "; } else if ( whatis == "Y") { devicetype = "temp"; devicetodo = "t, , , , , , , , "; dhttemp = 1; // dht22 sensor } else if ( whatis == "y") { devicetype = "temp-volt"; devicetodo = "t,v, , , , , , , "; dhttemp = 1; // dht22 sensor } else if ( whatis == "Z") { devicetype = "temp"; devicetodo = "t, , , , , , , , "; dhttemp = 2; // 500 to 800 degrees heat } else if ( whatis == "Z") { devicetype = "temp-volt"; devicetodo = "t,v, , , , , , , "; dhttemp = 2; // 500 to 800 degrees heat } else if ( whatis == "1") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; dhttemp = 2; // 500 to 800 degrees heat } else if ( whatis == "2") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; dhttemp = 2; // 500 to 800 degrees heat preverse = 1; } if (devicetodo.substring(4,5) == "s" ) { // buttonupdt = 1 ; // relay pin // pinMode(BUTTON, INPUT_PULLUP); pinMode(BUTTON, OUTPUT); // grab the current state of the button current = digitalRead(BUTTON); currentold = 0 ; PSerial (""); PSerial ("Button = "); PlnSerial(String(current)); } if (devicetodo.substring(6,7) == "p" ) { // relay pin // pinMode(PUMP1, INPUT_PULLUP); pinMode(PUMP1, INPUT); pinMode(PUMP2, INPUT); pinMode(PUMP3, INPUT); pinMode(PUMP4, INPUT); // digitalWrite(PUMP1, LOW); // digitalWrite(PUMP2, LOW); // digitalWrite(PUMP3, LOW); // pinMode(BUTTON, OUTPUT); // grab the current state of the button Pcurrent = digitalRead(PUMP1); Pcurrentold = Pcurrent ; Pcurrent2 = digitalRead(PUMP2); Pcurrentold2 = Pcurrent2 ; Pcurrent3 = digitalRead(PUMP3); Pcurrentold3 = Pcurrent3 ; Pcurrent4 = digitalRead(PUMP4); Pcurrentold4 = Pcurrent4 ; PSerial (""); PSerial ("Pump1 = "); PlnSerial(String(Pcurrent)); PSerial ("Pump2 = "); PlnSerial(String(Pcurrent2)); PSerial ("Pump3 = "); PlnSerial(String(Pcurrent3)); PSerial ("Pump4 = "); PlnSerial(String(Pcurrent4)); if (devicetodo.substring(4,5) == " " ) { pinMode(BUTTON, INPUT); digitalWrite(BUTTON, LOW); // grab the current state of the button current = digitalRead(BUTTON); currentold = 0 ; PSerial ("B1 = "); PlnSerial(String(current)); } if (devicetodo.substring(8,9) == " " ) { // buttonupdt = 1 ; pinMode(BUTT, INPUT); // grab the current state of the button curr = digitalRead(BUTT); currold = 0 ; PSerial (""); PSerial ("B2 = "); PlnSerial(String(curr)); } } if (devicetodo.substring(8,9) == "b" ) { // relay pin // pinMode(BUTTON, INPUT_PULLUP); pinMode(BUTT, OUTPUT); // grab the current state of the button curr = digitalRead(BUTT); currold = 0 ; PSerial (""); PSerial ("Push Button = "); PlnSerial(String(curr)); } if (devicetodo.substring(8,9) == "h" ) { thermostat = 1 ; heater = 1 ; PSerial (""); PSerial ("Heater is = "); PlnSerial(String(heater)); } if (devicetodo.substring(8,9) == "a" ) { thermostat = 1 ; aircond = 1 ; PSerial (""); PSerial ("A/C is = "); PlnSerial(String(aircond)); } } void PSerial(String value) { if (details != 0 ) { Serial.print(value); } } void PlnSerial(String value) { if (details != 0 ) { Serial.println(value); } } void readTrim() { uint8_t data[32],i=0; Wire.beginTransmission(BME280_ADDRESS); Wire.write(0x88); Wire.endTransmission(); Wire.requestFrom(BME280_ADDRESS,24); while(Wire.available()){ data[i] = Wire.read(); i++; } Wire.beginTransmission(BME280_ADDRESS); Wire.write(0xA1); Wire.endTransmission(); Wire.requestFrom(BME280_ADDRESS,1); data[i] = Wire.read(); i++; Wire.beginTransmission(BME280_ADDRESS); Wire.write(0xE1); Wire.endTransmission(); Wire.requestFrom(BME280_ADDRESS,7); while(Wire.available()){ data[i] = Wire.read(); i++; } dig_T1 = (data[1] << 8) | data[0]; dig_T2 = (data[3] << 8) | data[2]; dig_T3 = (data[5] << 8) | data[4]; dig_P1 = (data[7] << 8) | data[6]; dig_P2 = (data[9] << 8) | data[8]; dig_P3 = (data[11]<< 8) | data[10]; dig_P4 = (data[13]<< 8) | data[12]; dig_P5 = (data[15]<< 8) | data[14]; dig_P6 = (data[17]<< 8) | data[16]; dig_P7 = (data[19]<< 8) | data[18]; dig_P8 = (data[21]<< 8) | data[20]; dig_P9 = (data[23]<< 8) | data[22]; dig_H1 = data[24]; dig_H2 = (data[26]<< 8) | data[25]; dig_H3 = data[27]; dig_H4 = (data[28]<< 4) | (0x0F & data[29]); dig_H5 = (data[30] << 4) | ((data[29] >> 4) & 0x0F); dig_H6 = data[31]; } int mdns1(int webtype){ // Check for any mDNS queries and send responses //mdns.update(); // Check if a client has connected WiFiClient client = server.available(); if (!client) { return(20); } Serial.print("Time elapsed: ");Serial.println(String(flipcount/2)); Serial.println(""); Serial.println("New client"); // Wait for data from client to become available while(client.connected() && !client.available()){ delay(1); } // Read the first line of HTTP request String req = client.readStringUntil('\r'); // First line of HTTP request looks like "GET /path HTTP/1.1" // Retrieve the "/path" part by finding the spaces int addr_start = req.indexOf(' '); int addr_end = req.indexOf(' ', addr_start + 1); if (addr_start == -1 || addr_end == -1) { Serial.print("Invalid request: "); Serial.println(req); Serial.print("Time elapsed: ");Serial.println(String(flipcount/2)); return(20); } req = req.substring(addr_start + 1, addr_end); Serial.print("Request: "); Serial.println(req); client.flush(); String s; s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from All Automations"; s += "
"; if ( webtype == 1 ) { // in ap server mode } s += "\r\n\r\n"; client.print(s); Serial.println("Done with client"); Serial.print("Time elapsed: ");Serial.println(String(flipcount/2)); return(20); }