· 5 years ago · Feb 17, 2021, 06:44 AM
1#include <ESP8266WiFi.h>
2#include <DNSServer.h>
3#include <ESP8266WebServer.h>
4#include <WiFiManager.h>
5#include <DHT.h>
6#include "ThingSpeak.h"
7String apiKey = "QDYQ1KXG4SN2EWWV"; // API key from ThingSpeak
8
9//const char *ssid = "__RuhulAmin__"; // replace with your wifi ssid and wpa2 key
10//const char *pass = "write12345";
11const char* server = "api.thingspeak.com";
12
13unsigned long channel =1205343;
14unsigned int pump = 3; //indicating field 3 in thingspeak
15WiFiClient client;
16
17
18void setup()
19{
20
21 Serial.begin(115200);
22 WiFiManager wifiManager;
23 Serial.println("Conecting.....");
24 wifiManager.autoConnect("HIGH VOLTAGES","12345");
25 Serial.println("connected");
26 delay(100);
27
28 // WiFi.begin(ssid, pass);
29
30 while (WiFi.status() != WL_CONNECTED)
31 {
32 delay(500);
33 Serial.print(".");
34 }
35 Serial.println("");
36 Serial.println("WiFi connected");
37
38}
39
40
41
42void loop()
43{
44
45 int pump_status = ThingSpeak.readFloatField(channel, pump); //reading status from thingspeak server
46
47
48 if(pump_status == 1){
49 digitalWrite(pump, 1);
50 Serial.println("pump is On..!");
51 }
52 else if(pump_status == 0){
53 digitalWrite(pump, 0);
54 Serial.println("Pump is Off..!");
55 }
56
57
58
59
60
61}