added functionality react to a Space Ping Event

This commit is contained in:
Romedius Weiss 2015-12-27 05:17:29 +01:00
parent 145345a035
commit 6bebb3dcda
2 changed files with 32 additions and 13 deletions

1
ITS_Open_direct_2fb/APIKey_template.h Executable file → Normal file
View file

@ -2,4 +2,5 @@
String thingtweetAPIKey = "myThingspeakKey"; String thingtweetAPIKey = "myThingspeakKey";
String serverAPIKey = "myserverAPIKey"; String serverAPIKey = "myserverAPIKey";
String pingAPIKey ="pingApiKey";

View file

@ -68,7 +68,7 @@ void setup()
delay(1000); delay(1000);
// Get current Status // Get current Status
TriggerServerReq(); RequestState();
} }
void loop() void loop()
@ -118,8 +118,10 @@ void startEthernet()
} }
setEth(1); setEth(1);
} }
Serial.println("DONE"); if(debug){
Serial.println(); Serial.println("DONE");
Serial.println();
}
delay(1000); delay(1000);
} }
@ -187,19 +189,21 @@ void setRoom(int statuss){
setLeds(); setLeds();
} }
void RequestState() {
TriggerServerReq("/status-s.php",0);
}
void TriggerServerReq() { void TriggerServerReq(String s, int mode) {
// attempt to connect, and wait a millisecond: // attempt to connect, and wait a millisecond:
if(debug){Serial.println("connecting to server... Status req");} if(debug){Serial.println("connecting to server... Status req");}
if (client.connect(serverName, 80)) { if (client.connect(serverName, 80)) {
if(debug){Serial.println("making HTTP request...");} if(debug){Serial.println("making HTTP request...");}
// make HTTP GET request to server: // make HTTP GET request to server:
client.println("GET /status-s.php HTTP/1.1"); client.println("GET "+ s +" HTTP/1.1");
client.println("HOST: it-syndikat.org"); client.println("HOST: it-syndikat.org");
client.println("Connection: close"); client.println("Connection: close");
client.println(); client.println();
readServerStatus(); readServerStatus(mode);
//readServerReturn();
}else{ }else{
if(debug){Serial.println("Not connected...");} if(debug){Serial.println("Not connected...");}
} }
@ -217,7 +221,7 @@ void TriggerServerUpdate(boolean stat) {
client.println("HOST: it-syndikat.org"); client.println("HOST: it-syndikat.org");
client.println("Connection: close"); client.println("Connection: close");
client.println(); client.println();
readServerStatus(); readServerStatus(0);
}else{ }else{
if(debug){Serial.println("Not connected...");} if(debug){Serial.println("Not connected...");}
} }
@ -225,7 +229,8 @@ void TriggerServerUpdate(boolean stat) {
} }
//reads out the status returned by the server and sets the LED's appropriately. //reads out the status returned by the server and sets the LED's appropriately.
int readServerStatus() { //the mode is defied by the intended call:
int readServerStatus(int mode) {
char lastsign='0'; char lastsign='0';
boolean readStatus = false; boolean readStatus = false;
while(client.connected()) { while(client.connected()) {
@ -248,18 +253,30 @@ int readServerStatus() {
} }
if (readStatus) { if (readStatus) {
// if you got a "<" character,
// you've reached the end of the tweet:
if(currentLine.startsWith("true", 0)){ if(currentLine.startsWith("true", 0)){
if(debug){Serial.println("");} if(debug){Serial.println("");}
setRoom(1); switch(mode){
case 0:
setRoom(1);
break;
case 1:
if(debug){Serial.println("Wink Wink");}
break;
}
// close the connection to the server: // close the connection to the server:
client.stop(); client.stop();
return 0; return 0;
} }
if(currentLine.startsWith("false", 0)){ if(currentLine.startsWith("false", 0)){
if(debug){Serial.println("");} if(debug){Serial.println("");}
setRoom(0); switch(mode){
case 0:
setRoom(0);
break;
case 1:
if(debug){Serial.println("No Wink");}
break;
}
// close the connection to the server: // close the connection to the server:
client.stop(); client.stop();
return 0; return 0;
@ -276,6 +293,7 @@ int readServerStatus() {
//This just reads the server return and logs it to the serial //This just reads the server return and logs it to the serial
// @deprecated
void readServerReturn() { void readServerReturn() {
//if(debug){Serial.println("readServerReturn ... ");} //if(debug){Serial.println("readServerReturn ... ");}
while(client.connected()) { while(client.connected()) {