product-iots/modules/distribution/src/sketches/arduino/PollServer.ino

56 lines
1.3 KiB
Arduino
Raw Normal View History

2015-06-16 19:29:26 +00:00
boolean readControls() {
// String responseMsg;
pollClient.fastrprint(F("GET "));
pollClient.fastrprint(SERVICE_EPOINT);
pollClient.fastrprint(F("readcontrols/"));
pollClient.fastrprint(DEVICE_ID);
pollClient.fastrprint(F("?owner="));
pollClient.fastrprint(DEVICE_OWNER);
pollClient.fastrprint(F(" HTTP/1.1")); pollClient.fastrprint(F("\n"));
pollClient.fastrprint(host.c_str()); pollClient.fastrprint(F("\n"));
pollClient.println();
2015-06-09 14:51:48 +00:00
2015-06-16 19:29:26 +00:00
delay(1000);
2015-06-09 14:51:48 +00:00
2015-06-16 19:29:26 +00:00
while (pollClient.available()) {
char response = pollClient.read();
responseMsg += response;
}
2015-06-09 14:51:48 +00:00
2015-06-16 19:29:26 +00:00
int index = responseMsg.lastIndexOf(":");
int newLine = responseMsg.lastIndexOf("\n");
subStrn = responseMsg.substring(index + 1);
responseMsg = responseMsg.substring(newLine + 1, index);
2015-06-09 14:51:48 +00:00
if(DEBUG) {
Serial.print(responseMsg);
Serial.println();
Serial.println("-------------------------------");
}
2015-06-16 19:29:26 +00:00
if (subStrn.equals("ON")) {
Serial.println("ITS ON");
//digitalWrite(13, HIGH);
digitalWrite(6, HIGH);
} else if (subStrn.equals("OFF")){
Serial.println("ITS OFF");
//digitalWrite(13, LOW);
digitalWrite(6, LOW);
}
if (responseMsg.equals("BULB")) {
return false;
}
2015-06-09 14:51:48 +00:00
2015-06-16 19:29:26 +00:00
return true;
2015-06-09 14:51:48 +00:00
}