IsMyServerOnline Arduino Yún

IsMyServerOnline
IsMyServerOnline Arduino Yún
#include 

#define greenLedPin 2
#define redLedPin 3

const char command[] = "curl http://minlinuxserver.com/ExecCommandServletUptime";
const char lookForText[] = "up";

void setup() {
  Bridge.begin(); 	/* Initialize the Bridge */
  Serial.begin(9600); 	/* Initialize the Serial for debugging */

  pinMode(greenLedPin, OUTPUT); // green
  pinMode(redLedPin, OUTPUT); // red
  
  lights(false);
}

void loop() {
  String output = "";
  Process p;

  p.runShellCommand(command);

  while(p.running());  /* do nothing until the process finishes, so you get the whole output */

  //Serial.print("output:"); /* Some serial debugging */
  while (p.available() > 0) {
    char c = p.read();
    output.concat(c);
  }
  
  output.trim();
  if(output.indexOf(lookForText) > 0){
    lights(true);  
  }else{
    lights(false);  
  }

  Serial.println(output);

  p.flush();

  delay(5000);  // wait 5 seconds before you do it again
}

void lights(boolean on){
  if(on){
    digitalWrite(redLedPin, LOW);
    digitalWrite(greenLedPin, HIGH);
  }else{
    digitalWrite(redLedPin, HIGH);
    digitalWrite(greenLedPin, LOW);
  }
}

Publicerat av

Peter Lindblom

Mer info om mig finns på sidan http://plweb.se/om-peter-lindblom/

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *