diff --git a/server/commande_telephone.ino b/server/commande_telephone.ino index 2820cde..590eea3 100644 --- a/server/commande_telephone.ino +++ b/server/commande_telephone.ino @@ -87,25 +87,34 @@ void serverConfig() { String command; float value; - if (request->hasParam("command")) { - command = request->getParam("command")->value(); - if (request->hasParam("value")){ - value = request->getParam("value")->value().toFloat(); - } - else{ - value = 0; - } - requestCheck(command,value); - } - else { - command = "Not the good command"; - } + + // Parse request params and update command and value + parseRequestParams(request, command, value); + Serial.print(command); Serial.print(": "); Serial.println(value); request->send(200, "text/plain", command); }); } +void parseRequestParams(AsyncWebServerRequest &request, String &command, int &value) +{ + // Stop here with error message if wrong command + if (!request->hasParam("command")) + { + command = "Not the good command"; + return; + } + + // Update command from params + command = request->getParam("command")->value(); + + // Update value from params and use "0" as default + value = request->hasParam("value") ? request->getParam("value")->value().toFloat() : 0; + + requestCheck(command, value); +} + // Fonction pour convertir une longueur en cm vers un nombre de pas moteur. int convertLengthToSteps(float length) {