#include #include #include #define DEBUG true #define STARTUP true #define RX 10 //pin layout #define TX 11 // #define measureO A0// #define measureU A1// #define relay 8 // #define button 4 // #define dimmer 9 // SoftwareSerial Esp8266(RX, TX); String ssid = "FRITZ!Box 6591 Cable VW"; String pwd = "15974136204554170633"; int connectionId; bool skipWifiSetup = false; bool on = true;//is pump regulation turned on LiquidCrystal_I2C lcd(0x27, 16, 2); int displayPage; int disTimeout = 10000; //display timeout time in milliseconds unsigned long disTimer=0; //this integer is used to store display timer data; const int tempSize = 44; double temptable[ tempSize ] = { 140, 130, 120, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0, -2, -4, -6, -8, -10, -12, -14, -16, -18, -20, }; const int resSize = 44; double restable[ resSize ] = { 118, 150, 195, 255, 294, 339, 393, 458, 535, 628, 740, 876, 1042, 1244, 1493, 1801, 2184, 2663, 3266, 4029, 4787, 5225, 5710, 6246, 6840, 7499, 8231, 9045, 9950, 10959, 12085, 13342, 14479, 16325, 18094, 20079, 22313, 24827, 27663, 30866, 34489, 38592, 43247, 48536 }; int V = 5; //supply voltage from arduino double R = 1000; //static resistor double tempO; //temperature roof sensor double tempU; //temperature water tank; double tempDiff; bool pump; //pump on/off bool batterySaverMode; int sampleRateESM = 9000000;//sample rate while energy saving int defaultSampleRate = 1000; int difOn = 20; //temp diff for relay activation int difOff = 5; //temp diff for relay off int sampleRate = 1000; int maxTempO = 130; //max temp(emergency stop) int maxTempU = 90; //max boiler temp unsigned long compTimer=0; int errorLog[10]; //this list is used to store the last 10 errors double errorLogTime[10]; //this list is used to store the time of the last 10 errors unsigned long timerStart; int timeOn = 0; void setup() { Serial.begin(115200); Esp8266.begin(9600); pinMode(relay, OUTPUT); pinMode(dimmer, OUTPUT); pinMode(button, INPUT_PULLUP); for(int i =0;i<1;i++){//initialize WIFI connection and loading bar sendData("AT\r\n", 1000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+RST\r\n", 2000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+CWMODE=1\r\n", 2000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+CWJAP=\"" + ssid + "\",\"" + pwd + "\"\r\n", 10000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+CIFSR\r\n", 2000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+CIPMUX=1\r\n", 2000, DEBUG, STARTUP); if(skipWifiSetup) {break;} sendData("AT+CIPSERVER=1,80\r\n", 2000, DEBUG, STARTUP); if(skipWifiSetup) {break;} } } String sendData(String command, const int timeout, boolean debug, boolean startup) { String response = ""; Esp8266.print(command); unsigned long time = millis(); while( (time+timeout) > millis()) { while(Esp8266.available()) { char c = Esp8266.read(); // read the next character. response+=c; } } if(startup) { if(response.indexOf("OK")==-1){ skipWifiSetup = true; } } if(debug) { Serial.print(response); //displays the esp response messages in arduino Serial monitor } return response; } void espsend(String d) { String cipSend = " AT+CIPSEND="; cipSend += connectionId; cipSend += ","; cipSend +=d.length(); cipSend +="\r\n"; sendData(cipSend, 1000, DEBUG, false); sendData(d, 1000, DEBUG, false); } String createWebPage(){ String page = "

Solar-Pumpe

Temperatur oben: "; page+=tempO; page+="℃

Temperatur unten: "; page+=tempU; page+="℃

Pumpe: "; if(pump){ page+="an
"; } else { page+="aus

"; } return page; } void loop() { if (!skipWifiSetup){//web page response if(Esp8266.available()) { /////////////////////Recieving from web browser to toggle led if(Esp8266.find("+IPD,")) { delay(300); connectionId = Esp8266.read()-48; String webpage = createWebPage(); espsend(webpage); String closeCommand = "AT+CIPCLOSE="; ////////////////close the socket connection////esp command closeCommand+=connectionId; // append connection id closeCommand+="\r\n"; sendData(closeCommand,3000,DEBUG,false); } } } }