amc:ss2023:group-c:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
amc:ss2023:group-c:start [2023/07/24 15:02] – fatima.mendoza | amc:ss2023:group-c:start [2023/07/24 23:21] (current) – [4.1. Improvements] pablo-antonio.castillo-castillo | ||
---|---|---|---|
Line 123: | Line 123: | ||
=== 2.3.4.Raw Code === | === 2.3.4.Raw Code === | ||
+ | <code c++> | ||
+ | /* | ||
+ | Source of information: | ||
+ | https:// | ||
+ | https:// | ||
+ | https:// | ||
+ | https:// | ||
+ | */ | ||
+ | // | ||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include < | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | // | ||
+ | int IRpin = 13; | ||
+ | int state = 0; | ||
+ | // | ||
+ | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 | ||
+ | // Initialize DHT sensor pin. | ||
+ | #define DHTPIN 14 | ||
+ | DHT dht(DHTPIN, DHTTYPE); | ||
+ | // | ||
+ | #define PWDN_GPIO_NUM 32 | ||
+ | #define RESET_GPIO_NUM -1 | ||
+ | #define XCLK_GPIO_NUM 0 | ||
+ | #define SIOD_GPIO_NUM 26 | ||
+ | #define SIOC_GPIO_NUM 27 | ||
+ | #define Y9_GPIO_NUM 35 | ||
+ | #define Y8_GPIO_NUM 34 | ||
+ | #define Y7_GPIO_NUM 39 | ||
+ | #define Y6_GPIO_NUM 36 | ||
+ | #define Y5_GPIO_NUM 21 | ||
+ | #define Y4_GPIO_NUM 19 | ||
+ | #define Y3_GPIO_NUM 18 | ||
+ | #define Y2_GPIO_NUM 5 | ||
+ | #define VSYNC_GPIO_NUM 25 | ||
+ | #define HREF_GPIO_NUM 23 | ||
+ | #define PCLK_GPIO_NUM 22 | ||
+ | // | ||
+ | // LED Flash PIN (GPIO 4) | ||
+ | #define FLASH_LED_PIN 4 | ||
+ | |||
+ | // | ||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | // | ||
+ | |||
+ | // | ||
+ | String myDeploymentID = " | ||
+ | String myMainFolderName = " | ||
+ | // | ||
+ | |||
+ | // | ||
+ | /** The smtp host name e.g. smtp.gmail.com for GMail*/ | ||
+ | #define SMTP_HOST " | ||
+ | #define SMTP_PORT 465 | ||
+ | |||
+ | /* The sign in credentials */ | ||
+ | #define AUTHOR_EMAIL " | ||
+ | #define AUTHOR_PASSWORD " | ||
+ | |||
+ | /* Recipient' | ||
+ | #define RECIPIENT_EMAIL " | ||
+ | |||
+ | /* Declare the global used SMTPSession object for SMTP transport */ | ||
+ | SMTPSession smtp; | ||
+ | |||
+ | /* Callback function to get the Email sending status */ | ||
+ | void smtpCallback(SMTP_Status status); | ||
+ | |||
+ | // | ||
+ | unsigned long previousMillis = 0; | ||
+ | const int Interval = 20000; | ||
+ | // | ||
+ | |||
+ | // Variable to set capture photo with LED Flash. | ||
+ | // Set to " | ||
+ | // Set to " | ||
+ | bool LED_Flash_ON = false; | ||
+ | |||
+ | // Initialize WiFiClientSecure. | ||
+ | WiFiClientSecure client; | ||
+ | |||
+ | // | ||
+ | // This subroutine is to test the connection to " | ||
+ | void Test_Con() { | ||
+ | const char* host = " | ||
+ | while (1) { | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | client.setInsecure(); | ||
+ | |||
+ | if (client.connect(host, | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | client.stop(); | ||
+ | break; | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | client.stop(); | ||
+ | } | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
+ | } | ||
+ | // | ||
+ | |||
+ | // | ||
+ | // Subroutine for capturing and sending photos to Google Drive. | ||
+ | void SendCapturedPhotos() { | ||
+ | const char* host = " | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | client.setInsecure(); | ||
+ | |||
+ | // | ||
+ | if (client.connect(host, | ||
+ | Serial.println(" | ||
+ | |||
+ | if (LED_Flash_ON == true) { | ||
+ | digitalWrite(FLASH_LED_PIN, | ||
+ | delay(100); | ||
+ | } else { | ||
+ | digitalWrite(FLASH_LED_PIN, | ||
+ | } | ||
+ | |||
+ | // | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | |||
+ | for (int i = 0; i <= 3; i++) { | ||
+ | camera_fb_t* fb = NULL; | ||
+ | fb = esp_camera_fb_get(); | ||
+ | if (!fb) { | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | return; | ||
+ | } | ||
+ | esp_camera_fb_return(fb); | ||
+ | delay(200); | ||
+ | } | ||
+ | |||
+ | camera_fb_t* fb = NULL; | ||
+ | fb = esp_camera_fb_get(); | ||
+ | if (!fb) { | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | if (LED_Flash_ON == true) digitalWrite(FLASH_LED_PIN, | ||
+ | |||
+ | Serial.println(" | ||
+ | // | ||
+ | |||
+ | // | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | String url = "/ | ||
+ | |||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println(); | ||
+ | |||
+ | int fbLen = fb->len; | ||
+ | char* input = (char*)fb-> | ||
+ | int chunkSize = 3 * 1000; //--> must be multiple of 3. | ||
+ | int chunkBase64Size = base64_enc_len(chunkSize); | ||
+ | char output[chunkBase64Size + 1]; | ||
+ | |||
+ | Serial.println(); | ||
+ | int chunk = 0; | ||
+ | for (int i = 0; i < fbLen; i += chunkSize) { | ||
+ | int l = base64_encode(output, | ||
+ | client.print(l, | ||
+ | client.print(" | ||
+ | client.print(output); | ||
+ | client.print(" | ||
+ | delay(100); | ||
+ | input += chunkSize; | ||
+ | Serial.print(" | ||
+ | chunk++; | ||
+ | if (chunk % 50 == 0) { | ||
+ | Serial.println(); | ||
+ | } | ||
+ | } | ||
+ | client.print(" | ||
+ | client.print(" | ||
+ | |||
+ | esp_camera_fb_return(fb); | ||
+ | // | ||
+ | |||
+ | // | ||
+ | Serial.println(" | ||
+ | long int StartTime = millis(); | ||
+ | while (!client.available()) { | ||
+ | Serial.print(" | ||
+ | delay(100); | ||
+ | if ((StartTime + 10 * 1000) < millis()) { | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | Serial.println(); | ||
+ | while (client.available()) { | ||
+ | Serial.print(char(client.read())); | ||
+ | } | ||
+ | // | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | // | ||
+ | Serial.println(" | ||
+ | client.stop(); | ||
+ | } | ||
+ | // | ||
+ | |||
+ | // | ||
+ | void smtpCallback(SMTP_Status status) { | ||
+ | /* Print the current status */ | ||
+ | Serial.println(status.info()); | ||
+ | |||
+ | /* Print the sending result */ | ||
+ | if (status.success()) { | ||
+ | Serial.println(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | Serial.println(" | ||
+ | |||
+ | for (size_t i = 0; i < smtp.sendingResult.size(); | ||
+ | /* Get the result item */ | ||
+ | SMTP_Result result = smtp.sendingResult.getItem(i); | ||
+ | |||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | |||
+ | // You need to clear sending result as the memory usage will grow up. | ||
+ | smtp.sendingResult.clear(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // | ||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | |||
+ | // Disable brownout detector. | ||
+ | WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, | ||
+ | |||
+ | // | ||
+ | dht.begin(); | ||
+ | //Getting temp. and hum. values | ||
+ | float h = dht.readHumidity(); | ||
+ | // Read temperature as Celsius (the default) | ||
+ | float t = dht.readTemperature(); | ||
+ | // Compute heat index in Celsius (isFahreheit = false) | ||
+ | float hic = dht.computeHeatIndex(t, | ||
+ | |||
+ | // | ||
+ | String hum = String(h); | ||
+ | String temp = String(t); | ||
+ | String heat_index_celsius = String(hic); | ||
+ | |||
+ | // | ||
+ | Serial.begin(115200); | ||
+ | Serial.println(); | ||
+ | delay(1000); | ||
+ | |||
+ | pinMode(FLASH_LED_PIN, | ||
+ | |||
+ | // Setting the ESP32 WiFi to station mode. | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | WiFi.mode(WIFI_STA); | ||
+ | |||
+ | // | ||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | WiFi.begin(ssid, | ||
+ | |||
+ | // The process timeout of connecting ESP32 CAM with WiFi Hotspot / WiFi Router is 20 seconds. | ||
+ | // If within 20 seconds the ESP32 CAM has not been successfully connected to WiFi, the ESP32 CAM will restart. | ||
+ | // I made this condition because on my ESP32-CAM, there are times when it seems like it can't connect to WiFi, so it needs to be restarted to be able to connect to WiFi. | ||
+ | int connecting_process_timed_out = 20; //--> 20 = 20 seconds. | ||
+ | connecting_process_timed_out = connecting_process_timed_out * 2; | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | Serial.print(" | ||
+ | delay(500); | ||
+ | |||
+ | if (connecting_process_timed_out > 0) connecting_process_timed_out--; | ||
+ | if (connecting_process_timed_out == 0) { | ||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | |||
+ | /* Set the network reconnection option */ | ||
+ | MailClient.networkReconnect(true); | ||
+ | |||
+ | /** Enable the debug via Serial port | ||
+ | * 0 for no debugging | ||
+ | * 1 for basic level debugging | ||
+ | */ | ||
+ | smtp.debug(1); | ||
+ | |||
+ | /* Set the callback function to get the sending results */ | ||
+ | smtp.callback(smtpCallback); | ||
+ | |||
+ | /* Declare the Session_Config for user defined session credentials */ | ||
+ | Session_Config config_mail; | ||
+ | |||
+ | /* Set the session config */ | ||
+ | config_mail.server.host_name = SMTP_HOST; | ||
+ | config_mail.server.port = SMTP_PORT; | ||
+ | config_mail.login.email = AUTHOR_EMAIL; | ||
+ | config_mail.login.password = AUTHOR_PASSWORD; | ||
+ | config_mail.login.user_domain = ""; | ||
+ | |||
+ | /* | ||
+ | Set the NTP config time | ||
+ | */ | ||
+ | config_mail.time.ntp_server = F(" | ||
+ | config_mail.time.gmt_offset = 2; | ||
+ | config_mail.time.day_light_offset = 0; | ||
+ | |||
+ | /* Declare the message class */ | ||
+ | SMTP_Message message; | ||
+ | |||
+ | /* Set the message headers */ | ||
+ | message.sender.name = F(" | ||
+ | message.sender.email = AUTHOR_EMAIL; | ||
+ | message.subject = F(" | ||
+ | message.addRecipient(F(" | ||
+ | |||
+ | //Send raw text message | ||
+ | String textMsg = String(" | ||
+ | message.text.content = textMsg.c_str(); | ||
+ | message.text.charSet = " | ||
+ | message.text.transfer_encoding = Content_Transfer_Encoding:: | ||
+ | |||
+ | message.priority = esp_mail_smtp_priority:: | ||
+ | message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay; | ||
+ | |||
+ | |||
+ | /* Connect to the server */ | ||
+ | if (!smtp.connect(& | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | ESP.restart(); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | if (!smtp.isLoggedIn()) { | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | if (smtp.isAuthenticated()) | ||
+ | Serial.println(" | ||
+ | else | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | /* Start sending Email and close the session */ | ||
+ | if (!MailClient.sendMail(& | ||
+ | ESP_MAIL_PRINTF(" | ||
+ | |||
+ | |||
+ | // | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | |||
+ | camera_config_t config; | ||
+ | config.ledc_channel = LEDC_CHANNEL_0; | ||
+ | config.ledc_timer = LEDC_TIMER_0; | ||
+ | config.pin_d0 = Y2_GPIO_NUM; | ||
+ | config.pin_d1 = Y3_GPIO_NUM; | ||
+ | config.pin_d2 = Y4_GPIO_NUM; | ||
+ | config.pin_d3 = Y5_GPIO_NUM; | ||
+ | config.pin_d4 = Y6_GPIO_NUM; | ||
+ | config.pin_d5 = Y7_GPIO_NUM; | ||
+ | config.pin_d6 = Y8_GPIO_NUM; | ||
+ | config.pin_d7 = Y9_GPIO_NUM; | ||
+ | config.pin_xclk = XCLK_GPIO_NUM; | ||
+ | config.pin_pclk = PCLK_GPIO_NUM; | ||
+ | config.pin_vsync = VSYNC_GPIO_NUM; | ||
+ | config.pin_href = HREF_GPIO_NUM; | ||
+ | config.pin_sscb_sda = SIOD_GPIO_NUM; | ||
+ | config.pin_sscb_scl = SIOC_GPIO_NUM; | ||
+ | config.pin_pwdn = PWDN_GPIO_NUM; | ||
+ | config.pin_reset = RESET_GPIO_NUM; | ||
+ | config.xclk_freq_hz = 20000000; | ||
+ | config.pixel_format = PIXFORMAT_JPEG; | ||
+ | |||
+ | // init with high specs to pre-allocate larger buffers | ||
+ | if (psramFound()) { | ||
+ | config.frame_size = FRAMESIZE_UXGA; | ||
+ | config.jpeg_quality = 10; //0-63 lower number means higher quality | ||
+ | config.fb_count = 2; | ||
+ | } else { | ||
+ | config.frame_size = FRAMESIZE_SVGA; | ||
+ | config.jpeg_quality = 8; //0-63 lower number means higher quality | ||
+ | config.fb_count = 1; | ||
+ | } | ||
+ | |||
+ | // camera init | ||
+ | esp_err_t err = esp_camera_init(& | ||
+ | if (err != ESP_OK) { | ||
+ | Serial.printf(" | ||
+ | Serial.println(); | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | ESP.restart(); | ||
+ | } | ||
+ | |||
+ | sensor_t* s = esp_camera_sensor_get(); | ||
+ | |||
+ | // Selectable camera resolution details : | ||
+ | // -UXGA = 1600 x 1200 pixels | ||
+ | // -SXGA = 1280 x 1024 pixels | ||
+ | // -XGA = 1024 x 768 pixels | ||
+ | // -SVGA = 800 x 600 | ||
+ | // -VGA = 640 x 480 | ||
+ | // -CIF = 352 x 288 | ||
+ | // -QVGA = 320 x 240 | ||
+ | // -HQVGA | ||
+ | // -QQVGA | ||
+ | s-> | ||
+ | |||
+ | Serial.println(" | ||
+ | Serial.println(); | ||
+ | |||
+ | delay(1000); | ||
+ | |||
+ | Test_Con(); | ||
+ | |||
+ | SendCapturedPhotos(); | ||
+ | |||
+ | Serial.println(); | ||
+ | |||
+ | delay(15000); | ||
+ | |||
+ | rtc_gpio_hold_en(GPIO_NUM_4); | ||
+ | |||
+ | esp_sleep_enable_ext0_wakeup(GPIO_NUM_13, | ||
+ | |||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | esp_deep_sleep_start(); | ||
+ | } | ||
+ | // | ||
+ | |||
+ | // | ||
+ | void loop() { | ||
+ | } | ||
+ | |||
+ | </ | ||
===== 3. Results ===== | ===== 3. Results ===== | ||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
===== 4. Discussion and Conclusion ===== | ===== 4. Discussion and Conclusion ===== | ||
Line 136: | Line 629: | ||
As always there are some improvements that can be made. It would be better to use an infrared camera so even when it's dark the pictures are visible. Also for the current design of the house there can be some improvements by providing more holes so it has more ventilation and it wont accumulate water. | As always there are some improvements that can be made. It would be better to use an infrared camera so even when it's dark the pictures are visible. Also for the current design of the house there can be some improvements by providing more holes so it has more ventilation and it wont accumulate water. | ||
+ | === 4.2. Recomendations=== | ||
+ | * Perform measurements to make decisions related to the energy efficiency of the project. | ||
+ | * PCB design to allow better access and manipulation of essential elements of the project. | ||
+ | * Make improvements to the code dedicated to upload the photo to google drive to minimize errors. | ||
===== 5. Bibliography ===== | ===== 5. Bibliography ===== |
amc/ss2023/group-c/start.1690203762.txt.gz · Last modified: 2023/07/24 15:02 by fatima.mendoza