Aeris Workshop program to read Moisture sensor and send the data to AerCloud using MQTT

Dependencies:   MQTT mbed-src

Files at this revision

API Documentation at this revision

Comitter:
agoel
Date:
Wed Jun 17 22:55:16 2015 +0000
Parent:
2:08cbf9d1754f
Commit message:
TimeZone correction in setting time for RTC of the dragon fly board

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 08cbf9d1754f -r db681a5cf46f main.cpp
--- a/main.cpp	Wed Jun 17 00:10:49 2015 +0000
+++ b/main.cpp	Wed Jun 17 22:55:16 2015 +0000
@@ -102,8 +102,8 @@
 
 
 // Define alcoholSensor and moisture input PIN (Arduino connector namings A0 - PA_0, A1 - PA_1, A2 - PC_4, A3 - PB_0, A4 - PC_1, A5 - PC_0
-AnalogIn moistureSensor(PC_2);        // A0 - PA_0
-AnalogIn alcoholSensor(PB_0);   // A3
+AnalogIn moistureSensor(PC_2);      // A0 - PA_0
+AnalogIn alcoholSensor(PB_0);       // A3
 
 float moistureValue = 0.0f;
 float alcoholValue = 0.0f;
@@ -186,10 +186,12 @@
     char hourStr[2+1];
     char minuteStr[2+1];
     char secStr[2+1];
+    char timeZoneStr[3+1];
  
     uint32_t hourInt;
     uint32_t minuteInt;
     uint32_t secInt;
+    int32_t tzInt;
 
     //Step 1 - Seperate the day, month and year into their own NULL terminated string buffers...
     yearStr[0] = dateString[1];
@@ -222,10 +224,20 @@
     secStr[1] = timeString[7];
     secStr[2] = '\0';
 
+    timeZoneStr[0] = timeString[8];
+    timeZoneStr[1] = timeString[9];
+    if (timeString[10] != '\"') {
+        timeZoneStr[2] = timeString[10];
+    } else {
+        timeZoneStr[2] = '\0';
+    }
+    timeZoneStr[3] = '\0';
+
     //Step 4 - Run atoi() to parse the strings into integer values...
     hourInt = atoi(hourStr);
     minuteInt = atoi(minuteStr);
     secInt = atoi(secStr);
+    tzInt = atoi(timeZoneStr);
 
     time_t rawtime;
     struct tm * timeinfo;
@@ -247,16 +259,17 @@
      
 //    printf("***** Year: %s, Month: %s, Day: %s ****** \n\n\n", yearStr, monthStr, dayStr);
 //    printf("***** Year: %d, Month: %d, Day: %d ****** \n\n\n", yearInt, monthInt, dayInt);
-//    printf("***** hour: %s, minute: %s, sec: %s ****** \n\n\n", hourStr, minuteStr, secStr);
-//    printf("***** hour: %d, minute: %d, sec: %d ****** \n\n\n", hourInt, minuteInt, secInt);
+//    printf("***** hour: %s, minute: %s, sec: %s, TZ: %s ****** \n\n\n", hourStr, minuteStr, secStr, timeZoneStr);
+//    printf("***** hour: %d, minute: %d, sec: %d, TZ: %d ****** \n\n\n", hourInt, minuteInt, secInt, tzInt);
 
     time_t t1=0;
     t1 = mktime(timeinfo);
-    set_time (t1 + 7*60*60); //offseting the TimeZone Index
+    set_time (t1 - tzInt*15*60); // offseting the TimeZone Index (received value from string is in quarter of the hour)
     ctTime = time (NULL);
     printf("Time set to (UTC): %s\r\n", ctime(&ctTime));
 }
 
+
 int main()
 {
     bool simProvisioned = false;