I need help to parse a GET into a INT

hello all, first post, I am struggling...

I have searched and am struggling to get the GET string into a INT. The GET gets a form type "time" and returns "12:34"

I need the string into a variable in the format "1234"

Current code is throwing the error:
exit status 1
incompatible types in assignment of 'void*' to 'char [5]'

int starttime;

server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
    String inputMessage;
    String inputParam;
    char timeinput[5]

      else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
      inputMessage.toCharArray(timeinput,5);
      timeinput = memmove(&timeinput[2], &timeinput[3], strlen(timeinput) - 2);
      starttime = atoi(timeinput);
      Serial.println(starttime);
    }

incompatible types in assignment of ‘void*’ to ‘char [5]’

And that refers to which line ?char timeinput[5]Shouldn’t there be a ‘;’ there ?inputMessage.toCharArray(timeinput,5);If ‘inputMessage’ is “12:34” then the CharArray should be 6 characters, 5 + 1 for the terminator. Of course you could do the parsing just using the ‘String’ class, using substring() and toInt()

And shouldn’t there be a closing “}“, and presumably an earlier “if (......) {“, before...

 else if (

I have muddled through and found a solution that is not graceful, but works. if anyone has a suggestion on how to make this more elegant it would be appreciated :slight_smile:

else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
//      inputParam = memmove(&inputParam[2], &inputParam[3], strlen(inputParam) - 2);
      int timeinput1 = (inputMessage.charAt(0) - '0')*1000;
      int timeinput2 = (inputMessage.charAt(1) - '0')*100;
      int timeinput3 = (inputMessage.charAt(3) - '0')*10;
      int timeinput4 = inputMessage.charAt(4) - '0';
      int starttime = timeinput1+timeinput2+timeinput3+timeinput4;

it’s not obvious (to me) what you’re trying to read from an http request

are you trying to read the time from “If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT”?

GET /home.html HTTP/1.1
Host: developer.mozilla.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://developer.mozilla.org/testpage.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT
If-None-Match: “c561c68d0ba92bbeb8b0fff2a9199f722e3a621a”
Cache-Control: max-age=0

It's a parameter embedded in the GET URL:
http://......./.....?PARAM_INPUT_2=12:34

This code is running on the server and decoding the incoming URL to get the parameters.

The name of the parameter is whatever PARAM_INPUT_2 is presumably #defined as, but the OP has neglected to share with us.

char buff[6];
inputMessage.toCharArray(buff, sizeof(buff));
uint8_t hrs = atoi(strtok(buff, ":"));
uint8_t mins = atoi(strtok(NULL, ":"));

I'm sure you can do this kind of tokenised splitting with the String class as well. I'm just pre-programmed to NOT use String. I accept on the ESP8226 it's not a problem.

Do what you like with the separate hrs and mins parts once you have parsed them.
Combine them into a bastardised unholy child of the devil with result = hrs * 100 + mins if you want.

Edit: The French tried decimal time once. It didn't work out so well for them. About as well as requesting the prime meridian should run through Paris....

consider (using standard C string functions)

output

GET /home.html?PARAM_INPUT_2=12:34 HTTP/1.1
Host: developer.mozilla.org
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://developer.mozilla.org/testpage.html
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT
If-None-Match: "c561c68d0ba92bbeb8b0fff2a9199f722e3a621a"
Cache-Control: max-age=0


PARAM_INPUT_2=12:34
12:34
  hr 12, min 34
char s [] = "GET /home.html?PARAM_INPUT_2=12:34 HTTP/1.1\n"
 "Host: developer.mozilla.org\n"
 "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0\n"
 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n"
 "Accept-Language: en-US,en;q=0.5\n"
 "Accept-Encoding: gzip, deflate, br\n"
 "Referer: https://developer.mozilla.org/testpage.html\n"
 "Connection: keep-alive\n"
 "Upgrade-Insecure-Requests: 1\n"
 "If-Modified-Since: Mon, 18 Jul 2016 02:36:04 GMT\n"
 "If-None-Match: \"c561c68d0ba92bbeb8b0fff2a9199f722e3a621a\"\n"
 "Cache-Control: max-age=0\n\n";

void setup()
{
    Serial.begin (115200);
    Serial.println (s);

    char *t = strtok(strstr(s, "PARAM_INPUT"), " ");
    Serial.println (t);

    strtok (t, "=");
    char *q = strtok (NULL, "=");
    Serial.println (q);

    int  hr, min;
    sscanf (q, "%d:%d", &hr, &min);

    char u [20];
    sprintf (u, "  hr %d, min %d", hr, min);
    Serial.println (u);
}

void loop() { }

I’m sure you can do this kind of tokenised splitting with the String class as well. I’m just pre-programmed to NOT use String. I accept on the ESP8226 it’s not a problem.

In fact there was (and probably still is) an issue with strtok() in the ESP core (which tends to show up whenever people use / are referred to use, Robin’s Serial Input Basics) so if parsing it like this is the plan, i would suggest using the ‘String’ class, it has almost no issues on an ESP, and none if used locally (rather than globally)

that is not graceful, but works. if anyone has a suggestion on how to make this more elegant

the issue is in the ‘:’ half way, and i am also a little curious what happens when the hours are less than 10.
i would do something like this to prevent any unwanted result from that event like this:

inputMessage = request->getParam(PARAM_INPUT_2)->value();
uint8_t i = 0;
uint16_t starttime = 0;
while (i < inputMesaage.length()) {
  char c = inputMessage.charAt(i);
  if ((c >= '0') && (c <= '9')) {
    starttime = (starttime * 10) + (c - '0');
    }
  i++;
  }