No rest for the wicked
Haha
I really appreciate the help by the way.
Just wanna learn it. I looked at the Phobot coding but could not figure how to control over the web using the APi
Dave
No rest for the wicked
Haha
I really appreciate the help by the way.
Just wanna learn it. I looked at the Phobot coding but could not figure how to control over the web using the APi
Dave
Whatās the problem you canāt get over?
Have you looked at the WebControl.cpp
sample?
Been trying, just confusing me
Would this bit here be my variables in the APi url?
void setup() {
Spark.function("control", control);
Spark.function("setmotors", setMotors);
Spark.variable("volts", &volts, DOUBLE);
Spark.variable("distance", &distance, DOUBLE);
So I would use something like, forwards/backwards/stop via the APi
Dave
The two functions setMotors
and control
are the ones you want to look at.
If you look at the code, youāll see what command strings you need to send into the functions to have the device do what you want.
ok.
Bear with me to see if Iām actually going the right way or the wrong way.
Old code (running but not controlled by the web)
#include "PhoBot/PhoBot.h"
PhoBot p = PhoBot(12.0, 12.0);
void setup() {
}
void loop() {
p.setMotors("M4-B-200");
delay(25000);
p.setMotors("M4-S");
delay(2000);
p.setMotors("M4-f-200");
delay(500);
p.setMotors("M4-S");
delay(5000);
}
New Code
char motorCommand[12];
uint motorNr;
int speed;
int control(String command) {
return p.control(command);
}
int setMotors(String command) {
return p.setMotors(command);
}
if (speed==0)
sprintf(motorCommand, "M%u-S", motorNr);
else
sprintf(motorCommand, "M%u-%s-%d", motorNr, (speed > 0 ? "F" : "B"), abs(speed));
p.setMotors(motorCommand);
I assume the p.setMotors("M4-B-200");
will be the same but where does it go, or is that called via the API?
Dave
Uhm nope.
My code would just illustrate how to build a control string from two numeric values, but the sample I refered wonāt need that.
The sample expects you to already send in a well formed command string - however you will have to do that on your remote side.
There is even a curl
sample call in the first line of the sample comment, but wrapping your brain round all that is something we canāt do for you.
Commands are of the format: Motor-Direction-duty
Motor is one of: M1, M2, M3, M4
Direction is one of: F, B, S (forward, back, stop) - reverse has no effect on M1 and M2
Duty is percentage 0 to 100 and controls the motor speed.
M1 and M2 do not have PWM so duty is 0 or 1
To read the battery voltage use:
https://api.spark.io/v1/devices/3b001b000447343232363230/volts?access_token=172f237a43e4ed0ee25ddbb1507ebd5061bb19c5
To read the rangfinder distance in cm use:
https://api.spark.io/v1/devices/3b001b000447343232363230/distance?access_token=172f237a43e4ed0ee25ddbb1507ebd5061bb19c5
*/
#include āPhoBot/PhoBot.hā
//double volts = 0.0;
//double distance = 0.0;
PhoBot p; // = PhoBot();
//HC_SR04 rangefinder = HC_SR04(p.trigPin, p.echoPin);
int control(String command) {
return p.control(command);
}
int setMotors(String command) {
return p.setMotors(command);
}
void setup() {
Spark.function(ācontrolā, control);
Spark.function(āsetmotorsā, setMotors);
//Spark.variable(āvoltsā, &volts, DOUBLE);
//Spark.variable(ādistanceā, &distance, DOUBLE);
}
void loop() {
//volts = p.batteryVolts();
//distance = rangefinder.getDistanceCM();
//delay(100);
}
</details>
i think i might be useless
I think i understand that now.
It makes more sense seeing it like the second way⦠Iām sorry for my density lol
the API string i guess would be
https://api.spark.io/v1/devices/DEVICEID/setMotors?access_token=TOKEN
So if i want to use the following
M4-F-100
Looking at the example code
curl https://api.particle.io/v1/devices/0123456789abcdef/brew \
-d access_token=123412341234 \
-d "args=coffee"
How would i then add this to the CURL / API call?
Am i right in thinking i would have an argument. (args?) after the access token with the M4-F-100 within it?
Hoping thats right or the right track.
Yet again, i canāt thank you enough
Dave
Ok shoot me
Itās at the top I think
ok so Iām using
https://api.spark.io/v1/devices/deviceid/setMotors?access_token=token&?params=M4-F-100
but just getting
{
"error": "Timed out."
}
so i must be getting close
Also using SSH getting the same error
{
"ok": false,
"error": "Timed out."
}
How about this?
The way how you do it depends on your remote app (as said earlier too)
So you'd need to disclose your inrentions on this to us too.
its to trigger a device to release a biscuit for my cats⦠lol
have tried
curl https://api.spark.io/v1/devices/DEVICE ID/setmotors -d access_token=TOKEN -d params=M4-F-100
But thats getting timed out error
Im also trying just over the web as the API url
https://api.spark.io/v1/devices/DEVICE ID/setmotors?access_token=TOKEN&control=M4-F-100
Try this page to test your firmware
http://suda.github.io/particle-web-interface/
Ok calling
M4-F-100
will start the motor moving via that interface
so it must be something Iām calling wrong
is there any any way to see exactly what that Suda web interface page is polling to the Particle?
So i can see my variables
As its working using that like and setting parameters there, but not in the URL or Api call
Dave
Getting somewhere
in SSH using CURL
curl https://api.spark.io/v1/devices/DEVICEID/setmotors -d access_token=TOKEN -d params=M4-F-100
this works.
so how to i call the params as M4-F-100 within the URL from the API call?
Dave
Got is working
Good tho hear
Just one point.
If you find a solution please do post it along with your success report for others to benefit from it too.
(or what the problem was that held you back before)
figured out about the GET and POST requests via the API
so have to use a function to be able to get it to run in Javascript
function ONEFEED()
{
$.post("https://api.spark.io/v1/devices/DEVICE/setmotors?access_token=token",
{
args:"M4-B-200"
});
}
using
<button type="button" onclick="ONETREAT()">One Treat</button>
Now i just need to figure it out so it only does one revolution of the motor rather than continually spinning