a

Dependencies:   mbed Sht31 MAX44009

Revision:
7:e4984029012e
Parent:
6:94a26631ec03
Child:
8:cca99ce7c5bc
--- a/main.cpp	Thu Apr 23 14:33:38 2020 +0000
+++ b/main.cpp	Fri Apr 24 03:57:46 2020 +0000
@@ -34,7 +34,8 @@
 float luxdata[10];
 
 int counter = 10; //to tackle with 0 mod 10 problem, use 10 instead;
-
+int sendCounter=0; // for sending in auto/ instant measure
+int _30Scounter=0;
 bool allfilled = false;
 RGBf RGBavg;
 TandH THavg;
@@ -48,15 +49,17 @@
 
 int main()
 {   
-
+    set_time(1587699064); 
+ 
     //pc.read
     pc.baud ( 19200 );
     Batt2SYS = 0;
 
-
+ 
        
     while(1) { 
         counter = counter%10;
+        time_t seconds = time(NULL);
         {
             int sensor_addr = 41 << 1;
             char id_regval[1] = {146};
@@ -193,31 +196,50 @@
        // pc.printf("Shine Like:%s,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",signal,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
             BLE_Can_receive = 0;
             counter++;
-            if (counter == 10){
+            if (counter == 10 &&_30Scounter==3){
+                _30Scounter=0;
                 FILE *fp = fopen("/local/out.txt", "a");   
-                fprintf(fp, "{%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f},",(int)(RGBavg.C+0.5),
-                 (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);   
-                 fclose(fp); 
+                fprintf(fp, "[%d,%d,%d,%d,%d,%d,%d,%0.001f],\n",seconds,(int)(RGBavg.C+0.5),
+                        (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),(int)THavg.t,(int) THavg.h,luxavg);   
+                fclose(fp); 
                 allfilled = true; 
             }
+            else if (counter==10){
+                _30Scounter++;
+                 allfilled = true; 
+            }
             BLE_Can_receive = 1;
         if (wrote){
-            //wait_ms(5);
-            pc.printf("%s,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",signal,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
-            if (counter == 10){ //10 = all element is filled {  
-                if (signal[0]=='i'){
-                    pc.printf("end");
+            if (signal[0]=='s'){
+                FILE *fp = fopen("/local/out.txt", "r"); 
+                char str[45];   
+                 while(!feof(fp))
+                    if(fgets(str,40,fp)!=NULL) {
+                        pc.printf("%s\n",str);
+                        //wait_ms(300);
+                    }
+                 fclose(fp);
+                wrote=false;
+            }
+            else {
+                sendCounter++;
+                pc.printf("%d,%d,%d,%d,%d,%3.2f,%3.2f%,%0.001f\n",sendCounter,(int)(RGBavg.C+0.5), (int)(RGBavg.R+0.5), (int)(RGBavg.G+0.5), (int)(RGBavg.B+0.5),THavg.t, THavg.h,luxavg);
+                if (sendCounter == 10){ //10 = all element is filled {  
+                    if (signal[0]=='i'){
+                        pc.printf("end");
+                    }
+                    else if (signal[0]=='a')
+                    {
+                        pc.printf("aend");
+                    }
+                    sendCounter=0;
+                    wrote=false;
+                    }
                 }
-                else if (signal[0]=='a')
-                {
-                    pc.printf("aend");
-                }
-                wrote=false;
-                }
+            
         }
         else{
             if(pc.readable() ) {
-                //pc.printf("can read now");
                 led=!led;
                 pc.scanf("%1s", signal);
                 wrote=true;