User Tools

Site Tools


amc:ss2025:group-f:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amc:ss2025:group-f:start [2025/07/28 20:43] – [3.1 Code Explanation] 33784_students.hsrwamc:ss2025:group-f:start [2025/07/29 22:36] (current) paul-christian.thoma
Line 1: Line 1:
 ======  Smart Plant Watering with ESP32 and MQTT====== ======  Smart Plant Watering with ESP32 and MQTT======
 +**Applied Measurement and Control 2025**
 +
 Paul-Christian Thoma(32436)-Elham Mohammadi(32475)-Deniz-Zeynep Adem(33784) Paul-Christian Thoma(32436)-Elham Mohammadi(32475)-Deniz-Zeynep Adem(33784)
  
Line 16: Line 18:
 By combining local sensing, cloud-based logic, and remote monitoring tools, this system provides a scalable, modular approach to smart irrigation in home or laboratory environments. By combining local sensing, cloud-based logic, and remote monitoring tools, this system provides a scalable, modular approach to smart irrigation in home or laboratory environments.
  
-{{ amc:ss2025:group-f:prototype2.jpeg |}}+{{ :amc:ss2025:group-f:prototype2.jpeg?direct&600 |{{ amc:ss2025:group-f:prototype2.jpeg |}}}}
 **Figure 1.** Automated Plant Watering System Prototype **Figure 1.** Automated Plant Watering System Prototype
  
Line 123: Line 125:
 The following diagrams, created using Tinkercad, illustrate the complete hardware connections for both the Sensor and Pump nodes in the system.  The following diagrams, created using Tinkercad, illustrate the complete hardware connections for both the Sensor and Pump nodes in the system. 
  
-{{ amc:ss2025:group-f:moisture_sensor_circuit.png |}}+{{ :amc:ss2025:group-f:moisture_sensor_circuit.png?direct&600 |}}
 **Figure 2.** Schematic Diagram of Sensor Setup (designed by Deniz-Zeynep Adem) **Figure 2.** Schematic Diagram of Sensor Setup (designed by Deniz-Zeynep Adem)
                                      
  
-{{ amc:ss2025:group-f:pump_wiring_with_adaptor.png |}}+{{ :amc:ss2025:group-f:pump_wiring_with_adaptor.png?direct&600 |}}
 **Figure 3.** Schematic Diagram of Pump Setup (designed by Deniz-Zeynep Adem) **Figure 3.** Schematic Diagram of Pump Setup (designed by Deniz-Zeynep Adem)
  
Line 496: Line 498:
 **4. Integrate the Web App URL into Your ESP32 Code** **4. Integrate the Web App URL into Your ESP32 Code**
  
-In your ESP32 Arduino code, update the `GOOGLE_SHEET_URL`:+In your ESP32 Arduino code, update the `GOOGLE_SHEET_URL` with the copied URL from your own project:
  
 '' ''
Line 504: Line 506:
  
 '' ''
- 
- //Don't forget to replace `"your_script_id"` with the full Web App URL you copied!// 
- 
  
  
Line 512: Line 511:
 **5. Upload and Run the ESP32 Code** **5. Upload and Run the ESP32 Code**
  
-Upload your finalized ESP32 code via Arduino IDE or PlatformIO.+Upload your finalized ESP32 code via Arduino IDE.
  
   * **The ESP32 will:**   * **The ESP32 will:**
Line 535: Line 534:
 **Google Apps Script Codes:** **Google Apps Script Codes:**
  
 +<code cpp> 
 +function doPost(e) {
   try {   try {
     const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");     const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
     const data = JSON.parse(e.postData.contents);     const data = JSON.parse(e.postData.contents);
 +
     const status = data.status || "";     const status = data.status || "";
     const moisture = data.moisture || "";     const moisture = data.moisture || "";
     const action = data.action || "";     const action = data.action || "";
     const timestamp = new Date();     const timestamp = new Date();
-    // Insert new row at top (after header)+ 
 +    // Add new data to top (2nd row)
     sheet.insertRows(2, 1);     sheet.insertRows(2, 1);
-    sheet.getRange(2, 1).setValue(timestamp);   // Column A: Timestamp +    sheet.getRange(2, 1).setValue(timestamp); 
-    sheet.getRange(2, 2).setValue(action);      // Column B: Action (e.g., Pump is ON) +    sheet.getRange(2, 2).setValue(action); 
-    sheet.getRange(2, 3).setValue(moisture);    // Column C: Moisture value +    sheet.getRange(2, 3).setValue(moisture); 
-    sheet.getRange(2, 4).setValue(status);      // Column D: Status (e.g., Moist 😊) +    sheet.getRange(2, 4).setValue(status); 
-    // Optional: Send email alert when there's a maintenance alert+ 
 +    // Send emails if there is an alert
     if (action.toLowerCase().includes("alert")) {     if (action.toLowerCase().includes("alert")) {
-      const emailAddress = "youremail@example.com"; // Replace with your email +      MailApp.sendEmail("youremail@example.com""⚠️ Plant Alert" 
-      const subject = "⚠️ Plant System Alert"; +        `Soil Alert!\nStatus: ${status}\nMoisture: ${moisture}\nAction: ${action}`);
-      const message = `An alert has been logged in your system:\n\n` + +
-                      `Status: ${status}\nMoisture: ${moisture}\nAction: ${action}\nTime: ${timestamp}`+
-      MailApp.sendEmail(emailAddress, subject, message);+
     }     }
 +
     return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT);     return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT);
-  } catch (error) { +  } catch (err) { 
-    Logger.log("Error: " + error); +    return ContentService.createTextOutput("Error: " + err)
-    return ContentService.createTextOutput("Error: " + error)+
                          .setMimeType(ContentService.MimeType.TEXT);                          .setMimeType(ContentService.MimeType.TEXT);
   }   }
 +}
 +
 +</code>
 ======  4. Node-RED Overview====== ======  4. Node-RED Overview======
  
Line 573: Line 576:
 Below is a video showcasing the node-Red flow and showing the code and possible errors that came up and how they were fixed. Starting with the discussion part of this documentation.  Below is a video showcasing the node-Red flow and showing the code and possible errors that came up and how they were fixed. Starting with the discussion part of this documentation. 
  
-https://student-wiki.eolab.de/lib/exe/fetch.php?w=120&h=120&tok=b20d52&media=amc:ss2025:group-f:whatsapp_image_2025-07-28_at_12.23.27_am.jpeg +{{ :amc:ss2025:group-f:file_2025-07-28_14.25.34.png?direct&600 |}}
  
 **Figure 4.** Documentation of the data in note-red (designed by Paul-Christian Thoma) **Figure 4.** Documentation of the data in note-red (designed by Paul-Christian Thoma)
Line 622: Line 624:
  
  
-{{youtube>sK5l7mIVL0s?}} +{{youtube>sK5l7mIVL0s?}}                                         
- +
- +
  
 +{{youtube>vU9CFVkbPiY?}}
  
 +{{youtube>XZt8VXC4Ths?}}
  
  
amc/ss2025/group-f/start.1753728219.txt.gz · Last modified: 2025/07/28 20:43 by 33784_students.hsrw