Talk:OpenDuino

From syn2cat - HackerSpace.lu
Revision as of 18:13, 17 September 2009 by Bartek (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

temporary storage for source code of arduino part:

{{{

  1. include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 99 }; byte gateway[] = { 192 ,168 ,1 ,254 }; byte subnet[] = { 255, 255, 255, 0 }; boolean open = false;

//byte server_ip[] = {74, 125, 127, 100}; //google byte server_ip[] = { 80, 90, 47, 170 }; //hackerspace.lu //byte server_ip[] = { 192, 168, 1, 65 };

char request[300] = "GET /OpenDuino.php?status=0 HTTP/1.0"; //char request[300] = "GET /index.html HTTP/1.0";

unsigned long time = 0; unsigned long oldtime = 0;

unsigned long trigger_oldtime = 0;

//Server server(1337);

void setup() {

 Ethernet.begin(mac, ip, gateway, subnet);
 //server.begin();
 Serial.begin(9600);
 // connect once on launch
 dialup();
 
 oldtime = millis();

}

void dialup() {

 Client client(server_ip,80);  
 Serial.println("Connecting...");
 Serial.println(request);
 if( client.connect() ){
   client.println(request);
   client.println();
  } else {
    Serial.println("Connection failed.");
  } //*/
    
 if(client.available()) {
   char c = client.read();
   Serial.println(c);
 } //*/
 client.stop();

}


void loop() {

 time = millis();
 
 if(digitalRead(0) == 0) {
   if( time - trigger_oldtime > 1000 ) {
     trigger_oldtime = time;
     Serial.println("Changing state.");
     open = !open;
     request[26] = (int)open+48;
     dialup();
   }
 }
 
 
 if( open ) {
   digitalWrite(7,HIGH);
   digitalWrite(5,LOW);
 } else {
   digitalWrite(7,LOW);
   digitalWrite(5,HIGH);
 }
 
 if( time-oldtime > 300000 ) {
     oldtime = time;
     dialup();
 }

} }}}

Personal tools
Namespaces

Variants
Views
Actions
Navigation
syn2cat
Hackerspace
Activities
Initiatives
Community
Tools
Tools