Text Message Doorlock

From Matt Bilsky

Revision as of 19:20, 8 December 2011 by Matt Bilsky (talk | contribs) (Created page with "== Code == === Arduino === ***********************************: Arduino meets Processing via Wifi: Arduino Client side sketch: /************************...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Code

=== Arduino ===

/*************************************/ /* Arduino meets Processing via Wifi */ /* Arduino Client side sketch */ /*************************************/

/* Switch and LED settings */

  1. define start_sw 4
  2. define led 13

/* DD-WRT user-ID,password,serial-speed settings */

  1. define USER_ID "root"
  2. define PASSWD "admin"
  3. define SERIAL_SPEED 9600

/* Processing-Server IP and TCP-Port settings */

  1. define SERVER "192.168.10.87"
  2. define PORT "5555"

void setup() {

 pinMode(led, OUTPUT);
 pinMode(start_sw,INPUT);
 Serial.begin(SERIAL_SPEED); 
 /* waiting until start_sw was pushed */
 while(digitalRead(start_sw)==HIGH){
   digitalWrite(led,HIGH);
   delay(100);
   digitalWrite(led,LOW);
   delay(100);
 }
 while(digitalRead(start_sw)==LOW);
 /* login and connect */
 //login();    //login DD-WRT
 connection();  //connect Processing-Server
 digitalWrite(led,HIGH);

}

void loop() {

 int x = analogRead(0); // read voltage of potentiometer
 if(Serial.available()>0){
   Serial.read(); // read out data from Processing-Server
   Serial.println(x,DEC); //send data to Processing-Server
 }
 /* if start_sw is pushed */
 if(digitalRead(start_sw)==LOW){
//     disconnect();  //disconnect from Processing-Server
     //logoff();  // logoff from DD-WRT
     /* LED blink eternally */
     while(true){
        digitalWrite(led,LOW);
        delay(1000);
        digitalWrite(led,HIGH);
        delay(1000);
     }         
 }

}

/* login to DD-WRT */ void login() {

 Serial.print("\n"); 
 allflush(); // flushing serial read buffer 
 Serial.println(USER_ID); 
 delay(500);
 Serial.println(PASSWD);
 allflush();

}

/* logoff from DD-WRT */ void logoff() {

 Serial.print("\x03"); //CTRL+C
 delay(100);
 Serial.println("exit");
 allflush(); 

}

/* connect to Processing-Server */ void connection() {

 Serial.print("\x03\n\n"); //CRTL+C,LF,LF
 allflush(); 
 /* telnet to Processing-Server */
 Serial.print("telnet ");
 Serial.print(SERVER);
 Serial.print(" ");
 Serial.println(PORT);
 allflush();
 /* telnet change "character mode".  cf: DD-WRT telnet command */
 Serial.print("\x03"); //CTRL+C
 Serial.print("c");
 allflush();
 Serial.print("\n");
 allflush();
 /* send first data to Processing-Server. first data is 0 */
 Serial.println("0");  //send 0

}

/* disconnect form Processing-Server */ void disconnect() {

 digitalWrite(led,HIGH);
 /* exit telnet.  cf:DD-WRT telnet command */
 Serial.print("\x1d");//CTRL+]
 delay(100);
 Serial.print("e");
 delay(100);
 allflush();

}

/* flushing serial read buffer */ void allflush() {

 delay(100); 
 while(Serial.available()>0) Serial.flush();

}

/* End of Client side sketch */

/* Copyright by Kimio Kosaka 2008.08.20 */