amc2022:groupz:start
Differences
This shows you the differences between two versions of the page.
| amc2022:groupz:start [2022/09/11 23:17] – [Table] ziad001 | amc2022:groupz:start [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 210: | Line 210: | ||
| <code c++> | <code c++> | ||
| - | / | ||
| * AMC Group Z | * AMC Group Z | ||
| * Monitoring Drought Effects | * Monitoring Drought Effects | ||
| - | */ | + | |
| - | #include < | + | #include < |
| - | #include < | + | #include < |
| - | #include < | + | #include < |
| - | #include < | + | #include < |
| - | #include < | + | #include < |
| - | DFRobot_DHT11 DHT; | + | DFRobot_DHT11 DHT; //6 |
| - | #define AOUT_PIN 36 | + | #define AOUT_PIN 36 //7 |
| - | #define DHT11_PIN 14 | + | #define DHT11_PIN 14 //8 |
| - | #define EEPROM_BYTES 2 | + | #define EEPROM_BYTES 2 //9 |
| - | //#define RestartPin 27 | + | //#define RestartPin 27 //10 |
| - | #define uS_TO_S_FACTOR 1000000 | + | #define uS_TO_S_FACTOR 1000000 |
| - | #define TIME_TO_SLEEP | + | #define TIME_TO_SLEEP |
| - | RTC_DATA_ATTR int bootCount = 0; | + | RTC_DATA_ATTR int bootCount = 0; //12 |
| - | Adafruit_MLX90614 mlx = Adafruit_MLX90614(); | + | Adafruit_MLX90614 mlx = Adafruit_MLX90614(); |
| - | int dry = 2677; | + | int dry = 2677; //14 |
| - | int wet = 977; | + | int wet = 977; //15 |
| // WiFi | // WiFi | ||
| - | const char *ssid = " | + | const char *ssid = " |
| - | const char *password = " | + | const char *password = " |
| // MQTT Broker | // MQTT Broker | ||
| - | const char *mqtt_broker = " | + | const char *mqtt_broker = " |
| - | const char *topic_1 = " | + | const char *topic_1 = " |
| - | const char *topic_2 = " | + | const char *topic_2 = " |
| - | const char *topic_3 = " | + | const char *topic_3 = " |
| - | const char *topic_4 = " | + | const char *topic_4 = " |
| - | const char *topic_5 = " | + | const char *topic_5 = " |
| - | //const char *topic_down = " | + | |
| - | const int mqtt_port = 1883; | + | |
| - | WiFiClient espClient; | + | const int mqtt_port = 1883; //24 |
| - | PubSubClient client(espClient); | + | |
| - | void callback(char *topic, byte *payload, unsigned int length) { | + | WiFiClient espClient; //25 |
| - | | + | PubSubClient client(espClient); |
| - | | + | |
| + | void callback(char *topic, byte *payload, unsigned int length) { //27 | ||
| + | | ||
| + | | ||
| | | ||
| - | for (int i = 0; i < length; i++) { | + | for (int i = 0; i < length; i++) { |
| | | ||
| } | } | ||
| Line 265: | Line 264: | ||
| } | } | ||
| - | void print_wakeup_reason(){ | + | void print_wakeup_reason(){ |
| esp_sleep_wakeup_cause_t wakeup_reason; | esp_sleep_wakeup_cause_t wakeup_reason; | ||
| Line 276: | Line 275: | ||
| } | } | ||
| | | ||
| - | void setup() { | + | void setup() { //29 |
| EEPROM.begin(EEPROM_BYTES); | EEPROM.begin(EEPROM_BYTES); | ||
| - | Serial.begin(115200); | + | Serial.begin(115200); |
| - | while (!Serial); | + | while (!Serial); |
| - | if (!mlx.begin()) { | + | if (!mlx.begin()) { //32 |
| Serial.println(" | Serial.println(" | ||
| while (1); | while (1); | ||
| }; | }; | ||
| - | delay(1000); | + | delay(1000); |
| | | ||
| - | ++bootCount; | + | ++bootCount; |
| Serial.println(" | Serial.println(" | ||
| - | print_wakeup_reason(); | + | print_wakeup_reason(); |
| - | esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); | + | esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); |
| Serial.println(" | Serial.println(" | ||
| " Seconds" | " Seconds" | ||
| - | Serial.println(" | + | Serial.println(" |
| delay(1000); | delay(1000); | ||
| - | WiFi.begin(ssid, | + | WiFi.begin(ssid, |
| - | while (WiFi.status() != WL_CONNECTED) { | + | while (WiFi.status() != WL_CONNECTED) { //39 |
| - | delay(1000); | + | delay(1000); |
| - | Serial.println(" | + | Serial.println(" |
| - | Serial.println(" | + | Serial.println(" |
| | | ||
| // | // | ||
| - | client.setServer(mqtt_broker, | + | client.setServer(mqtt_broker, |
| client.setCallback(callback); | client.setCallback(callback); | ||
| | | ||
| - | while (!client.connected()) { | + | while (!client.connected()) { //42 |
| String client_id = " | String client_id = " | ||
| client_id += String(WiFi.macAddress()); | client_id += String(WiFi.macAddress()); | ||
| Serial.printf(" | Serial.printf(" | ||
| | | ||
| - | if (client.connect(client_id.c_str())) { | + | if (client.connect(client_id.c_str())) { //43 |
| Serial.println(" | Serial.println(" | ||
| } | } | ||
| - | else { | + | else { //44 |
| Serial.print(" | Serial.print(" | ||
| Serial.print(client.state()); | Serial.print(client.state()); | ||
| Line 325: | Line 324: | ||
| } | } | ||
| - | void loop() { | + | void loop() { //45 |
| - | char soil_moisture_value[3]; | + | char soil_moisture_value[3]; |
| char air_temperature[3]; | char air_temperature[3]; | ||
| char air_humidity[3]; | char air_humidity[3]; | ||
| Line 333: | Line 332: | ||
| char ground_temperature[3]; | char ground_temperature[3]; | ||
| | | ||
| - | int value = analogRead(AOUT_PIN); | + | int value = analogRead(AOUT_PIN); |
| - | int percHumidity = map(value, dry, wet, 0, 100); | + | int percHumidity = map(value, dry, wet, 0, 100); //48 |
| delay(2000); | delay(2000); | ||
| - | if ((percHumidity > -5) && (percHumidity < 105)) { | + | if ((percHumidity > -5) && (percHumidity < 105)) { //49 |
| - | | + | |
| | | ||
| - | dtostrf(percHumidity, | + | dtostrf(percHumidity, |
| - | client.publish(topic_1, | + | client.publish(topic_1, |
| } | } | ||
| delay(2000); | delay(2000); | ||
| Line 383: | Line 382: | ||
| delay(1000); | delay(1000); | ||
| | | ||
| - | Serial.flush(); | + | Serial.flush(); |
| esp_deep_sleep_start(); | esp_deep_sleep_start(); | ||
| Serial.println(" | Serial.println(" | ||
| Line 594: | Line 593: | ||
| Powering ESP32 directly with a 9v battery is not recommended [29]. Therefore we need to use a voltage regulator to supply the ESP32 with 5 volts only. Using the Pololu voltage regulator and a voltmeter, we regulated the voltage to 5.39 Volts, as shown in the picture below, so the voltage that was reaching the ESP32 was 5.39 Volts. | Powering ESP32 directly with a 9v battery is not recommended [29]. Therefore we need to use a voltage regulator to supply the ESP32 with 5 volts only. Using the Pololu voltage regulator and a voltmeter, we regulated the voltage to 5.39 Volts, as shown in the picture below, so the voltage that was reaching the ESP32 was 5.39 Volts. | ||
| - | ^{{ : | + | ^ {{ : |
| - | |//**Figure 14**// Voltage values reaching the ESP32 when connected with a voltage regulator| | + | | //**Figure 14**// Voltage values reaching the ESP32 when connected with a voltage regulator, '' |
amc2022/groupz/start.1662931046.txt.gz · Last modified: 2023/01/05 14:38 (external edit)