Problems setting servo position via HTTP Post

I’m a terrible programmer but i’m looking to put a server in a specific position bij doing a HTTP POST.

When compling my code i get this error: servo_over_the_internet.cpp:16:22: error: invalid user-defined conversion from ‘String’ to ‘int’ [-fpermissive]

This is the code on the Core.

Servo myservo;  
int pos = 0;    

void setup() 
{ 
    Spark.function("pos",setPosition);
    myservo.attach(D0);  
} 


void loop() 
{ 
}

int setPosition(String pos) {
    myservo.write(pos);              
}

And i’m going to use this url to post the position:
https://api.particle.io/v1/devices/53ff6cxxxxxxxxxxx42467?access_token=c7xxxxxxxxxxxxxxxxxxx21&pos=90

If anyone can give a little help… Thanks.

With kind regards,
Just Vervaart

Just,

your servo expects an int here:

int setPosition(String pos) {
    myservo.write(pos);              
}

try this

int setPosition(String pos) 
{
  int servoPosition = pos.toInt();  // converts your String to an int
  myservo.write(servoPosition);   
  return servoPosition;  // need to return a value...           
}
1 Like

There is was a little typo.
It should be int servoPosition = pos.toInt(); (capital I in toint)

1 Like