Hello community!
First of all thank you all for this incredible "manual" each of you have contributed which has help me ease into the Arduino world and really do the things i need fast and reliable!
I have encountered a nitpick issue with my program which i would love your input.
I am sending json (POSTcall function) through the Arduino's API to a website and the bellow function is used to get the input from the URL:
void process(BridgeClient client) {
// read the command
String command = client.readStringUntil('\r');
// is this API of valid string?
if ((command == "possition") || (command == "up") || (command == "down")) {
if ((command == "possition") && (possition == 1)) {
POSTcall(client, "Up");
return;
}
else if ((command == "possition") && (possition == 2)) {
POSTcall(client, "Down");
return;
}
else if ((command == "up") && (possition == 2) ) {
buttonUPpressed(client);
return;
}
else if ((command == "down") && (possition == 1)) {
buttonDOWNpressed(client);
return;
}
else {
switch (possition) {
case 1:
POSTcall(client, "The keys are allready Up!");
break;
case 2:
POSTcall(client, "The Keys are allready Down!");
break;
}
}
return;
}
else {
POSTcall(client, "An error occurred");
return;
}
delay(1);
return;
}
POSTcall Function:
void POSTcall (BridgeClient client, const char* state) {
client.println("Status: 200");
client.println("Access-Control-Allow-Headers: *");
client.println("Access-Control-Allow-Origin: http://tsekadoros.ddns.net");
client.println("Access-Control-Allow-Methods: POST");
client.println("Content-type: application/json; charset=utf-8");
client.println(); //mandatory blank line
client.print("{\"Position\": \"");
client.print(state);
client.print("\"}");
}
Everything works as expected on Mozilla and Chrome on 2 PCs that ive tried but when i sent the "Up" or "Down" api from my Galaxy s8+ chrome browser i get the "The keys are allready Up!" or "The keys are allready Down!" values depending if it was the down or up button.
Is there maybe an explanation to this? Maybe i missed a "return" somewhere in the function?
Thank you!