I been playing with the oak robot kit.
Now receiving commands from a web form
I use more or less the robot example code and added a few particle functions to send pseudo serial commands :
int SpeedValue = 1023;
void setup() {
botInit();
Particle.function("Movement",Movement);
Particle.publish("Oak Report", "Start");
}
int Movement(String command)
{
char buf[10];
command.toCharArray(buf, 10) ;
int firstChar = (int) buf[0];
switch (firstChar)
{
case 'f': //forward
botForward( SpeedValue);
return 1;
break;
case 'r': //reverse
botReverse( SpeedValue);
return 2;
break;
case 'd': //droite
botRight( SpeedValue);
return 3;
break;
case 'g': //gauche
botLeft( SpeedValue);
return 4;
break;
case 'D'://DROITE
botHardRight( SpeedValue);
return 5;
break;
case 'G': //GAUCHE
botHardLeft( SpeedValue);
return 6;
break;
case 's':
botStop();
return 7;
break;
}
return -1;
}
Also found a nice form on the particle docs to send POST commands directly in my browser:
<!-- Robot control -->
<!DOCTYPE>
<html>
<body>
<center>
<br>
<form action="https://api.particle.io/v1/devices/[DEVICE ID HERE]/Movement?access_token=[access token here]" method="POST">
Tell your Robot what ro do!<br>
<br>
<input type="radio" name="args" value="f">forward
<br>
<input type="radio" name="args" value="G">Hard Left
<input type="radio" name="args" value="g">Left
<input type="radio" name="args" value="d">Right
<input type="radio" name="args" value="D">Hard Right
<br>
<input type="radio" name="args" value="r">reverse
<br>
<br>
<input type="radio" name="args" value="s">Stop motor
<br>
<input type="submit" value="Do it!">
</form>
</center>
</body>
</html>
I have 0 experience in HTML, right now to make a bit efficient I'll get rid of the buttons and just put buttons, but I was wondering how I can make my browser not go to the particle report page (output of the function) ?
I plan to have some proximity sensor at some point and some encoders (well they are there but for now the data they output is not been used (got some serious bouncing going on).