#include int ADC= A0; //analogue channel const char* ssid = "YourWifi"; //WIFI NAME const char* password = "YourPassword"; //WIFI PASSWORD const char* host = "emoncms.org"; const int DHWRelay =4; int DHWRelayState =0; void setup() { pinMode (DHWRelay, INPUT); Serial.begin(9600);//Baud rate delay(10); Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } int value = 0; void loop() { DHWRelayState = digitalRead(DHWRelay); delay(2000); ++value; //set up input params int value = LOW; float ADCVal=0.0; float voltageVal=0.0; float lpmFlowVal=0.0; for(unsigned int i=0;i<10;i++){ ADCVal=ADCVal+analogRead(ADC); //Read analog ADC value delay(5); //ADC stable } ADCVal=(float)ADCVal/10.0; //Find average of 10 values voltageVal=(float)(ADCVal/1024.0)*3; //Convert to voltage if(voltageVal<0.5) { lpmFlowVal=0.00; //does not read below 0.5V }else{ lpmFlowVal=(float) voltageVal*47.66666 - 16.83333; //from Sika VVX25 datasheet } Serial.print("connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 80; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } // create a URI for the request String urlFlow = "/input/post?node=home&fulljson={\"ASHPFlowV\":" + String(lpmFlowVal) + "}&apikey=YourAPIKey"; // this will have to be edited for your arrangement String urlDHWRelay = "/input/post?node=home&fulljson={\"DHWRelayState\":" + String(DHWRelayState) + "}&apikey=YourAPIKey"; // this will have to be edited for your arrangement Serial.print("Requesting URL: "); Serial.println(urlFlow); // This will send the request to the server client.print(String("GET ") + urlFlow + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return; } } // Read all the lines of the reply from server and print them to Serial while(client.available()){ String line = client.readStringUntil('\r'); Serial.print(line); } if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } Serial.print("Requesting URL: "); Serial.println(urlDHWRelay); // This will send the request to the server client.print(String("GET ") + urlDHWRelay + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); unsigned long timeoutDHW = millis(); while (client.available() == 0) { if (millis() - timeoutDHW > 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return; } } // Read all the lines of the reply from server and print them to Serial while(client.available()){ String line = client.readStringUntil('\r'); Serial.print(line); } Serial.println(); Serial.println("closing connection"); }