2fb: use POST for non-idempotent API endpoints
This commit is contained in:
parent
b06c799e21
commit
741e0ee5b3
1 changed files with 8 additions and 33 deletions
|
@ -288,17 +288,17 @@ void readServerStatus(int mode) {
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerServerReq(String s, int mode) {
|
void TriggerServerReq(String req, int mode) {
|
||||||
// attempt to connect, and wait a millisecond:
|
// attempt to connect, and wait a millisecond:
|
||||||
if (debug) {
|
if (debug) {
|
||||||
Serial.println("connecting to server... Status req");
|
Serial.println("connecting to server... Status req");
|
||||||
}
|
}
|
||||||
if (client.connect(SERVER_DOMAIN, 80)) {
|
if (client.connect(SERVER_DOMAIN, 80)) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
Serial.println("making HTTP request...");
|
Serial.println("making HTTP request: " + req);
|
||||||
}
|
}
|
||||||
// make HTTP GET request to server:
|
// make HTTP request to server:
|
||||||
client.println("GET " + s + " HTTP/1.1");
|
client.println(req + " HTTP/1.1");
|
||||||
client.println("HOST: " SERVER_DOMAIN);
|
client.println("HOST: " SERVER_DOMAIN);
|
||||||
client.println("Connection: close");
|
client.println("Connection: close");
|
||||||
client.println();
|
client.println();
|
||||||
|
@ -312,7 +312,7 @@ void TriggerServerReq(String s, int mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestState() {
|
void RequestState() {
|
||||||
TriggerServerReq("/api/status-s.php", 0);
|
TriggerServerReq("GET /api/status-s.php", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status LED pins
|
// Status LED pins
|
||||||
|
@ -348,46 +348,21 @@ void setup() {
|
||||||
RequestState();
|
RequestState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TriggerServerUpdate(boolean stat) {
|
|
||||||
// attempt to connect, and wait a millisecond:
|
|
||||||
if (debug) {
|
|
||||||
Serial.println("connecting to server... Update Req");
|
|
||||||
}
|
|
||||||
if (client.connect(SERVER_DOMAIN, 80)) {
|
|
||||||
if (debug) {
|
|
||||||
Serial.println("making HTTP request...");
|
|
||||||
}
|
|
||||||
// make HTTP GET request to server:
|
|
||||||
String s = (stat ? "true" : "false");
|
|
||||||
client.println("GET /api/update.php?open=" + s + "&apikey=" UPDATE_API_KEY +
|
|
||||||
" HTTP/1.1");
|
|
||||||
client.println("HOST: " SERVER_DOMAIN);
|
|
||||||
client.println("Connection: close");
|
|
||||||
client.println();
|
|
||||||
readServerStatus(0);
|
|
||||||
} else {
|
|
||||||
if (debug) {
|
|
||||||
Serial.println("Not connected...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// note the time of this connect attempt:
|
|
||||||
}
|
|
||||||
|
|
||||||
void readButtons() {
|
void readButtons() {
|
||||||
if ((digitalRead(topen) == LOW) && (hsopen != 1)) {
|
if ((digitalRead(topen) == LOW) && (hsopen != 1)) {
|
||||||
// startEthernet();
|
// startEthernet();
|
||||||
setRoom(2);
|
setRoom(2);
|
||||||
TriggerServerUpdate(true);
|
TriggerServerReq("POST /api/update.php?open=true&apikey=" UPDATE_API_KEY, 0);
|
||||||
}
|
}
|
||||||
if ((digitalRead(tclose) == LOW) && (hsopen != 0)) {
|
if ((digitalRead(tclose) == LOW) && (hsopen != 0)) {
|
||||||
// startEthernet();
|
// startEthernet();
|
||||||
setRoom(2);
|
setRoom(2);
|
||||||
TriggerServerUpdate(false);
|
TriggerServerReq("POST /api/update.php?open=false&apikey=" UPDATE_API_KEY, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestPing() {
|
void RequestPing() {
|
||||||
TriggerServerReq("/api/ping-get.php?apikey=" PING_GET_API_KEY, 1);
|
TriggerServerReq("POST /api/ping-get.php?apikey=" PING_GET_API_KEY, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launchUpdate() {
|
void launchUpdate() {
|
||||||
|
|
Reference in a new issue