cannot convert 'const String' to 'byte {aka unsigned char}' in assignment

Hi everyone, total newbie here working on a sketch for a esp8266. After many hours of trying to figure this out I figured I’d ask for help. So I’m passing some parameters through a server to esp8266 via html input then save to eeprom hopefully.

Now I’m stuck at turning that parameter Stirng “erver.arg(i);” into a byte? My sever input parameters are always a number between 0-100 so they should be a single byte anyways right? example

192.168.4.1/save3?rpm3=78

How can I convert my 0-100 html input perimeter whatever is in “erver.arg(i);” to a byte so that I can save “erver.arg(i);” to eeprom? This doesn’t work:
qrpm3 = server.arg(i); I get error: cannot convert ‘const String’ to ‘byte {aka unsigned char}’ in assignment

This does:

String qrpm3 = server.arg(i);

But its a string, I just need a single byte so I can save it straight to eeprom with:

        EEPROM.write(3,server.arg(i));
        EEPROM.commit();

Part of the code:

  if (server.args() > 0 ) {
    for ( byte i = 0; i < server.args(); i++ ) {
      if (server.argName(i) == "rpm3") {
        // do something here with value from server.arg(i);

        String qrpm3 = server.arg(i);
        Serial.println(server.arg(i));
        Serial.println(qrpm3);
        //EEPROM.write(3,server.arg(i));
        //EEPROM.commit();
      }
    }
  }

Hi, try the toInt() string object function

byte myByte;

myByte = qrpm3.toInt();

converts the string into integer and then simply store into a byte data type variable.

Here is the syntax

https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/

I’m struggling to see how this is a “general electronics” question - you could ask a moderator to move the topic to the programming section.

I actually wrote my own converter since toInt() returns 0 for an incorrect input and then i cannot test for that (if 0 is a valid input as a value)

myele:

qrpm3 = server.arg(i);

I get error: cannot convert 'const String' to 'byte {aka unsigned char}' in assignment

I think you want:

qrpm3 = server.arg(i).toInt();

Nikosant03:
Hi, try the toInt() string object function

byte myByte;

myByte = qrpm3.toInt();




converts the string into integer and then simply store into a byte data type variable.

This worked awesome thanks so much :slight_smile: