v2 for lunchbox

Dependencies:   HTTPClient PWM_Tone_Library PinDetect_KL25Z Queue cc3000_hostdriver_mbedsocket mbed

Fork of kragl by The Kragl

Files at this revision

API Documentation at this revision

Comitter:
inezraharjo
Date:
Wed Dec 02 18:32:02 2015 +0000
Parent:
2:f47fb78ba7b0
Child:
4:e1f2918c9770
Commit message:
update version 12/1;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Nov 30 01:39:27 2015 +0000
+++ b/main.cpp	Wed Dec 02 18:32:02 2015 +0000
@@ -32,7 +32,7 @@
 // - SPI CLK  => (pin D13)
 // plus wifi network SSID, password, security level and smart-configuration flag.
 mbed_cc3000::cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13),
-                         "CalVisitor", "", NONE, false);
+                         "Fire_2441", "", NONE, false);
 
 // create an http instance
 HTTPClient http;
@@ -116,7 +116,7 @@
     code[passwordcounter] = i;
     passwordcounter++;
     if (codeEntered==false){
-    correctLED = 1;
+        correctLED = 1;
     }
     //buttonQ.Put(&i);
 }
@@ -188,7 +188,8 @@
 
 void reedOpen( void )
 {
-    pc.printf("Reed Open\n");
+    pc.printf("Reed Open\r\n");
+    pc.printf("boxOpenLegal: %d\r\n", boxOpenLegal);
     reedIsOpen = 1;
 }
 
@@ -204,8 +205,9 @@
             warningLED = 0;
             wait(0.15);
         }
+        Buzzer = 0;
     }
-    Buzzer = 0;
+    pc.printf("boxOpenLegal: %d\r\n", boxOpenLegal);
 }
 
 void reedOpenHeld( void )
@@ -268,7 +270,7 @@
     //int i;
     int init = 0; // init wifi done
     start_t = clock();
-
+    int num = 0;                        
     reedIsOpen = (reed == 1);
     while (1) {
         pc.printf("reed value:%d\r\n",reedIsOpen);
@@ -312,7 +314,7 @@
             }
         }
         current_t = clock();
-        total_t = (double)(current_t - start_t) / CLOCKS_PER_SEC;
+        total_t = (double)(current_t - start_t) / (CLOCKS_PER_SEC);
         //pc.printf("total_t: %d\r\n", total_t);
         if ((total_t%1)==0){ //every t seconds
             pc.printf("SENDING TO URL\n");
@@ -328,8 +330,16 @@
                                   strlen(str));
                         
                         char* s = strtok(str, "\n");
+                        pc.printf("code string: %s\r\n",s);
+                        if (true){
+                            for (int c=1; c<5; c++){
+                                char test[] = {s[c]};
+                                num = atoi(test);
+                                password[c-1] = num;    
+                            }
+                        }   
                         char test[] = {s[5]};
-                        int num = atoi(test);
+                        num = atoi(test);
                         pc.printf("Result last digit: %d\r\n", num);
                         if (num==1){
                             boxOpenLegal = true;
@@ -362,15 +372,19 @@
                     ret = http.get(url, str, 128);
                 }
             }
-        pc.printf("waiting to check...\r\n");
-        if (reedIsOpen && codeEntered) {
+        //pc.printf("waiting to check...\r\n");
+        //pc.printf("boxOpenLegal: %d\r\n", boxOpenLegal);
+        //pc.printf("reedIsOpen: %d\r\n", reedIsOpen);
+        if (!boxOpenLegal && reedIsOpen && codeEntered) {
             pc.printf("LEGAL OPENING");
             boxOpenLegal = true;
             codeEntered = false;
             Buzzer = 0;
-            wait(0.3);
+            
         } else if (reedIsOpen && !boxOpenLegal) {
             // turn on alarm;
+            pc.printf("boxOpenLegal: %d\r\n", boxOpenLegal);
+            pc.printf("reedIsOpen: %d\r\n", reedIsOpen);
             pc.printf("ALARM TIME\r\n");
             Buzzer = 1;
             
@@ -417,7 +431,7 @@
                     ret = http.get(url, str, 128);
                 }
             }
-            wait(0.3);
+            //wait(0.3);
         } else if (!reedIsOpen && boxOpenLegal) {
             Buzzer = 0;
             boxOpenLegal = false;
@@ -442,11 +456,11 @@
                     tries--;
                 }
             }
-            wait(0.3);
+            //wait(0.3);
         }
         if (!codeEntered && passwordcounter==sizeof(code)/4) {
             codeEntered = true;
-            
+            /*
             sprintf(url, "http://www.charlesding.net/kragl/pincode_read.php?");
             int ret2 = http.get(url, str, 128);
             
@@ -481,19 +495,18 @@
                 tries--;
                 ret2 = http.get(url, str, 128);
             }
-            wait(0.3);   
-            
+            //wait(0.3);   
+            */
             for (int j=0; j<sizeof(code)/4; j++) {
                 if (code[j]!=password[j]) {
                     codeEntered = false;
                 }
             }
-            char test[] = {s[5]};
-            int num = atoi(test);
             if (num==1){
                 codeEntered = true;
             }
             if (codeEntered==true){
+                Buzzer = 0;
                 warningLED = 0;
                 for (int j=0; j<8; j++){
                     correctLED =1;
@@ -524,7 +537,7 @@
             
             int ret = http.get(url, str, 128);
             pc.printf("Trying to Request %s\r\n", url);
-            tries = 50;
+            int tries = 50;
             while (tries > 0) {
                 ret = http.get(url, str, 128);
                 if (!ret) {