void setupAP(void) { configMode = true; // in config mode Serial.print("Configuring access point..."); /* You can remove the password parameter if you want the AP to be open. */ WiFi.softAPConfig(apIP, apIP, netMsk); // WiFi.softAP(softAP_ssid, softAP_password); // WiFi.softAP(softAP_ssid.c_str(), softAP_password.c_str()); WiFi.softAP(softAP_ssid.c_str()); // WiFi.softAP(softAP_ssid); delay(1000); // Without delay I've seen the IP address blank // delay(100); // Without delay I've seen the IP address blank //// Serial.print("AP IP address: "); Serial.println(WiFi.softAPIP()); /* Setup the DNS server redirecting all the domains to the apIP */ // dnsServer.setErrorReplyCode(DNSReplyCode::NoError); // dnsServer.start(DNS_PORT, "*", apIP); } /** Is this an IP? */ boolean isIp(String str) { for (int i = 0; i < str.length(); i++) { int c = str.charAt(i); if (c != '.' && (c < '0' || c > '9')) { return false; } } return true; } void cleareeprom() { for (int i = 0; i < 256; ++i) { EEPROM.write(i, clearchar[0]); } // String firsteeprom = "+"; // firsteeprom = "9"; // EEPROM.write(0, firsteeprom[0] ); EEPROM.commit(); Serial.print ("EEPROM.read(0) = "); Serial.println (EEPROM.read(0)); Serial.print ("char(EEPROM.read(0)) = "); Serial.println (char(EEPROM.read(0))); Serial.println ("Cleared Eeprom"); } /** IP to String? */ String toStringIp(IPAddress ip) { String res = ""; for (int i = 0; i < 3; i++) { res += String((ip >> (8 * i)) & 0xFF) + "."; } res += String(((ip >> 8 * 3)) & 0xFF); return res; } void senddatatoapi() { if ( !getPage() ) { PlnSerial("GET request failed"); sentapi = 0 ; } else { PlnSerial("GET request succeded"); sentapi = 1 ; } } bool getPage() { WiFiClient client; // Attempt to make a connection to the remote server if ( !client.connect(http_site, http_port) ) { // if (!client.connect(Accessip, Accesport)) { return false; } if ( tempreading = "C" ) { float temptodisp = valuedev1; } else { // to change to celcius or farhaneigh float temptodisp = (valuedev1*1.8)+32; } if (precision == 1) { temptodisp = round(temptodisp * 10); temptodisp = temptodisp/10 ; PSerial("temptodisp after making it 1 decimal = ");PlnSerial (String (temptodisp)); temptodisp = (int) round(temptodisp) ; PSerial("temptodisp after making it integer and rounded = ");PlnSerial (String (temptodisp)); } else { temptodisp = (round(temptodisp * precision) ) ; // / precision ; temptodisp = (temptodisp / precision) ; // / precision ; } matrix.print(temptodisp, DEC); matrix.writeDisplay(); if (preverse == 1 ) { if (Pcurrent == 1) { Pcurrent = 0 ; PlnSerial("in if preverse and pcurrent = 1 "); } else { Pcurrent = 1 ; PlnSerial("in if preverse and pcurrent = 0 "); } } PSerial("Pcurrent = "); PlnSerial(String(Pcurrent)); if (dhttemp == 1) { valuedev1 = temp_f ; valuedev2 = humidity; } String strvaluedev1 = "" ; if ( valuedev1 == -127 || valuedev1 == 185 || valuedev1 == 0) { strvaluedev1 = "n/a" ; } else { strvaluedev1 = String(valuedev1) ; } String strvaluedev2 = "" ; if ( valuedev2 == -127 || valuedev2 == 185 || valuedev1 == 0) { strvaluedev2 = "n/a" ; } else { strvaluedev2 = String(valuedev2) ; } if (devicetodo.substring(12,13) == "a" ) { strvaluedev1 = temp_act; strvaluedev2 = hum_act; pressureKPA = press_act; } String toprint = "" ; // Make an HTTP GET request // String toprint = "GET http://boatautomation.com/jojo/sendtoAPI-1.php?macid='"+String(MAC_char)+"'&temp1='"+String(valuedev1)+"'&temp2='"+String(valuedev2)+"'&temp3='"+String(valuedev3)+"'&freq='"+String(freq)+"'&rebootfreq='"+String(rebootfreq)+"'&ip='"+ipadd+"' HTTP/1.1" ; if ( buttonupdt == 1) { // if ( datetosave == " " ) { PlnSerial("in buttonupdt = 1"); toprint = wheretosend + "?macid='"+String(MAC_char)+"'&datesaved='"+String(datetosave)+"'&power='"+"'&baro='"+String(pressureKPA,1)+String(pcurrent)+"'&pushbutton='"+String(curr)+"'&button='"+String(current)+"'&pump='"+String(Pcurrent)+"'&pump2='"+String(Pcurrent2)+"'&pump3='"+String(Pcurrent3)+"'&signal='"+String(rssi)+"'&temp1='"+String(strvaluedev1)+"'&temp2='"+String(strvaluedev2)+"'&temp3='"+String(valuedev3)+"'&freq='"+String(freq)+"'&rebootfreq='"+String(rebootfreq)+"'&clientcode='"+String(clientcode)+"'&ip='"+ipadd+"' HTTP/1.1" ; //"'&pump='"+String(Pcurrent1)+"'&pump2='"+String(Pcurrent2)+"'&pump3='"+String(Pcurrent3)+ if ((devicetodo.substring(4,5) == "s" ) || (devicetodo.substring(8,9) == "b" )) { buttonupdt = 0 ; } } else { // toprint = wheretosend + "?macid='"+String(MAC_char)+"'&pump='"+String(Pcurrent)+"'&signal='"+String(rssi)+"'&temp1='"+String(strvaluedev1)+"'&temp2='"+String(strvaluedev2)+"'&temp3='"+String(valuedev3)+"'&freq='"+String(freq)+"'&rebootfreq='"+String(rebootfreq)+"'&clientcode='"+String(clientcode)+"'&ip='"+ipadd+"' HTTP/1.1" ; toprint = wheretosend + "?macid='"+String(MAC_char)+"'&datesaved='"+String(datetosave)+"'&power='"+String(pcurrent)+"'&baro='"+String(pressureKPA,1)+"'&pushbutton='"+5+"'&button='"+5+"'&pump='"+String(Pcurrent)+"'&pump2='"+String(Pcurrent2)+"'&pump3='"+String(Pcurrent3)+"'&signal='"+String(rssi)+"'&temp1='"+String(strvaluedev1)+"'&temp2='"+String(strvaluedev2)+"'&temp3='"+String(valuedev3)+"'&freq='"+String(freq)+"'&rebootfreq='"+String(rebootfreq)+"'&clientcode='"+String(clientcode)+"'&ip='"+ipadd+"' HTTP/1.1" ; } PSerial("toprint = "); PlnSerial(String(toprint)); client.println(toprint); //// client.println("GET /test.html HTTP/1.1"); client.print("Host: "); client.println(wheretosend + "?macid='"+String(MAC_char)+"'&signal='"+String(rssi)+"'&pump='"+String(Pcurrent)+"'&temp1='"+String(strvaluedev1)+"'&temp2='"+String(valuedev2)+"'&temp3='"+String(valuedev3)+"'&freq='"+String(freq)+"'&rebootfreq='"+String(rebootfreq)+"'&clientcode='"+String(clientcode)+"'&ip='"+ipadd+"'"); if (preverse == 1 ) { if (Pcurrent == 1) { Pcurrent = 0 ; PlnSerial("in if preverse and pcurrent = 1 "); } else { Pcurrent = 1 ; PlnSerial("in if preverse and pcurrent = 0 "); } } // delay(2000); while(client.available()){ String line = client.readStringUntil('\r'); PSerial("line = :"); PlnSerial(String(line)); } client.println("Connection: close"); client.println(); return true; } void getpressure(){ pressureKPA = mpl115a2.getPressure(); // Serial.print("Pressure (kPa): "); Serial.print(pressureKPA, 4); Serial.println(" kPa"); PSerial("Pressure (kPa): ");PSerial (String (pressureKPA, 4)) ; PlnSerial (" kPa") ; pressureKPA = 10*pressureKPA; // Serial.print("Pressure (mpar): "); Serial.print(pressureKPA, 4); Serial.println(" mpar"); PSerial("Pressure (mpar): ");PSerial (String (pressureKPA, 4)) ; PlnSerial (" mpar") ; Serial.print("Pressure (mpar): ");Serial.print (String (pressureKPA, 4)) ; Serial.println (" mpar") ; if (precision == 1) { pressureKPA = round(pressureKPA * 10); pressureKPA = pressureKPA/10 ; PSerial("pressureKPA after making it 1 decimal = ");PlnSerial (String (pressureKPA)); pressureKPA = (int) round(pressureKPA) ; PSerial("pressureKPA after making it integer and rounded = ");PlnSerial (String (pressureKPA)); } else { pressureKPA = round(pressureKPA * precision) ; pressureKPA = pressureKPA / precision ; PSerial("pressureKPA after * precision = ");PlnSerial (String (pressureKPA)); } // temperatureC = mpl115a2.getTemperature(); // Serial.print("Temp (*C): "); Serial.print(temperatureC, 1); Serial.println(" *C"); } void gettemp() { if (dhttemp == 1) { humidity = dht.readHumidity(); // Read humidity (percent) temp_f = dht.readTemperature(false); // Read temperature as Celsius if (isnan(humidity) || isnan(temp_f)) { PlnSerial("Failed to read from DHT sensor!"); temp_f = -127.0; humidity = -127.0; temptemp == -127.0 ; temptemp2 == -127.0 ; return; } else { temptemp = temp_f ; temptemp = temptemp + adjtemp ; temptemp2 = humidity ; temptemp2 = temptemp2 + adjtemp2 ; if (precision == 1) { temptemp = round(temptemp * 10); temptemp = temptemp/10 ; PSerial("temptemp after making it 1 decimal = ");PlnSerial (String (temptemp)); temptemp = (int) round(temptemp) ; PSerial("temptemp after making it integer and rounded = ");PlnSerial (String (temptemp)); temptemp2 = round(temptemp2 * 10); temptemp2 = temptemp2/10 ; PSerial("temptemp2 after making it 1 decimal = ");PlnSerial (String (temptemp2)); temptemp2 = (int) round(temptemp2) ; PSerial("temptemp2 after making it integer and rounded = ");PlnSerial (String (temptemp2)); } else { temptemp = (round(temptemp * precision) ) ; // / precision ; temptemp = (temptemp / precision) ; // / precision ; temptemp2 = (round(temptemp2 * precision) ) ; // / precision ; temptemp2 = (temptemp2 / precision) ; // / precision ; } } } else if (dhttemp == 2) { printTemp31855(temp.readThermocouple(CELSIUS)); temptemp = tempmax31855 ; if ( temptemp == 0 ) { temptemp == -127.0 ; temptemp2 == -127.0 ; return; } temptemp = temptemp + adjtemp ; PSerial("tempmax31855 temptemp = ");PlnSerial (String (temptemp)); printTemp31855(temp.readJunction(CELSIUS)); temptemp2 = tempmax31855 ; temptemp2 = temptemp2 + adjtemp2 ; PSerial("tempmax31855 temptemp2 = ");PlnSerial (String (temptemp2)); if (precision == 1) { temptemp = round(temptemp * 10); temptemp = temptemp/10 ; PSerial("temptemp after making it 1 decimal = ");PlnSerial (String (temptemp)); temptemp = (int) round(temptemp) ; PSerial("temptemp after making it integer and rounded = ");PlnSerial (String (temptemp)); temptemp2 = round(temptemp2 * 10); temptemp2 = temptemp2/10 ; PSerial("temptemp2 after making it 1 decimal = ");PlnSerial (String (temptemp2)); temptemp2 = (int) round(temptemp2) ; PSerial("temptemp2 after making it integer and rounded = ");PlnSerial (String (temptemp2)); } else { temptemp = (round(temptemp * precision) ) ; // / precision ; temptemp = (temptemp / precision) ; // / precision ; temptemp2 = (round(temptemp2 * precision) ) ; // / precision ; temptemp2 = (temptemp2 / precision) ; // / precision ; } } else if ( dhttemp == 0){ tempv = ""; // added Feb 15 //// float temptemp; //// String temperature; String temperature = ""; sensors.requestTemperatures(); // Send the command to get temperatures // temptemp = sensors.getTempCByIndex(0); // removed Feb 15 // print the device information printData(insideThermometer); temptemp = tempv.toFloat(); PSerial("temptemp before anything = ");PlnSerial (String (temptemp)); // if ((abs(temptemp - oldtemptest) > 20 * tempdiff && oldtemptest < 200 && wrongtempcount < wtcmax) || temptemp == 185 ){ // if ((wrongtempcount < wtcmax) && oldtemptest < 200 )|| temptemp == 185 || temptemp == 0 ){ if ( temptemp == 0 || temptemp == 185 ) { temptemp = -127 ; wrongtempcount += 1 ; PSerial("wrongtempcount = ");PlnSerial (String (wrongtempcount)); } else { wrongtempcount = 0 ; temptemp = temptemp + adjtemp ; PSerial ("temptemp = "); PlnSerial(String(temptemp)); if (precision == 1) { temptemp = round(temptemp * 10); temptemp = temptemp/10 ; //PSerial("temptemp after making it 1 decimal = ");PlnSerial (String (temptemp)); temptemp = (int) round(temptemp) ; // PSerial("temptemp after making it integer and rounded = ");PlnSerial (String (temptemp)); } else { temptemp = (round(temptemp * precision) ) ; // / precision ; temptemp = (temptemp / precision) ; // / precision ; } // PSerial("temptemp: "); // PlnSerial(String(temptemp)); PSerial("temptemp after rounding: "); PlnSerial(String(temptemp)); } if ( numtemp > 1 ) { printData(outsideThermometer); temptemp2 = tempv.toFloat(); // temperature = String(temptemp); // temperature = String(temptemp + adjtemp); // Serial.print("Temperature in C: "); // Serial.println(temperature); ///////////////////////////////////////////////////////////// a faire come temp1 // if (abs(temptemp2 - oldtemptest2) > 4 * tempdiff ) { // if ((abs(temptemp2 - oldtemptest2) > 20 * tempdiff && oldtemptest2 < 200 && wrongtempcount < wtcmax) || temptemp2 == 185 ){ if ( temptemp2 == 0 || temptemp2 == 185 ) { temptemp2 = -127 ; wrongtempcount += 1 ; PSerial("wrongtempcount = ");PlnSerial (String (wrongtempcount)); } else { wrongtempcount = 0 ; temptemp2 = temptemp2 + adjtemp2 ; PSerial ("tempeading = "); PlnSerial(String(tempreading)); // temptemp = temptemp + adjtemp ; // if ( tempreading == "F" ) { // temptemp = (temptemp * 2) + 30 ; // //F = (C x 2) + 30 // } if (precision == 1) { temptemp2 = round(temptemp2 * 10); temptemp2 = temptemp2/10 ; PSerial("temptemp2 after making it 1 decimal = ");PlnSerial (String (temptemp2)); temptemp2 = (int) round(temptemp2) ; PSerial("temptemp2 after making it integer and rounded = ");PlnSerial (String (temptemp2)); } else { temptemp2 = (round(temptemp2 * precision) ) ; // / precision ; temptemp2 = (temptemp2 / precision) ; // / precision ; } PSerial("temptemp2: "); PlnSerial(String(temptemp2)); /* PSerial("temptemp after rounding: "); PlnSerial(String(temptemp)); Serial.print("precision: "); PlnSerial(String(precision)); */ PSerial("temptemp2 after rounding: "); PlnSerial(String(temptemp2)); } } } // added may 4th-2016 /* if (precision == 1) { temptemp = round(temptemp * 10); temptemp = temptemp/10 ; PSerial("temptemp after making it 1 decimal = ");PlnSerial (String (temptemp)); temptemp = (int) round(temptemp) ; PSerial("temptemp after making it integer and rounded = ");PlnSerial (String (temptemp)); temptemp2 = round(temptemp2 * 10); temptemp2 = temptemp2/10 ; PSerial("temptemp2 after making it 1 decimal = ");PlnSerial (String (temptemp2)); temptemp2 = (int) round(temptemp2) ; PSerial("temptemp2 after making it integer and rounded = ");PlnSerial (String (temptemp2)); } else { temptemp = (round(temptemp * precision) ) ; // / precision ; temptemp = (temptemp / precision) ; // / precision ; temptemp2 = (round(temptemp2 * precision) ) ; // / precision ; temptemp2 = (temptemp2 / precision) ; // / precision ; } */ } // function to print a device address void printAddress(DeviceAddress deviceAddress) { for (uint8_t i = 0; i < 8; i++) { // zero pad the address if necessary if (deviceAddress[i] < 16) PSerial("0"); PlnSerial(String(deviceAddress[i], HEX)); } } // function to print the temperature for a device void printTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); PSerial("Temp C: "); PSerial(String(tempC)); // Serial.print(" Temp F: "); // Serial.print(DallasTemperature::toFahrenheit(tempC)); PlnSerial(" "); tempv=String(tempC); } // function to print a device's resolution void printResolution(DeviceAddress deviceAddress) { PSerial("Resolution: "); PSerial(String(sensors.getResolution(deviceAddress))); PlnSerial(" "); } // Print the temperature, or the type or fault for Max31855 void printTemp31855(double temperature) { float oldtemp31855 = valuedev1 ; switch ((int) temperature) { case FAULT_OPEN: PSerial("FAULT_OPEN"); tempmax31855 = oldtemp31855; break; case FAULT_SHORT_GND: PSerial("FAULT_SHORT_GND"); tempmax31855 = oldtemp31855; break; case FAULT_SHORT_VCC: PSerial("FAULT_SHORT_VCC"); tempmax31855 = oldtemp31855; break; case NO_MAX31855: PSerial("NO_MAX31855"); break; default: tempmax31855 = temperature ; PSerial("Max31855 = "); PlnSerial(String(tempmax31855)); break; } PSerial(" "); } // main function to print information about a device void printData(DeviceAddress deviceAddress) { PSerial("Device Address: "); printAddress(deviceAddress); PSerial(" "); printTemperature(deviceAddress); PlnSerial(" "); } void getvolt(){ /* float testvolt = 0 ; int i = 0 ; for ( i ; i < 10; ++i){ // testvolt = testvolt + analogRead(A0) ; testvolt = testvolt + (analogRead(A0) / adjvolt) ; // PSerial( i ); PSerial("testvolt = ");PlnSerial (String (testvolt)); PSerial( i ); PSerial("analog = ");PlnSerial (String ((analogRead(A0) / adjvolt))); } voltvolt = testvolt / i ; */ // PSerial("analog = ");PlnSerial (String (analogRead(A0)); voltvolt = (analogRead(A0) / adjvolt) ; voltvolt = (round(voltvolt * vprecision) ) ; // / precision ; voltvolt = (voltvolt / vprecision) ; // / precision ; //// voltvolt = analogRead(A0); // PSerial("volts = "); // PlnSerial(String(voltvolt)); // PSerial("output: "); // PlnSerial(String(voltvolt)); // PlnSerial(String(analogRead(A0)); // voltvolt = voltvolt / adjvolt ; // voltvolt = (round(voltvolt * vprecision) ) ; // / precision ; // voltvolt = (voltvolt / vprecision) ; // / precision ; /* PSerial("voltvolt after rounding: "); PlnSerial(String(voltvolt)); PSerial("vprecision: "); PlnSerial(String(vprecision)); PSerial("voltvolt after rounding: "); PlnSerial(String(voltvolt)); */ } 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-switch-pump"; devicetodo = "t,v,s,p, , , , , "; } else if (whatis == "d") { devicetype = "temp-volt-pump"; devicetodo = "t,v, ,p, , , , , "; } 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 == "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; // dht200 sensor } else if ( whatis == "Z") { devicetype = "temp"; devicetodo = "t, , , , , , , , "; dhttemp = 2; // 500 to 800 degrees heat } 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); 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 ; PSerial (""); PSerial ("Pump1 = "); PlnSerial(String(Pcurrent)); PSerial ("Pump2 = "); PlnSerial(String(Pcurrent2)); PSerial ("Pump3 = "); PlnSerial(String(Pcurrent3)); if (devicetodo.substring(4,5) == " " ) { pinMode(BUTTON, INPUT); digitalWrite(BUTTON, LOW); // grab the current state of the button current = digitalRead(BUTTON); currentold = 0 ; PSerial ("Pump4 = "); 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 ("Pump5 = "); 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 pins(int pinp) { String pin = pinnum.substring(pinp,pinp+1) ; int pinpr = 0 ; if ( pin == "C" ) { pinpr = 12 ; } else if ( pin == "E" ) { pinpr = 13 ; } else if ( pin == "F" ) { pinpr = 14 ; } else if ( pin == "G" ) { pinpr = 15 ; } else if ( pin == "H" ) { pinpr = 16 ; } else { pinpr = pin.toInt() ; } return ; } void ispoweron() { PSerial("powercut = "); PlnSerial(String(powercut)); PSerial("sentapi = "); PlnSerial(String(sentapi)); if ( powercut == 1) { pcurrent = 0 ; // datetosave = dateTime ; senddatatoapi(); PlnSerial("Sending api"); if ( sentapi == 1) { powercut = 0 ; datetosave = " " ; PSerial("datetosave = "); PlnSerial(datetosave); String firsteeprom = "9"; EEPROM.write(0, firsteeprom[0] ); EEPROM.commit(); PlnSerial("clearing eeprom"); // for (int i = 140; i < 141; ++i) for (int i = datetosave_from; i < datetosave_to; ++i) { EEPROM.write(i, clearchar[0]) ; } /* PlnSerial("writing eeprom datetosave:"); // for (int i = 140; i < 141; ++i) for (int i = datetosave_from; i < datetosave_to; ++i) { EEPROM.write(i, datetosave[i-datetosave_from]); PSerial("Wrote: "); PlnSerial(datetosave[i-datetosave_from]); } */ EEPROM.commit(); // s += "
Saved
"; // resolution = strreqanswer.toInt() ; // y = freq ; // sensors.setResolution(0,resolution); PSerial("datetosave = "); PlnSerial(datetosave); } } else { pcurrent = digitalRead(POWER); // PSerial (""); // PSerial ("PUMP1 = "); PlnSerial(String(current)) ( } if (pcurrent == 1) { // IO0 is 1 /* PSerial("connecting to "); PlnSerial(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 13; if (!client.connect(host, httpPort)) { PlnSerial("connection failed"); return; } PlnSerial(">Sending Header<}"); // This will send the request to the server /////////////////////////////////////////////////// missing line here delay(100); // Read all the lines of the reply from server and print them to Serial // expected line is like : Date: Thu, 01 Jan 2015 22:00:14 GMT // char buffer[12]; // String dateTime = ""; PlnSerial("> Listening...<"); while(client.available()) { String line = client.readStringUntil('\r'); if (line.indexOf("Date") != -1) { PSerial("=====>"); } else { // PSerial(line); // date starts at pos 7 TimeDate = line.substring(7); PlnSerial(TimeDate); // time starts at pos 14 TimeDate = line.substring(7, 15); datetosave = TimeDate ; TimeDate.toCharArray(buffer, 10); PlnSerial("UTC Date/Time:"); PlnSerial(buffer); TimeDate = line.substring(16, 24); TimeDate.toCharArray(buffer, 10); PlnSerial(buffer); // $date = date('Y-m-d\TH:i:s\-\0\0\:\0\0'); PSerial("datetosave1 = "); PlnSerial(datetosave); // datetosave += myChar + TimeDate + myChar + "-" + myChar + "0" + myChar + "0" + myChar + ":" + myChar + "0" + myChar + "0" ; datetosave += "T" + TimeDate + "-00:00" ; PSerial("datetosave = "); PlnSerial(datetosave); } } PlnSerial(""); PlnSerial("closing connection"); client.println("Connection: close"); client.println(); PlnSerial("Close connection}"); PlnSerial(">WiFi Connected<}"); */ datetosave = dateTime ; if (pcurrentold == 0 ){ datetosave = dateTime ; senddatatoapi(); PlnSerial("Sending api"); } } else if (pcurrentold == 1){ // save the last time read in eeprom // else if ( req.startsWith("/resolution=") ) { // s += "
Saving the resolution value
"; // s += "