Jacob Smith / Mbed 2 deprecated IoT_V3

Dependencies:   4DGL-uLCD-SE IoTsecuritySys PinDetect mbed-rtos mbed

Fork of IoT by Tal Landes

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <mbed.h>
00002 #include <string>
00003 #include <iostream>
00004 #include "rtos.h"
00005 #include <mpr121.h>
00006 #include <stdlib.h>
00007 #include "PinDetect.h"
00008 #include "uLCD_4DGL.h"
00009 #include "SongPlayer.h"
00010 #include "Speaker.h"
00011 #include "EthernetInterface.h"
00012 /* CODE_LENGTH needs to be double the amount of numbers you
00013       want in your authenticator/passcode because of the way interrupt.fall(&fallInterrupt)
00014       works. It is called twice every time an interrupt is detected.
00015       The extra numbers in the array will just be filled with zeros and ignored in checking 
00016       code sequences, so they will not matter either way */
00017       /* i.e, you want a code with 7 numbers, CODE_LENGTH needs to be 14 */
00018 #define CODE_LENGTH 8
00019 
00020 DigitalOut led1(LED1);
00021 DigitalOut led2(LED2);
00022 DigitalOut led3(LED3);
00023 DigitalOut led4(LED4);
00024 
00025 DigitalOut doorlock(p21);
00026 
00027 
00028 //uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
00029 uLCD_4DGL uLCD(p28, p27, p29); 
00030 
00031 // Create the interrupt receiver object on pin 26
00032 InterruptIn interrupt(p30);
00033 
00034 // Setup the i2c bus on pins 9 and 10
00035 I2C i2c(p9, p10);
00036 
00037 // Setup the Mpr121:
00038 // constructor(i2c object, i2c address of the mpr121)
00039 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
00040 
00041 // pc serial communication for testing
00042 Serial pc(USBTX, USBRX);
00043 
00044 //Set up IR sensor 
00045 AnalogIn IrSensor(p20);
00046 
00047 //Shiftbright
00048 DigitalOut latch(p15);
00049 DigitalOut enable(p16);
00050 //AnalogOut DACout(p18);
00051 //Cycles through different colors on RGB LED
00052 SPI spi(p11, p12, p13);
00053 
00054 
00055 SongPlayer mySpeaker(p26);
00056 Speaker NotePlayer(p26);
00057 
00058 // ethernet setup    
00059 EthernetInterface eth;
00060 
00061 //Lock timeout 
00062 Timeout flipper;
00063 
00064 // ***** GLOBALS ***** //
00065 // Timer is to seed rand
00066 string ID = "1";
00067 volatile int NumTry = 0; 
00068 Timer t1;
00069 Timer t2;
00070 // code counter is the next position in inputCode array
00071 volatile int codeCounter;
00072 // inputCode array is the sequence of numbers the user will enter
00073 volatile int inputCode[CODE_LENGTH];
00074 //volatile bool code_enabled;
00075 volatile float IrVoltage = 0.0;
00076 int FindStrLocation(string sntsc, string word, string ptr);
00077 enum Statetype { Armed = 0, IR_sensed = 1, Second_Step = 2, Cleared = 3, Alarm_ON = 4};
00078 Statetype state = Armed;
00079 char charCode[5];
00080 
00081 float note[18]= {1568.0,1396.9};
00082 float duration[18]= {0.48,0.24};
00083 
00084 Mutex LCD_Access; 
00085 Mutex PC_Access;
00086 Mutex Eth_Lock;
00087 Semaphore Consul_Access(5);
00088 
00089 void Shiftbright_thread(void const *args);
00090 void LCD_Code_Enter_Thread(void const *args);
00091 void uLCD_thread(void const *args);
00092 void RGB_LED(int red, int green, int blue);
00093 void Ethernet_thread(void const *args);
00094 bool Ethernet_massage_Send(string args);
00095 void Activate_Lock();
00096 void init_LCD();
00097 // Key hit/release interrupt routine
00098 void fallInterrupt() {
00099     int key_code=0;
00100     int i=0;
00101     int value=mpr121.read(0x00);
00102     value +=mpr121.read(0x01)<<8;
00103     // LED demo mod
00104     i=0;
00105     // puts key number out to LEDs for demo
00106     for (i=0; i<12; i++) {
00107     if (((value>>i)&0x01)==1) key_code=i+1;
00108     }
00109     led4=key_code & 0x01;
00110     led3=(key_code>>1) & 0x01;
00111     led2=(key_code>>2) & 0x01;
00112     led1=(key_code>>3) & 0x01;
00113   
00114     // save the keypress to inputCode array
00115     switch (state) {
00116         case Armed:
00117         break;
00118         case IR_sensed:
00119         case Second_Step:
00120             if(codeCounter < CODE_LENGTH){
00121             // ignore odd numbers
00122             if(codeCounter % 2 != 0){
00123                 inputCode[codeCounter] = 0;
00124             }
00125             // only save the even numbers (see lines 6-10)
00126             else{
00127                 inputCode[codeCounter] = key_code - 1;
00128                 //pc.printf("codeCounter: %d  --  code:  %d\n\r", codeCounter, key_code - 1);
00129             }      
00130             codeCounter++;
00131         }
00132         break;
00133         case Alarm_ON:
00134             if(key_code == 12 ){
00135                 state = Armed;
00136                 //Ethernet_massage_Send("UpdateStatus");
00137             }
00138         break; 
00139         case Cleared:
00140             if(key_code == 12 ){
00141                 state = Armed;
00142                 //Ethernet_massage_Send("UpdateStatus");
00143                 }
00144             else if (key_code == 11 ){
00145                 doorlock = 1;  
00146                 flipper.attach(&Activate_Lock, 3.0);
00147                 }
00148         break;
00149         }
00150     
00151 }
00152 
00153 // generate randomized code
00154 void generate_random_code(int (&codeArray)[CODE_LENGTH]){
00155     //int i = 0;
00156     // only care about the even numbers (see lines 6-10)
00157     //PC_Access.lock();
00158     //pc.printf("NEW CODE: ");
00159     //PC_Access.unlock();
00160     for(int i = 0; i < CODE_LENGTH; i+=2){
00161         srand(t1.read_us());
00162         codeArray[i] = (rand() % 9)+1; //nake code only 1-9
00163         PC_Access.lock();
00164         pc.printf("%d,  ", codeArray[i]);
00165         PC_Access.unlock();
00166     }
00167 
00168     snprintf(charCode, sizeof(charCode), "%i%i%i%i ", codeArray[0], codeArray[2], codeArray[4], codeArray[6]);
00169     //PC_Access.lock();
00170     //pc.printf("\n\r");
00171     //pc.printf("%s\n\r",charCode,codeArray[6]);
00172     //PC_Access.unlock();
00173     //Ethernet_massage_Send("TextCode");
00174 }
00175 
00176 // check if the code entered is the correct code
00177 bool check_code_sequence(int (&codeArray)[CODE_LENGTH]){
00178     //int i = 0;
00179     int j = 0;
00180     // only care about the even numbers (see lines 6-10)
00181 
00182     if (NumTry < 3) {
00183         NumTry++;
00184     for(int i = 0; i < CODE_LENGTH; i+=2){
00185         
00186         if(inputCode[i] == codeArray[i]){
00187         j++; // count the number of right numbers
00188         }
00189          
00190     }
00191     if(j == CODE_LENGTH/2){
00192         /*for(int i = 0; i < CODE_LENGTH; i+=2){
00193             //inputCode[i] =0;
00194         }*/
00195         return(true);
00196     }
00197     else if  (Ethernet_massage_Send("GetTempCode")){
00198         /*for(int i = 0; i < CODE_LENGTH; i+=2){
00199              //inputCode[i] =0;
00200         }*/
00201         //pc.printf("return true");
00202         return(true);
00203     }
00204     else {
00205         /*for(int i = 0; i < CODE_LENGTH; i+=2){
00206             //inputCode[i] =0;
00207         }*/
00208        return(false);
00209     }
00210     }
00211     else {
00212         //PC_Access.lock();
00213         //pc.printf("3 times ");
00214         //PC_Access.unlock();
00215         state = Alarm_ON;
00216         //Ethernet_massage_Send("UpdateStatus");
00217         return(false);
00218     }
00219 }
00220  
00221 int main() {
00222     interrupt.fall(&fallInterrupt);
00223     interrupt.mode(PullUp);
00224     pc.baud(921600);
00225     
00226     
00227     // authenticator is the randomly generated sequence of numbers by the machine
00228     // the user has to match this sequence to gain access, used for phase 2
00229     int authenticator[CODE_LENGTH];
00230     // passcode is the user's personal passcode, used for phase 1
00231     int passcode[CODE_LENGTH] = {1,0,2,0,3,0,4,0};//,4,0,5,0,6,0};
00232     codeCounter = 0;
00233     bool pass = false;
00234     
00235     // these 2 variables tell the machine when to generate a new random authentication code
00236     int new_code_timer = 0;
00237     int new_code_counter = 0;
00238     // this tells the state machine with phase of authentication we are in
00239     //code_enabled = false;
00240     
00241     for(int i = 0; i < CODE_LENGTH; i++){
00242       authenticator[i] = 0;
00243       inputCode[i] = 0;
00244     }
00245     
00246     // go ahead and start the timer so that when a random code is generated,
00247     // the seed will always be random, unlike the predecessor version
00248     t1.start();
00249     init_LCD();
00250     
00251     Timer t;
00252     t.start(); 
00253     //start threads:
00254     PC_Access.lock();
00255     pc.printf("\n\n\nSetting up Ethernet\n\r");
00256     PC_Access.unlock();
00257     Thread Ethernetthread(Ethernet_thread);
00258     wait(5); //Give the Ethernet connection some time to set up 
00259     Thread Shiftbright(Shiftbright_thread);
00260     Thread LCDthread(uLCD_thread);
00261     //Thread LCD_CodeEnterThread(LCD_Code_Enter_Thread);
00262     
00263     // while loop constantly checks if the entered code sequence is right or wrong,
00264     // given that the correct amount of numbers were entered
00265     PC_Access.lock();
00266     pc.printf("Ready\n\r");
00267     PC_Access.unlock();
00268     doorlock = 0; // make sure locked 
00269     while (1){
00270         switch(state){
00271             case Armed:
00272                 IrVoltage=IrSensor.read();
00273                 if (IrVoltage <= 0.1) { //if value just nois reset timer
00274                     t.reset();
00275                     state = Armed;
00276                 }
00277                 if (t.read() >= 3) { //wait 5 seconds to make sure that sense someone 
00278                     state = IR_sensed; 
00279                     //Ethernet_massage_Send("UpdateStatus");
00280                 }                  
00281                 break;
00282             case Cleared:
00283                 break;
00284             case IR_sensed:
00285                 if(codeCounter >= CODE_LENGTH){
00286                     pass = check_code_sequence(passcode);
00287                     if(pass == true){
00288                         //PC_Access.lock();
00289                         //pc.printf("SENDING AUTHENTICATION CODE...\n\r");
00290                         //PC_Access.unlock();
00291                         generate_random_code(authenticator);
00292                         t1.stop(); // reset the time
00293                         t1.reset(); // so that it is an even
00294                         t1.start(); // 30 seconds before 1st new code is generated
00295                         codeCounter = 0;
00296                         //code_enabled = true;
00297                         state = Second_Step;
00298                         //Ethernet_massage_Send("UpdateStatus");
00299                         Ethernet_massage_Send("TextCode");
00300                     }
00301                     else{
00302                         //PC_Access.lock();
00303                         //pc.printf("WRONG passcode\n\r");
00304                         //PC_Access.unlock();
00305                         codeCounter = 0;
00306                     }
00307                 }
00308                 break;
00309             case Second_Step:
00310                 if(codeCounter >= CODE_LENGTH){
00311                     NumTry = 0;
00312                     pass = check_code_sequence(authenticator);
00313                     if(pass == true){
00314                         //PC_Access.lock();
00315                         //pc.printf("ACCESS GRANTED\n\r");
00316                         //PC_Access.unlock();
00317 
00318                         //wait(5);
00319                         
00320                         //pc.printf("Resetting....\n\r");
00321                         //pc.printf("\n\n\rPlease Enter Your Personal Security Code\n\r");
00322                         codeCounter = 0;
00323                         //code_enabled = false;
00324                         state = Cleared;
00325                         //Ethernet_massage_Send("TextCode");
00326                         //Ethernet_massage_Send("UpdateStatus");
00327                         doorlock = 1;  
00328                         flipper.attach(&Activate_Lock, 3.0);
00329                     }
00330                     else{
00331                         //PC_Access.lock();
00332                         //pc.printf("ACCESS DENIED\n\r");
00333                         //PC_Access.unlock();
00334                         codeCounter = 0;
00335                     }
00336                 }
00337                 // this code generates a new authentication code every 30 seconds (30000 ms)
00338                 new_code_timer = (int)(t1.read_ms()/300000000);
00339                 if(new_code_timer > new_code_counter){
00340                     new_code_counter++;
00341                     generate_random_code(authenticator);
00342                     codeCounter = 0;
00343                 }
00344                 break;
00345         }
00346         // reset the timer when the number gets too high, should last about 35 minutes
00347         //  We do this because int can only hold a number up to 2^32 - 1, preventing errors
00348         if(t1.read_us() > 2147400000){
00349             t1.stop();
00350             t1.reset();
00351             new_code_timer = 0;
00352             new_code_counter = 0;
00353             t1.start();
00354         }
00355     }
00356 }
00357 
00358 
00359 void Shiftbright_thread(void const *args){
00360     spi.format(16,0);
00361     spi.frequency(500000);
00362     enable=0;
00363     latch=0;
00364     
00365     while(1) {
00366     switch (state) {
00367         case Armed:
00368             
00369             for (int i = 0; i <= 50; i++) {
00370                 RGB_LED( i, 0, 0);
00371                 Thread::wait(10);
00372             }
00373             for (int i = 50; i >= 0; i--) {
00374                 RGB_LED( i, 0, 0);
00375                 Thread::wait(10);
00376             }
00377         break;
00378         case IR_sensed:
00379             RGB_LED( 100, 0, 0);
00380             Thread::wait(500);
00381             RGB_LED( 0, 0, 0);
00382         break;
00383         case Alarm_ON:
00384             mySpeaker.PlaySong(note,duration);
00385         //Thread::wait(2000); 
00386             for (int i = 0; i <= 100; i++) {
00387                 RGB_LED( i, i/2, 0);
00388                 Thread::wait(10);
00389             }
00390             for (int i = 100; i >= 0; i--) {
00391                 RGB_LED( i, i/3, 0);
00392                 Thread::wait(10);
00393             }
00394         break; 
00395         case Cleared:
00396             RGB_LED( 0, 100, 0);
00397             break;
00398         }
00399         Thread::wait(1000);
00400    }
00401 }
00402 
00403 void RGB_LED(int red, int green, int blue) {
00404     
00405     unsigned int low_color=0;
00406     unsigned int high_color=0;
00407     high_color=(blue<<4)|((red&0x3C0)>>6);
00408     low_color=(((red&0x3F)<<10)|(green));
00409     spi.write(high_color);
00410     spi.write(low_color);
00411     latch=1;
00412     latch=0;
00413 }
00414 
00415 void init_LCD() {
00416     uLCD.baudrate(3000000);
00417     uLCD.background_color(BLACK);
00418     
00419 }
00420     
00421 
00422 void uLCD_thread(void const *args) {
00423     int Change = 99; 
00424     string temp;
00425     temp = "abc";
00426     while(1) {
00427         
00428         if (Change != state) {
00429             Change = state;
00430             switch (state) {
00431                 case Armed:
00432                     LCD_Access.lock();
00433                     uLCD.cls();
00434                     uLCD.color(WHITE);
00435                     uLCD.text_width(2);
00436                     uLCD.text_height(2);
00437                     uLCD.printf("  ARMED\r\n");
00438                     uLCD.text_width(1); 
00439                     uLCD.text_height(1);
00440                    
00441                     if (eth.getIPAddress() == "\0") {
00442                         uLCD.printf("\n\n No Internet connection");
00443                         }
00444                     else {
00445                         uLCD.printf("\n\nConnected to the  Internet\n");
00446                         uLCD.printf("IP Address: \n%s ", eth.getIPAddress());
00447                         }
00448                     LCD_Access.unlock();
00449                 break;
00450                 case IR_sensed:
00451                     LCD_Access.lock();
00452                     uLCD.cls();
00453                     uLCD.printf("\nSensor triggred \n"); 
00454                     uLCD.printf("\n  Enter the code ...");
00455                     LCD_Access.unlock();
00456                     for (int i=30; i>=0; --i) {
00457                         if (state == IR_sensed) {
00458                             LCD_Access.lock();
00459                             uLCD.text_width(4);
00460                             uLCD.text_height(4);
00461                             //LCD_Access.unlock();
00462                             //LCD_Access.lock();
00463                             uLCD.color(RED);
00464                             uLCD.locate(1,2);
00465                             uLCD.printf("%2D",i);                    
00466                             LCD_Access.unlock();                    
00467                             Thread::wait(1000);
00468                             }
00469                         }
00470                         if (state == IR_sensed) {
00471                             LCD_Access.lock();
00472                             uLCD.cls();
00473                             LCD_Access.unlock();
00474                             state = Alarm_ON;
00475                             //Ethernet_massage_Send("UpdateStatus");
00476                             Ethernet_massage_Send("TextAlarm");
00477                             }
00478 
00479                 break;
00480                 case Second_Step: 
00481                     LCD_Access.lock();
00482                     uLCD.cls();
00483                     uLCD.color(BLUE);
00484                     uLCD.printf("\nPleas enter code from text massage \n");
00485                     LCD_Access.unlock();
00486                     break;
00487                 case Alarm_ON:
00488                     LCD_Access.lock();
00489                     uLCD.cls();
00490                     uLCD.color(RED);
00491                     uLCD.text_width(1.5); //4X size text
00492                     uLCD.text_height(1.5);
00493                     uLCD.printf("\nALARM IS ON \nText message sent \n"); 
00494                     LCD_Access.unlock();
00495                     break;
00496                 case Cleared: 
00497                     LCD_Access.lock();
00498                     uLCD.cls();
00499                     uLCD.color(GREEN);
00500                     uLCD.printf("\n\nAccess Granted. \n\n"); 
00501                     LCD_Access.unlock();  
00502                 break; 
00503                 }
00504             }
00505             Thread::wait(100);
00506         }
00507 }
00508 
00509 void LCD_Code_Enter_Thread(void const *args) {
00510     int LineHight = 120;
00511     int LineWidth = 10; 
00512     int SpaceWidth = 5;
00513     int MidPoint = 127/2;
00514     while(1) {
00515         switch (state) {
00516                 case Armed:
00517                 break;
00518                 case IR_sensed:
00519                 case Cleared:
00520                 case Second_Step:
00521                   
00522                     Thread::wait(500);
00523                     while((state == IR_sensed)||(state == Cleared)||(state == Second_Step)) {
00524                         LCD_Access.lock();
00525                         //dusplay four lines 
00526                         uLCD.line(MidPoint-2*(LineWidth+SpaceWidth), LineHight, MidPoint- 2*SpaceWidth-LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
00527                         uLCD.line(MidPoint-LineWidth-SpaceWidth, LineHight, MidPoint-SpaceWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
00528                         uLCD.line(MidPoint+SpaceWidth, LineHight, MidPoint+SpaceWidth+LineWidth, LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
00529                         uLCD.line(MidPoint+2*SpaceWidth+LineWidth, LineHight, MidPoint+2*(SpaceWidth+LineWidth), LineHight, WHITE); //line( int x1, int y1, int x2, int y2, int color)
00530                         uLCD.locate(5,14);
00531                         uLCD.text_width(1); //4X size text
00532                         uLCD.text_height(1);
00533                         
00534                         // add black numbers
00535                         /*if (inputCode[0] == inputCode[2] ==inputCode[4] ==inputCode[6] == 0) {                        
00536                             uLCD.color(BLACK);                        
00537                         }
00538                         else {*/
00539                         //uLCD.color(WHITE);
00540                         uLCD.printf("%d %d  %d %d",inputCode[0],inputCode[2],inputCode[4],inputCode[6]);
00541                         //}
00542                         LCD_Access.unlock();
00543                     }
00544                 
00545                 case Alarm_ON:
00546                 break;
00547                 }
00548         }
00549 }
00550 
00551 void Ethernet_thread(void const *args) { 
00552  
00553     char buffer[300];
00554     int tempstatus = state;
00555     int ret,found;
00556     eth.init(); //Use DHCP
00557     eth.connect();
00558 //pc.printf("IP Address is: %s\n\r", eth.getIPAddress());
00559     while (1) {
00560         Thread::wait(1000);
00561         if (tempstatus !=state) {
00562             Ethernet_massage_Send("UpdateStatus");
00563             Thread::wait(1500);
00564             tempstatus = state;
00565             } 
00566         //t2.start();                 
00567         TCPSocketConnection sock;
00568         sock.connect("dreamphysix.com", 80);
00569         char http_cmd[100] = "GET http://www.dreamphysix.com/alarm/readstatus.php?mbedID=0 HTTP/1.0\n\n";
00570     //PC_Access.lock();
00571     //pc.printf("%s",http_cmd);
00572     //PC_Access.unlock();
00573     Eth_Lock.lock();
00574     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00575     Eth_Lock.unlock();
00576                         while (true) {
00577                         Eth_Lock.lock();
00578                         ret = sock.receive(buffer, sizeof(buffer)-1);
00579                         Eth_Lock.unlock();
00580                         if (ret <= 0)
00581                             break;
00582                         buffer[ret] = '\0';
00583                         Consul_Access.wait();
00584                         //PC_Access.lock();
00585                         //pc.printf("Received %d chars from server:\n%s\n", ret, buffer);
00586                         //PC_Access.unlock();
00587                         Consul_Access.release();
00588                         }
00589                     sock.close();
00590                     //t2.stop();
00591     string str(buffer);
00592     found = str.find("Status=");
00593     //pc.printf("location: %d string: %s" , found, str);              
00594     //pc.printf("\n\rhttp_cmd: %c\n\r",buffer[found+7]);
00595     //pc.printf("\n\state: %i\n\r",state);
00596     int dummy = (buffer[found+7])-48;
00597     state = (Statetype)dummy;
00598     //state = (Statetype)buffer[found+7];
00599     PC_Access.lock();
00600     pc.printf("\nstate: %i\n\r",dummy);
00601     PC_Access.unlock();
00602     //Thread::wait(3000); 
00603     }
00604 }
00605 
00606 bool Ethernet_massage_Send(string buff) { 
00607 
00608     char buffer[300];
00609     int ret;
00610     //pc.printf("IP Address is: %s\n\r", eth.getIPAddress());
00611 
00612                     TCPSocketConnection sock;
00613                     sock.connect("dreamphysix.com", 80);
00614                     
00615                     if (buff == "TextCode") { 
00616                             char http_cmd[100] = "GET http://www.dreamphysix.com/alarm/sendcode.php?authcode=0e9cae34a0&randomcode=";
00617                             strcat(http_cmd, charCode);
00618                             strcat(http_cmd, " HTTP/1.0\n\n");
00619                             PC_Access.lock();
00620                             pc.printf("%s",http_cmd);
00621                             PC_Access.unlock();
00622                             Eth_Lock.lock();
00623                             sock.send_all(http_cmd, sizeof(http_cmd)-1);
00624                             Eth_Lock.unlock();
00625                     }
00626                     else if (buff == "TextAlarm") {
00627                             char http_cmd[] = "GET http://dreamphysix.com/alarm/sendalert.php?authcode=0e9cae34a0 HTTP/1.0\n\n";
00628                             Eth_Lock.lock();
00629                             sock.send_all(http_cmd, sizeof(http_cmd)-1);
00630                             Eth_Lock.unlock();
00631                             PC_Access.lock();
00632                             pc.printf("%s",http_cmd);
00633                             PC_Access.unlock();
00634                    }
00635                     else if (buff == "GetTempCode") {
00636                             snprintf(charCode, sizeof(charCode), "%i%i%i%i ", inputCode[0], inputCode[2], inputCode[4], inputCode[6]);
00637                             char http_cmd[100] = "GET http://www.dreamphysix.com/alarm/validatecode.php?code=";
00638                             strcat(http_cmd, charCode);
00639                             strcat(http_cmd, " HTTP/1.0\n\n");
00640                             PC_Access.lock();
00641                             pc.printf("%s",http_cmd);
00642                             PC_Access.unlock();
00643                             Eth_Lock.lock();
00644                             sock.send_all(http_cmd, sizeof(http_cmd)-1);
00645                             Eth_Lock.unlock();
00646                     }
00647                     else if (buff == "UpdateStatus") {
00648                             char tempStatus[2];
00649                             snprintf(tempStatus, sizeof(tempStatus), "%i", state);
00650                             char http_cmd[100] = "GET http://www.dreamphysix.com/alarm/updatestatus.php?mbedID=1";
00651                             //strcat(http_cmd, ID);
00652                             strcat(http_cmd, "&status=");
00653                             strcat(http_cmd, tempStatus);
00654                             strcat(http_cmd, " HTTP/1.0\n\n");
00655                             PC_Access.lock();
00656                             pc.printf("%s",http_cmd);
00657                             PC_Access.unlock();
00658                             Eth_Lock.lock();
00659                             sock.send_all(http_cmd, sizeof(http_cmd)-1);
00660                             Eth_Lock.unlock();
00661                     }
00662                     else {
00663                         
00664                     }
00665 
00666 
00667                     while (true) {
00668                         Eth_Lock.lock();
00669                         ret = sock.receive(buffer, sizeof(buffer)-1);
00670                         Eth_Lock.unlock();
00671                         if (ret <= 0)
00672                             break;
00673                         buffer[ret] = '\0';
00674                         Consul_Access.wait();
00675                         //PC_Access.lock();
00676                        //pc.printf("Received %d chars from server:\n%s\n", ret, buffer);
00677                         //PC_Access.unlock();
00678                         Consul_Access.release();
00679                         }
00680                     sock.close();
00681                     
00682                     snprintf(buffer, ret, "%c",buffer);
00683                     //pc.printf("buffer: %s", buffer);
00684                     if (strstr(buffer,"True") != NULL) {
00685                          pc.printf("true fron eth check");
00686                          return true;
00687                     }
00688                     else if (strstr(buffer,"False") != NULL) {
00689                          pc.printf("false fron eth check");
00690                          return false;
00691                     }
00692                     else {
00693                         pc.printf("default ");
00694                         return true;
00695                     }
00696 }
00697 
00698 void Activate_Lock(){
00699     doorlock =! doorlock;
00700 }
00701 
00702