Geolocation through Ethernet

Dependencies:   mbed HTTPClient MMA8452Q mbed-rtos 4DGL-uLCD-SE NTPClient SDFileSystem1 EthernetInterface

Revision:
1:b0c480b628cd
Parent:
0:070ff55a028f
Child:
3:65349fe42061
--- a/main.cpp	Wed Dec 16 18:52:01 2020 +0000
+++ b/main.cpp	Thu Dec 17 18:34:29 2020 +0000
@@ -3,16 +3,19 @@
 #include "uLCD_4DGL.h"
 #include "EthernetInterface.h"
 #include "HTTPClient.h"
-//Geolocation output to LCD
+#include "SDFileSystem.h"
+//Geolocation output to LCD and SD card reader
 //Code based on: https://os.mbed.com/users/tlisowski3/notebook/geolocation-and-ntp-clock-on-ulcd-144-g2/
 
-//Set up Networking and LCD
+//Set up Networking, LCD and SD Card reader
+uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card, SPI pins
 EthernetInterface eth;
-uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
 NTPClient ntpClient;
 HTTPClient httpClient;
 
 void parse(char buffer[], int *j, char *string); //FUNCTION TO PARSE HTTP GET DATA
+void sdlog(int type, float time, float input0, char input1[], char input2[], char input3[]); //Function to write to the SD card
 char httpGetData[200]; //BUFFER TO HOLD DATA FROM HTTP GET REQUEST
  
 int main() {
@@ -59,7 +62,7 @@
         uLCD.printf("HTTP Error %d", r);
         return -1;
     }
-
+    sdlog(0, 1, 2, latitude, longitude, city);// Save info to SD card
     //Print Location Information
     uLCD.cls();
     uLCD.locate(0,0);
@@ -67,6 +70,7 @@
     uLCD.printf("LAT:%s\nLONG:%s\n",latitude,longitude); //LATITUDE AND LONGITUDE 
     uLCD.printf("Timezone:\n%s",timeZone); //PRINT TIMEZONE
     eth.disconnect(); //DISCONNECT FROM THE NETWORK 
+    
 }
 
 //SET FOR CSV FORMAT: NEEDS TO BE EDITED IF DIFFERENT FORMAT
@@ -82,3 +86,26 @@
         } else string[i]=buffer[*j+i]; //Keep adding to the string
     }
 }
+
+void sdlog(int type, float time, float input0, char input1[], char input2[], char input3[]){
+     FILE *file;
+    switch (type){
+    case 0:
+            file = fopen("/sd/location.txt", "w");
+        fprintf(file, "TIME: %f, Latitude: %s Longitude: %s, City: %s\n\r", time, input1, input2, input3);
+        fclose(file);
+        break;
+    case 1:
+            file = fopen("/sd/temperature.txt", "w");
+        fprintf(file, "TIME: %f, %f degC\n\r", time, input0);
+        fclose(file);
+        break;
+    case 2:
+            file = fopen("/sd/acceleration.txt", "w");
+        fprintf(file, "TIME: %f, WARNING: LOAD EXCEDDED MAXIMUM ALLOWED ANGLE\n\r", time);
+        fclose(file);
+        break;
+    default:
+    break;
+    }
+}
\ No newline at end of file