Hi. i am trying to convert a string to an integer, but i keep getting this error.
This is my code:
int led=D7;
String oatmeal;
String sugar;
String hours;
String minutes;
int sep[5];
int o;
void setup() {
pinMode(led, OUTPUT); // set the D7 LED as output
Spark.function("dispenser",blinkfunc); // a POST request for "blink" will reference blinkfunc, defined below
SPARK_WLAN_Loop();
Serial.begin(9600);
Serial.println("WLAN_LOOP");
}
// call the below function when the POST request matches it
int blinkfunc(String command) {
int index = 0;
Serial.println("raw: " + command);
Serial.println(command.length());
for(int i = 0; i < command.length(); i++){
if(command.charAt(i) == ',') {
sep[index] = i;
index++;
}
oatmeal = command.substring(sep[0]+1, sep[1]);
sugar = command.substring(sep[1]+1, sep[2]);
hours = command.substring(sep[2]+1, sep[3]);
minutes = command.substring(sep[3]+1, sep[4]);
o = oatmeal.toInt();
}
Serial.println("Oatmeal: " + oatmeal);
Serial.println("sugar: " + sugar);
Serial.println("hours: " + hours);
Serial.println("minutes: " + minutes);
Serial.println("converted: " + o);
return 1; // return 1 to show that this worked.
}
void loop() {
//not doing anything here
}
the POST i send to the function looks like this:
,1,1,8,30,
and the console would throw me this:
raw: ,1,1,8,30,
10
Oatmeal: 1
sugar: 1
hours: 8
minutes: 30
onverted:
Now. what i wanted, is the
onverted:
to look like this:
converted: 1
but the c keeps dissappearing, and the actual “o” value is nonexistent.
So how would i go about converting the “oatmeal” string to int?
Thanks alot in advance