Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include "FS.h" // pour le SPIFFS
- #include <ArduinoJson.h>
- #include <dampermotor.h>
- #include <Wire.h>
- // #include "Adafruit_MCP23017.h"
- // Adafruit_MCP23017 mcp;
- const char* CONFIG_HTML = "/html/config.html";
- const char* UPDATE_HTML = "/html/Update.html";
- const char* DISPLAY_DATA_HTML = "/html/display_data.html";
- const char* ssid = "ASUS";
- const char* password = "Famillejacobi";
- const uint16_t HTTPPort = 80;
- WiFiServer serveurWeb(HTTPPort); // crée un serveur sur le port HTTP standard
- const byte maxHTTPLine = 100;
- char httpLine[maxHTTPLine + 1]; //+1 pour avoir la place du '\0'
- const byte maxURL = 50;
- char urlRequest[maxURL + 1]; //+1 pour avoir la place du '\0'
- #define SoilSensor A0
- #define SoilS1EnablePin1 D0
- #define SoilS1EnablePin2 D1
- #define SoilS1EnablePin3 D2
- #define SoilS1EnablePin4 D3
- #define tap_solenoid1 0
- #define tap_solenoid2 1
- #define tap_solenoid3 2
- #define tap_solenoid4 3
- #define tap_solenoid_timeout 1500 // delay for 3 sec.
- #define PumpPin 2
- //Configure the soil moisture
- int MintSoilMoisture = 250;//Menth
- const int ParsleySoilMoisture = 230;//Persil
- const int BasilSoilMoisture = 260;//Basilic
- const int CorianderSoilMoisture = 300;//Coriande, Cousbara
- const int DillSoilMoisture = 2700;//Aneth, shamir
- const int SageSoilMoisture = 310;//Sauge, Marva
- const int rosemarySoilMoisture = 200;//Romarin
- int read_s1_value,read_s2_value,read_s3_value,read_s4_value; //read data from sensor
- int PlantS1,PlantS2,PlantS3,PlantS4; //User final target after converted from WebForm
- boolean electric_tap_motor1,electric_tap_motor2,electric_tap_motor3,electric_tap_motor4; //Off or On motor's electric tap
- const int onTime = 1000; // in ms
- const int offTime = 5000; // in ms
- boolean currentlyOn = false;
- unsigned long startTime;
- dampermotor tap_motor_sensor1(D4,D5,tap_solenoid_timeout); // define pin 4,5 to drive the tap_motor_sensor1
- dampermotor tap_motor_sensor2(D6,D7,tap_solenoid_timeout); // define pin 6,7 to drive the tap_motor_sensor1
- dampermotor tap_motor_sensor3(D8,D9,tap_solenoid_timeout); // define pin 8,9 to drive the tap_motor_sensor1
- //dampermotor tap_motor_sensor4(D10,11,tap_solenoid_timeout); // define pin 10,11 to drive the tap_motor_sensor1
- void printHTTPServerInfo()
- {
- Serial.print(F("Site web http: "));
- Serial.print(WiFi.localIP());
- if (HTTPPort != 80)
- {
- Serial.print(F(":"));
- Serial.print(HTTPPort);
- }
- Serial.println();
- }
- #include "config_json_file.h" // include the function for saving and loading config.json
- #include "spiffs_page_display.h" // include the function to display web page
- #include "waterControl.h" // include the irrigation system
- /**
- * Read Datas from all Sensors
- */
- int read_Sensors_Values(int EnableSoilPin)
- {
- int ReadSensor;
- digitalWrite(EnableSoilPin,HIGH);
- for(int SensorReading = 0;SensorReading < 5;SensorReading++)
- {
- ReadSensor = analogRead(SoilSensor);
- }
- digitalWrite(EnableSoilPin,LOW);
- return ReadSensor;
- }
- /**
- * Assign the correct Soil Target for the Plant Sensor connected after user choice from the WebForm
- */
- int SoilSensorWebUser(int WebSoilSensor)
- {
- switch(WebSoilSensor)
- {
- case 0:
- return(0);
- break;
- case 1:
- return(MintSoilMoisture);
- break;
- case 2:
- return(ParsleySoilMoisture);
- break;
- case 3:
- return(BasilSoilMoisture);
- break;
- case 4:
- return(CorianderSoilMoisture);
- break;
- case 5:
- return(DillSoilMoisture);
- break;
- case 6:
- return(SageSoilMoisture);
- break;
- case 7:
- return(rosemarySoilMoisture);
- break;
- }
- }
- void setup()
- {
- Serial.begin(115200);
- /*mcp.begin(); // use default address 0
- mcp.pinMode(0, INPUT);
- mcp.pinMode(tap_solenoid1, OUTPUT);
- mcp.pinMode(tap_solenoid2, OUTPUT);
- mcp.pinMode(tap_solenoid3, OUTPUT);
- mcp.pinMode(tap_solenoid4, OUTPUT);*/
- Serial.println("\n\nMounting FS...\n");
- // on démarre le SPIFSS
- if (!SPIFFS.begin())
- {
- Serial.println("erreur SPIFFS");
- while (true); // on ne va pas plus loin
- }
- loadConfig();
- /*if (!loadConfig())
- {Serial.println("Failed to load config");}
- else
- {Serial.println("Config loaded");}*/
- WiFi.begin(ssid, password);
- Serial.println();
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.write('.');
- }
- Serial.println();
- // on démarre le serveur
- serveurWeb.begin();
- printHTTPServerInfo();
- }
- void loop()
- {
- testRequeteWeb();
- // --- read sensors value Every 5sec for 1sec --- //
- if (currentlyOn && millis()>startTime+onTime) // Switch resistor off
- {
- currentlyOn = false;
- startTime=millis(); // Reset timer
- }
- if (!currentlyOn && millis()>startTime+offTime) // Switch resistor on
- {
- read_s1_value = read_Sensors_Values(SoilS1EnablePin1);
- read_s2_value = read_Sensors_Values(SoilS1EnablePin2);
- read_s3_value = read_Sensors_Values(SoilS1EnablePin3);
- read_s4_value = read_Sensors_Values(SoilS1EnablePin4);
- currentlyOn = true;
- startTime=millis(); // Reset timer
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement