STM32L476

Dependencies:   MbedJSONValue SDFileSystem WConstants mbed-dev DS1820 TinyGPSPlus epd1in54

Fork of A_SSL_Main by SilentSensors

Revision:
15:fad0681e6fee
Parent:
13:0477a745dad2
--- a/main.cpp	Tue Dec 04 17:49:59 2018 +0000
+++ b/main.cpp	Sun Dec 16 19:37:42 2018 +0000
@@ -19,16 +19,17 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Definitions and initialization
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
-#define TX5 PC_12
-#define RX5 PD_2
+#define TX5 PC_10
+#define RX5 PC_11
 #define GPSBaud 9600
 #define SerialBaud 115200
 #define SD_FILE_SYSTEM_H   
 SDFileSystem*       fs;
 FILE*               fp;
 TinyGPSPlus tgps;
-Serial serial(USBTX, USBRX,115200);                 //Local terminal Baud rate                              
-//SDFileSystem sd(PB_5, PB_4, PB_3, PB_12, "sd");     //uSD SPI
+Serial serial(USBTX, USBRX,115200);                 //Local terminal Baud rate  
+Serial GPSSerial(TX5, RX5);                            
+SDFileSystem sd(PB_5, PB_4, PB_3, PB_12, "sd");     //uSD SPI
 
 //Temp sensors
 #define MAX_PROBES      16
@@ -38,7 +39,7 @@
 //E-ink Display
 PinName rst; PinName dc; PinName busy; PinName mosi; PinName miso; PinName sclk; PinName cs;
 unsigned char frame_black[EPD_HEIGHT*EPD_WIDTH/8];
-Epd epd = Epd(PB_5, PB_4, PB_3, PA_8, PC_4, PC_7, PB_10);
+//Epd epd = Epd(PB_5, PB_4, PB_3, PA_8, PC_4, PC_7, PB_10);
 
 const  char * system_message;                       //Journey configuration to be received from server
 int deviceID = 1;
@@ -53,14 +54,14 @@
 char * readLastGeo;
 int msg_index;
 double geofencesNum;
-int geotest;
+int geotest=0;
 char geo_extract[6];
-
-DigitalOut en1(PC_5);
+/*
+    DigitalOut en1(PC_5);
     DigitalOut en2(PC_6);
     DigitalOut en3(PC_8);
     DigitalOut en4(PC_9);
-    
+ */   
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -165,17 +166,11 @@
     if (epd.Init(lut_full_update) != 0) {
         return -1;
     }
-    /*Write strings to the buffer */
-    epd.DrawStringAt(frame_black, 0, 10, "Temperature:", &Font24, COLORED);
-    epd.DrawStringAt(frame_black, 60, 30, cValt, &Font24, COLORED);
-    epd.DrawStringAt(frame_black, 0, 70, "In Geofence?", &Font24, COLORED);
-    if (g == 1){
-    epd.DrawStringAt(frame_black, 60, 90, "In Geo", &Font24, COLORED);
-    }
-    else {
-        epd.DrawStringAt(frame_black, 60, 90, "No", &Font24, COLORED);
-    }
-    /* Display the frame_buffer */
+    //Write strings to the buffer 
+    epd.DrawStringAt(frame_black, 0, 40, cValt, &Font72, COLORED);
+    epd.DrawStringAt(frame_black, 160, 120, "C", &Font24, COLORED);
+   
+    // Display the frame_buffer 
     epd.SetFrameMemory(frame_black, 0, 0, epd.width, epd.height);
     epd.DisplayFrame();
     epd.Sleep();
@@ -259,8 +254,8 @@
     statusReport["longitude"] = longTest;
     statusReport["geoFenceNum"] = geoFenceNum;
     statusReport["geoFenceEnteryDeparture"] = value;
-    statusReport["container"] = liquidTemp;
-    statusReport["Ambient"] = ambientTemp;
+    statusReport["liquidTemp"] = liquidTemp;
+    statusReport["AmbientTemp"] = ambientTemp;
     statusReport["heater"] = 34.5;
     statusReport["batteryVoltage"] = 3.67;
     statusReport["network"] = "Tele2";
@@ -280,8 +275,9 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 double jsonParseSystemToDevice(const char * parameter, int msg_index)
 {
+system_message = "{\"config\":[1.0,1.0,240.0,5.0],\"route1\":[1.0,0.0,1.0,1.0,1.0,1.0,54.5983852,-1.5708491,54.5969549,-1.5663735],\"route2\":[2.0,0.0,1.0,1.0,1.0,1.0,54.6542957,-1.4459836,54.6495902,-1.4430425],\"route3\":[3.0,0.0,1.0,1.0,1.0,1.0,54.7051416,-1.5638412,54.7101814,-1.5615844],\"route4\":[4.0,0.0,1.0,1.0,1.0,1.0,54.6298560,-1.3059736,54.6267899,-1.3075833],\"route5\":[5.0,1.0,1.0,1.0,1.0,2.0,5.0,54.6710093,-1.4587418,54.6730758,-1.4461951,54.6672642,-1.4436423,54.6678548,-1.4562232,54.6710093,-1.4587418]}";
 // Journey message received from system parsed into values. Message description:
-//"{\"config\":[device,temperatureRequired,temperatureInterval,numberOfGeos],\"route1\":[geoFenceNum,heating,temperatureRequired,pingOnArrival,pingOnDeparture,shape,outerCircle,latCentre,longCentre,latEdge,LongEdge,latEdge2,longEdge2],.........,\"routeX\":[geoFenceNum,heating,temperatureRequired,pingOnArrival,pingOnDeparture,shape,numOfVertices,lat1,long1,lat2,long2,..............,lat1,long1]}
+//"{\"config\":[device,temperatureRequired,temperatureInterval,numberOfGeos],\"route1\":[geoFenceNum,heating,temperatureRequired,pingOnArrival,pingOnDeparture,shape,outerCircle,latCentre,longCentre,latEdge,LongEdge,latEdge2,longEdge2],.........,\"routeX\":[geoFenceNum,heating,temperatureRequired,pingOnArrival,pingOnDeparture,shape,numOfVertices,lat1,long1,lat2,long2,..............,latX,longY]}
 
 MbedJSONValue journey;
 parse(journey, system_message);
@@ -292,8 +288,8 @@
 
 int main()
 {
-    en1=1;en2=1;en3=1;en4=1;
-    Serial GPSSerial(TX5, RX5);
+    //en1=1;en2=1;en3=1;en4=1;
+    
     GPSSerial.baud(GPSBaud);
     wait(0.001);
     DigitalOut SD_EN(PB_12);            //SD SPI enable (active low)
@@ -301,8 +297,7 @@
 
     //ToDo: To be replaced by the value received when subscribed to the Iot hub
     //Subscribe and save the message in system_message
-    system_message = "{\"config\":[1.0,1.0,240.0,5.0],\"route1\":[1.0,0.0,1.0,1.0,1.0,1.0,54.5983852,-1.5708491,54.5969549,-1.5663735],\"route2\":[2.0,0.0,1.0,1.0,1.0,1.0,54.6542957,-1.4459836,54.6495902,-1.4430425],\"route3\":[3.0,0.0,1.0,1.0,1.0,1.0,54.7051416,-1.5638412,54.7101814,-1.5615844],\"route4\":[4.0,0.0,1.0,1.0,1.0,1.0,54.6298560,-1.3059736,54.6267899,-1.3075833],\"route5\":[5.0,1.0,1.0,1.0,1.0,2.0,5.0,54.6710093,-1.4587418,54.6730758,-1.4461951,54.6672642,-1.4436423,54.6678548,-1.4562232,54.6710093,-1.4587418]}";
-
+    
 
     wait(1);
     serial.printf("Silent Hub v1.0  ........................\r\n"); 
@@ -314,11 +309,8 @@
    
    while(1) {     
         sleepCounter++;
-        
-        
         if(tgps.encode(GPSSerial.getc()))
-        {
-            tgps.encode(GPSSerial.getc());
+        {   
             latTest = tgps.location.lat(); longTest = tgps.location.lng();                      //Location  
             tyear = tgps.date.year(); tmonth = tgps.date.month(); tday = tgps.date.day();       //Date
             thour = tgps.time.hour(); tmin = tgps.time.minute(); tsec = tgps.time.second();     //Time
@@ -386,13 +378,13 @@
                 
             }
             count = count--;
-            /*
-            if (geotest == 0)       //ToDo &&make sure the last publish handshake was successful 
+            if (geotest == 1)       //ToDo &&make sure the last publish handshake was successful 
                 {
                 //msg to be saved on SD and published, will overwrite last saved message
                 s = jsonSerializeDeviceToSystem(deviceID, longTest, latTest, count, geotest, liquidTemp, ambientTemp, tday, tmonth, tyear, thour, tmin, tsec);
                 sprintf(chr_s,s.c_str());
                 Epd_EN = 1;
+                wait(0.02);
                 new_file("/sd/DeviceToSystemLog.txt");
                 add_data("/sd/DeviceToSystemLog.txt",chr_s);
                 read_file("/sd/DeviceToSystemLog.txt");
@@ -412,16 +404,18 @@
                 //NVIC_SystemReset();  
                 
                 //If it is a heating station log temperature 
-                
-                
                 }
-                new_file("/sd/HeatingStationLog.txt");
+                Epd_EN = 1;
+                double isHeat = 1;
                 readLastGeo = read_file("/sd/LastGeofence.txt");
+                serial.printf("pointer");
                 int intVal = atoi(readLastGeo);
                 serial.printf("\r\nlast Geo in int = %d:",intVal);
                 sprintf(geo_extract,"route%d",intVal);
-                if (jsonParseSystemToDevice(geo_extract,1) == 1.0);             //Check if it is a heating station
+                if (jsonParseSystemToDevice(geo_extract,1) == isHeat)             //Check if it is a heating station
                 {
+                    printf("pointer3: %3.2f",jsonParseSystemToDevice(geo_extract,1));
+                    serial.printf("pointer2");
                     char liq[32];char amb[32];
                     //const char seperator = ",";
                     sprintf(liq,"%.2f", liquidTemp);
@@ -431,8 +425,9 @@
                     add_data("/sd/HeatingStationLog.txt",amb);
                     add_data("/sd/HeatingStationLog.txt",",");
                     read_file("/sd/HeatingStationLog.txt");
+                    Epd_EN = 0;
                 }
-                   */ 
+                    
                 
         }
 
@@ -443,8 +438,4 @@
         }
    
     }
-  }
-
-
-
-
+}
\ No newline at end of file