STM32L476
Dependencies: MbedJSONValue SDFileSystem WConstants mbed-dev DS1820 TinyGPSPlus epd1in54
Fork of A_SSL_Main by
Diff: main.cpp
- Revision:
- 8:bc5a3b2ff424
- Parent:
- 6:d30c8e8678c9
- Child:
- 9:4ac09d77e2a0
diff -r e4b43774834e -r bc5a3b2ff424 main.cpp --- a/main.cpp Thu Aug 30 18:58:19 2018 +0000 +++ b/main.cpp Sun Sep 09 23:08:02 2018 +0000 @@ -9,10 +9,11 @@ #include "TinyGPSPlus.h" #include "SDFileSystem.h" #include "errno.h" - +#include "MbedJSONValue.h" +#include <string> -#define TX5 PG_7 -#define RX5 PG_8 +#define TX5 PB_6 +#define RX5 PG_10 #define GPSBaud 9600 #define Serial0Baud 115200 #define SD_FILE_SYSTEM_H @@ -175,7 +176,7 @@ return t; } -int sdCard() +int sdCardTest() { //SD card // Create and mount SDFileSystem @@ -219,6 +220,7 @@ err = fprintf(fp, " %d\r\n", i); if (err < 0) { serial.printf("Fail :(\r\n"); + error("error: %s (%d)\r\n", strerror(errno), -errno); } else serial.printf("OK\r\n"); @@ -265,6 +267,32 @@ } +//ToDo: pass arguments, organise inner subobjects, currently dummy values +string jsonSerializeDeviceToSystem() +{ + MbedJSONValue statusReport; + std::string s; + + //fill the object + statusReport["timestamp"]= "2018-04-23T18:25:43.511Z"; + statusReport["device"] = "DEVICE-1"; + statusReport["latitude"]= 57.1234; + statusReport["longitude"] = -4.567; + statusReport["geoFence"] = 1; + statusReport["container"] = 12.3; + statusReport["heater"] = 34.5; + statusReport["batteryVoltage"] = 4.98; + statusReport["network"] = "Vodafone UK"; + statusReport["signalStrength"] = -89; + + //serialize it into a JSON string + s = statusReport.serialize(); + serial.printf("status: %s\r\n",s ); + // + + return s; +} + int main() { GPSSerial.baud(GPSBaud); @@ -279,12 +307,14 @@ float y[5] = { 1,1,4,4,1}; float xtest; float ytest; + char xtestchar[32]; + char ytestchar[32]; float cx = 1; float cy = 50; float r = 15; int ans = 0; float liquidTemp = 0; - + std::string srr; wait(2); @@ -301,22 +331,35 @@ // serial.printf("%f\t%c\t%f\t%c\t%f\t%f\t%f\n\r",gps.longitude, gps.ns,gps.latitude,gps.ew, gps.alt, gps.geoid, gps.time); // serial.printf("%d:%d:%d",gps.hour,gps.minute,gps.seconed); // } - sdCard(); + sdCardTest(); while(1) { //wait (1); - + /* if (tgps.encode(GPSSerial.getc())) { displayInfo(); xtest = tgps.location.lng(); ytest = tgps.location.lat(); + sprintf(xtestchar,"%.2f", xtest); + sprintf(ytestchar,"%.2f", ytest); + serial.printf("\r\n %3.6f, %3.6f, \r\n", ytest, xtest); ans = inCircle(r, cx, cy, xtest, ytest); wait(5); //little delay to prevent double writing liquidTemp = getTemp(); serial.printf("\r\n In geofence = %d: \r\n", ans); + */ + srr = jsonSerializeDeviceToSystem(); + //char srrrr=srr.c_str(); + //const char srr = sr.c_str(); + + sd.mount(); + FILE *fp = fopen("/sd/logtest.txt", "w"); + fprintf(fp, srr.c_str()); + sd.unmount(); + /* } if (millis() > 5000 && tgps.charsProcessed() < 10) @@ -331,12 +374,15 @@ serial.printf("%d\r\n",i); i++; wait(1.0); + */ + wait(5); + } - wait(5); + } - +}