I have tried everything I can think of but cannot get the compiler to accept converting char to int. I tried first reading byte buffer but couldn't find a way to convert that. So, I tried read a single character in at a time and adding it to a string because then I thought I could iterate the string and pull the data that I need. The clock that I am using accepts int for each position of hour and minute (num1,num2,num3,num4). So I am sending a request to a server which replys with "04,51,40" + crlf. I need to take the 0 and put in num1, 4 in num2, 5 in num3, 1 in num4. Any help would be appreciated.
If you are using Strings, then the below type operation should work.
if (readString.length() >0) {
Serial.println(readString);
int n = readString.toInt();
Serial.println(n);
myservo.writeMicroseconds(n);
//myservo.write(n);
readString="";
}
XY Problem.
it looks like you have something like a webclient.
What hardware are you using?
What do you want to achieve?
in the end I guess you want something like
strtok and atoi
if you really always get
"04,51,40" + crlf.
and really want to have it in single digits
than even a simple char array buffer will work
num1=buffer[0]-32;
num2=buffer[1]-32;
num3=buffer[3]-32;
etc
could work.
I have an Arduino Mega with ethernet shield connected to 4 digit 7 segment display with rtc module.
I press button on Arduino and it makes a websocket to server sending "Time" request.
Server responds with datetime string in the following format "2020,02,01,09,28,58"+crlf.
I then was trying to parse through the string but was not realizing that the substring function on Arduino does (from, to) as opposed to (from, length).
So, I got everything functioning except simple things I am stumbling over.
Current road block is I want to "Serial.println(rtc.now()" before and after setting time...BUT
Compiler gives me error "no matching function for call to 'DateTime::toString()".
I also tried making DateTime dtNow variable, assigning rtc.now() to it and then trying "Serial.println(dtNow.toString())" but I think the compiler doesn't accept the toString method.