Differences

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

Link to this comparison view

pm:prj2023:adarmaz:sistem-cartografiere-sol [2023/05/30 09:06]
ioana.profeanu [Configurare timer]
pm:prj2023:adarmaz:sistem-cartografiere-sol [2023/05/30 09:13] (current)
ioana.profeanu [Download cod]
Line 150: Line 150:
  
 Pentru lucrul cu cardul SD, am utilizat biblioteca SD.h, ce pune la dispoziție funcții de bază pentru scrierea și citirea datelor de pe cardul SD. Pentru lucrul cu cardul SD, am utilizat biblioteca SD.h, ce pune la dispoziție funcții de bază pentru scrierea și citirea datelor de pe cardul SD.
 +
 +=== Scrierea metricilor medii ===
 +
 +La fiecare recalculare a metricilor, mediile datelor citite sunt stocate și pe cardul SD într-un fișier de log numit metrics.txt,​ inserându-se media temperaturii,​ a umitității aerului și solului, a luminozității și numărul de citiri.
  
 <spoiler Cod scriere metrici pe cardul SD> <spoiler Cod scriere metrici pe cardul SD>
 <code cpp> <code cpp>
-void writeMetricsToSD(){+// function which writes the average metrics to sd card 
 +void writeMetricsToSD() 
 +{
   if (SD.begin(7)) {   if (SD.begin(7)) {
     File myFile;     File myFile;
Line 187: Line 193:
 </​code>​ </​code>​
 </​spoiler>​ </​spoiler>​
- 
-=== Scrierea metricilor medii === 
- 
-La fiecare recalculare a metricilor, mediile datelor citite sunt stocate și pe cardul SD într-un fișier de log numit metrics.txt,​ inserându-se media temperaturii,​ a umitității aerului și solului, a luminozității și numărul de citiri. 
  
 === Citirea plantelor === === Citirea plantelor ===
Line 220: Line 222:
 <code cpp> <code cpp>
  
-void displayPlantsList(bool showAll) { +// functions which displays the valid plants 
-  display.clear(); ​// Clear the display +// on the display 
-  display.setCursor(0,​ 0); // Set the cursor position +void displayPlantsList(bool showAll) 
-  if (SD.begin(7)){+
 +  display.clear();​ 
 +  display.setCursor(0,​ 0); 
 +  ​// try to read from SD card 
 +  if (SD.begin(7)) {
     File myFile;     File myFile;
-    if(SD.exists("​plants.txt"​)) {+    if (SD.exists("​plants.txt"​)) {
       myFile = SD.open("​plants.txt"​);​       myFile = SD.open("​plants.txt"​);​
- +      // if the file exists, read from it 
-      if(myFile) {+      if (myFile) {
         int noPlantsOk = 0;         int noPlantsOk = 0;
- +        // parse the data of the plant by extracting it; 
-        while(myFile.available()) {+        // each data is delimited by a comma 
 +        while (myFile.available()) {
           bool okPlant = false;           bool okPlant = false;
           String line = myFile.readStringUntil('​\n'​);​           String line = myFile.readStringUntil('​\n'​);​
Line 237: Line 244:
           int values[9];           int values[9];
           int index = 0;           int index = 0;
 +          // read line
           while (line.length() > 0) {           while (line.length() > 0) {
             int commaIndex = line.indexOf(','​);​             int commaIndex = line.indexOf(','​);​
-            ​ 
             if (commaIndex != -1) {             if (commaIndex != -1) {
               String element = line.substring(0,​ commaIndex);​               String element = line.substring(0,​ commaIndex);​
-              line = line.substring(commaIndex + 2); // Skip comma and space after each value+              line = line.substring(commaIndex + 2);
               ​               ​
               if (index == 0) {               if (index == 0) {
Line 249: Line 255:
               } else {               } else {
                 values[index - 1] = element.toInt();​                 values[index - 1] = element.toInt();​
 +                // check if the plant is between parameters
                 if (showAll == false) {                 if (showAll == false) {
                   if (index == 1) {                   if (index == 1) {
Line 261: Line 267:
                   if (index == 3) {                   if (index == 3) {
                     int mediumTemp = sumTemps / timesRead;                     int mediumTemp = sumTemps / timesRead;
-                    if ((mediumTemp >= values[1] && mediumTemp <= values[2]) == false) {+                    if ((mediumTemp >= values[1] && mediumTemp <= values[2]) ​ 
 +                        ​== false) {
                       break;                       break;
                     }                     }
Line 268: Line 275:
                   if (index == 5) {                   if (index == 5) {
                     int mediumAirMoist = sumAirMoist / timesRead;                     int mediumAirMoist = sumAirMoist / timesRead;
-                    if ((mediumAirMoist >= values[3] && mediumAirMoist <= values[4]) == false) {+                    if ((mediumAirMoist >= values[3] && mediumAirMoist 
 +                        ​<= values[4]) == false) {
                       break;                       break;
                     }                     }
Line 275: Line 283:
                   if (index == 7) {                   if (index == 7) {
                     int mediumSoilMoist = sumSoilMoist / timesRead;                     int mediumSoilMoist = sumSoilMoist / timesRead;
-                    if ((mediumSoilMoist >= values[5] && mediumSoilMoist <= values[6]) == false) {+                    if ((mediumSoilMoist >= values[5] && mediumSoilMoist 
 +                        ​<= values[6]) == false) {
                       break;                       break;
                     }                     }
Line 284: Line 293:
               index++;               index++;
             } else {             } else {
-              // Last value in the line (no comma at the end)+              // read last value from line
               String element = line;               String element = line;
               values[index - 1] = element.toInt();​               values[index - 1] = element.toInt();​
               int mediumLight = sumLight / timesRead;               int mediumLight = sumLight / timesRead;
-              if (showAll == false && (mediumLight >= values[7] && mediumLight <= values[8]) == false) {+              if (showAll == false && (mediumLight >= values[7] 
 +                  ​&& mediumLight <= values[8]) == false) {
                 break;                 break;
               }               }
 +
               okPlant = true;               okPlant = true;
               noPlantsOk++;​               noPlantsOk++;​
Line 296: Line 307:
             }             }
           }           }
 +          // if a plant was found, display it
           if (okPlant) {           if (okPlant) {
-            ​checkAndDisplayPlant(name, values);+            ​displayPlantDetails(name, values);
           }           }
         }         }
 +        // if no plants were found
         if (noPlantsOk == 0) {         if (noPlantsOk == 0) {
           display.println("​No plants matched!"​);​           display.println("​No plants matched!"​);​
-          display.displayRows(); ​// Update the display+          display.displayRows();​
           delay(8000);​           delay(8000);​
         }         }
Line 308: Line 321:
           ​           ​
       } else {       } else {
 +        // if the file is not found
         display.println("​Add plants.txt file first!"​);​         display.println("​Add plants.txt file first!"​);​
-        display.displayRows(); ​// Update the display+        display.displayRows();​
         delay(8000);​         delay(8000);​
       }       }
     }      } 
   } else {   } else {
 +    // if unable to read file
     display.println("​Failed to display plants!"​);​     display.println("​Failed to display plants!"​);​
-    display.displayRows(); ​// Update the display+    display.displayRows();​
     delay(8000);​     delay(8000);​
   }   }
 } }
-    ​ 
 </​code>​ </​code>​
 </​spoiler>​ </​spoiler>​
Line 333: Line 347:
 <code cpp> <code cpp>
  
-// function ​for extracting ​the latitude +// function ​which, from an input NMEA sentence, 
-String ​extractLatitude(const String& sentence) {+// extracts a string with the latitude 
 +String ​extractCoordinates(const String& sentence) 
 +{
   int commas;   int commas;
   if (sentence.indexOf("​GPRMC"​) != -1) {   if (sentence.indexOf("​GPRMC"​) != -1) {
Line 348: Line 364:
   int endIndex = -1;   int endIndex = -1;
  
 +  // count commas and extract the value of the latitude
   for (size_t i = 0; i < sentence.length();​ i++) {   for (size_t i = 0; i < sentence.length();​ i++) {
     if (sentence[i] == ','​) {     if (sentence[i] == ','​) {
Line 367: Line 384:
 } }
  
-// function ​for receiving ​NMEA sentences+// function ​which reads NMEA sentences ​from 
 +// software serial for 20 seconds and returns the 
 +// latitude in case the sentence is valid
 String getGPGGAsentence() String getGPGGAsentence()
 { {
Line 376: Line 395:
   gpsSerial.begin(9600);​   gpsSerial.begin(9600);​
  
-  // repeat the reading for 20 seconds 
   while (timerDisplayInfo - currentTime < MINUTE / 4) {   while (timerDisplayInfo - currentTime < MINUTE / 4) {
     if (gpsSerial.available()) {     if (gpsSerial.available()) {
Line 400: Line 418:
   return sentence;   return sentence;
 } }
- 
 </​code>​ </​code>​
 </​spoiler>​ </​spoiler>​
Line 450: Line 467:
 ===== Download cod ===== ===== Download cod =====
  
-Codul poate fi vizualizat [[https://​github.com/​ioanaprofeanu/​Sistem-cartografiere-sol.git|aici]].+Codul poate fi vizualizat [[https://​github.com/​ioanaprofeanu/​Sistem-cartografiere-sol.git|aici]] ​sau descărcat {{:​pm:​prj2023:​adarmaz:​sistem_cartografiere_sol.zip|aici}}.
 ===== Jurnal ===== ===== Jurnal =====
  
pm/prj2023/adarmaz/sistem-cartografiere-sol.1685426792.txt.gz · Last modified: 2023/05/30 09:06 by ioana.profeanu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0