Hello,
I am needing help understanding the HTTP API. I am trying to develop Bash scripts to control MRL in order to help with remote debugging and system management, but I am running into problems regarding the API. Using this command:
curl -H "Content-Type: application/json" -X POST -d "{\"service\":$1,\"method\":$2,\"data\":\"$3\"}" http://localhost:$MRL_PORT/api/messages
MRL simply holds the connection but does not execute anything. I tried using the example JSON with this command:
curl -H "Content-Type: application/json" -X POST -d '{"msgID":1431792202686,"timeStamp":1431792202686,"name":"runtime","sender":"webgui","sendingMethod":"","historyList":[],"method":"start","data":["arduino","Arduino"]}'
which also did nothing but wait.
I also tried using wget to use the services URI API:
wget http://localhost:8888/services/runtime/createAndStart/python/Python
which also produced a wait.
I might just be overlooking something simple, but I can't find what I'm doing wrong so I would like some help.
Thanks!
Hello and Welcome
Hello and Welcome AutonomicPerfectionist,
If your looking for simple request response endpoint, don't use "messages".
The messages endpoint gets upgraded to a websocket - its for clients who want a persistent connection.
If you want request / response api use "services"
Your above url is incorrect :
It's missing /api .. and I prefere curl over wget
So it would be :
curl http://localhost:8888/api/service/runtime/start/python/Python
More documentation exist here - http://myrobotlab.org/content/myrobotlab-api
BTW - the messages "does" something, it only appears to wait because its opened a websocket connection, and is asynchronous. You'd need to subscribe to a service, and send a message which would send another message back. But I'd save that to after you've mastered the synchronous api.
Cheers,
GroG
Thanks!
Thanks GroG! I knew I was overlooking something simple! Another problem I noticed was that I had a zombie connected to the default port, so I wasn't even sending anything to the real MRL! Thanks again!
One more question
Okay, I've got basic commands working and I can now call methods remotely using my script. The only problem is that when trying to execute Python coffee remotely using the exec method, spaces aren't decoded correctly before being sent to gson. Ice tried encoding with both %20 and +, both of which returned with a malformed json exception. Again, maybe I'm just overlooking something, but I feel this might just be a simple preprocessing bug.
Thanks again!
"Python coffee" <- eh
"Python coffee" <- eh ?
Coffee script Python script wah ?
Dunno what your trying to do, so its a little hard to give good advice.
First response, put your script in a file and tell the Python service to execute the script with
http://localhost:8888/api/services/execFile/{filename}
Woops, my phone's autocorrect
Woops, my phone's autocorrect changed code to coffee... Anyways, I'm trying to run Python code remotely with bash so that I can run small code fragments remotely and the OS can trigger events, such as reminders, system notifications, etc. That way, InMoov can just say the notification rather than the user having to look at the screen. I was planning on using Python exec directly, but execFile will also do the trick. Thanks!