#include <ESP8266WiFi.h>
#include <AdafruitIO.h>
#include <Adafruit_MQTT.h>
#include "Adafruit_MQTT_Client.h"
#include <ArduinoHttpClient.h>
#include "DHTesp.h"
#include <WiFiUdp.h>
#include <NTPClient.h>
#define ON_S1 D1
#define ON_S2 D2
#define FULSLP 21600000
// set up the 'Sensor' feed
AdafruitIO_Feed *S1 = io.feed("S1");
AdafruitIO_Feed *S2 = io.feed("S2");
AdafruitIO_Feed *S3 = io.feed("S3");
//set up the 'Output' feed
AdafruitIO_Feed *PUMP = io.feed("PUMP");
AdafruitIO_Feed *LIGHT = io.feed("LIGHT");
AdafruitIO_Feed *SOLARMODE = io.feed("SOLARMODE");
AdafruitIO_Feed *NIGHTMODE = io.feed("NIGHTMODE");
// set up the 'DHT Sensor'
DHTesp dht;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 28800);
int Moist, MoistS, Temp, TempS, Humid, HumidS, PU, LI, SO, NM, SM;
unsigned long lastUpdate, DepSlep;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
pinMode(ON_S1, OUTPUT);
pinMode(ON_S2, OUTPUT);
// start the serial connection
Serial.begin(115200);
//DHT11 Sensor Setup to GIO 14(D5)
dht.setup(14, DHTesp::DHT11);
Serial.println();
// connect to io.adafruit.com
Serial.println("Connecting to Adafruit IO");
io.connect();
PUMP->onMessage(handlePump);
LIGHT->onMessage(handleLight);
SOLARMODE->onMessage(handleSolarmode);
NIGHTMODE->onMessage(handleNightmode);
// wait for a connection
while (io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
timeClient.begin();
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
if (millis() > (lastUpdate + 15000)) {
Moisture();
S1->save(Moist);
TemperatureHumidity();
S2->save(Temp);
S3->save(Humid);
timeClient.update();
Serial.println(timeClient.getFormattedTime());
}
if (millis() > (lastUpdate + 1000)) {
//Time Updates
timeClient.update();
//Pump control
if (PU == 1)
{
digitalWrite(ON_S1, HIGH);
}
else if (PU == 0)
{
digitalWrite(ON_S1, LOW);
}
else if (Moist <= 70) {
digitalWrite(ON_S1, HIGH);
while (Moist == 100);
digitalWrite(ON_S1, LOW);
}
//Light control
if (LI == 1)
{
digitalWrite(ON_S2, HIGH);
}
else if (LI == 0)
{
digitalWrite(ON_S1, LOW);
}
if (timeClient.getHours() <= 0 && timeClient.getHours() >= 6 && NM == 1) {
DepSlep = FULSLP - (timeClient.getHours() * 60 * 60 * 1000) - (timeClient.getMinutes() * 60 * 1000) - (timeClient.getSeconds() * 1000);
ESP.deepSleep(DepSlep);
}
lastUpdate = millis();
}
void handlePump(AdafruitIO_Data * data) {
int PU = data->toInt();
}
void handleLight(AdafruitIO_Data * data) {
int LI = data->toInt();
}
void handleSolarmode(AdafruitIO_Data * data) {
int SM = data->toInt();
}
void handleNightmode(AdafruitIO_Data * data) {
int NM = data->toInt();
}
void Moisture() {
//Soil Moisture Sensor
Moist = analogRead(A0) - 319;
Moist = 0.142 * Moist;
Moist = 100 - Moist;
if (Moist > 100) {
Moist = 100;
}
else if (Moist < 0) {
Moist = 0;
}
}
void TemperatureHumidity() {
//Sensor DHT11 Temperature and Humidity
Temp = dht.getTemperature();
Humid = dht.getHumidity();
}
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
D:\w0rK\FYP\FYP_Modification3\FYP_Modification3.ino: In function 'void setup()':
FYP_Modification3:70:19: error: 'handlePump' was not declared in this scope
PUMP->onMessage(handlePump);
^
FYP_Modification3:71:20: error: 'handleLight' was not declared in this scope
LIGHT->onMessage(handleLight);
^
FYP_Modification3:72:24: error: 'handleSolarmode' was not declared in this scope
SOLARMODE->onMessage(handleSolarmode);
^
FYP_Modification3:73:24: error: 'handleNightmode' was not declared in this scope
NIGHTMODE->onMessage(handleNightmode);
^
D:\w0rK\FYP\FYP_Modification3\FYP_Modification3.ino: In function 'void loop()':
FYP_Modification3:97:14: error: 'Moisture' was not declared in this scope
Moisture();
^
FYP_Modification3:100:25: error: 'TemperatureHumidity' was not declared in this scope
TemperatureHumidity();
^
FYP_Modification3:144:41: error: a function-definition is not allowed here before '{' token
void handlePump(AdafruitIO_Data * data) {
^
FYP_Modification3:148:42: error: a function-definition is not allowed here before '{' token
void handleLight(AdafruitIO_Data * data) {
^
FYP_Modification3:152:46: error: a function-definition is not allowed here before '{' token
void handleSolarmode(AdafruitIO_Data * data) {
^
FYP_Modification3:156:46: error: a function-definition is not allowed here before '{' token
void handleNightmode(AdafruitIO_Data * data) {
^
FYP_Modification3:160:17: error: a function-definition is not allowed here before '{' token
void Moisture() {
^
FYP_Modification3:177:3: error: expected '}' at end of input
}
^
exit status 1
'handlePump' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.