RVR sphero sdk - REST API

Hi, on one of the videos I have seen, someone shows a swagger page for the sdk Rest API served from the RPi.
I can’t seem to find any details about this anywhere.

The example python code does have REST versions of the code.

Can anyone shed some light on this?

Thanks

1 Like

I had a hard time finding it too. What I did was look in the video and copied the URL. Not at home but if you can’t find it that way let me know!

1 Like

So dont have to set anything up, it just runs automatically?
I’ll give it another go.
Thanks
BTW, I’m a Reed as well, must be related.

1 Like

You do have to run the SDK for it to be served and function. Search this forum for swagger and you will probably find a post of mine saying the URL too, sorry I can’t search atm I’m at work.

And neat!

Edit: quick warning, a bunch of the swagger endpoints are inaccurate at least on the Nodejs sdk. Check the example code in the SDK for the actual endpoints for stuff like sensor streaming.

1 Like

For the nodejs sdk, swagger is located at {ip-address}:2010/api-docs/. Not sure about the python version.

1 Like

Sorry, when you say, run the sdk, not sure what you mean.
Can’t find anything in the sdk files.

Do you know if there are any instructions on the web, didnt find anything.

1 Like

I can only speak to the Nodejs SDK. Essentially when you run the sdk for nodejs, it hosts a server which in turn serves Swagger. I have very little experience with Python, I’m a typescript/c# dev, so I can’t speak with any authority, but if you can execute a .py file maybe try the init file found here and report back?

1 Like

Have you ran through this tutorial? If you want Swagger you MIGHT need to use Nodejs as that for sure has it. Let me know and I can help guide you through it. I’d be up to chat on Discord if you want to instant message about it!

EDIT: I’ve been bored and did some more research. It really looks like if you want swagger you may have to go with Nodejs. Again, happy to chat about it! This does have RESTful in its name, so there is hope.

1 Like

Thanks Eric, I’ll have a look at the node stuff.
Its funny that the python docs and getting started dont mention installing / running the node version as well but do include python examples that use the rest api.
I tried running them, replacing the IP with the Pi’s IP but no luck, the rest api is def not running on my Pi.

1 Like

I have followed the steps at https://www.instructables.com/id/Install-Nodejs-and-Npm-on-Raspberry-Pi/ and have node and npm running on the pi.

I have cloned https://github.com/sphero-inc/sphero-sdk-raspberrypi-nodejs.

I’m not very familar with node so not sure what the next steps are and not finding anything online.

I’m a C# dev as well but I’m finding this very confusing.

I just joined discord but not sure how to use it, assume I need ot add you as a friend?

1 Like

Add Cyborg#4051 on Discord under friends -> add friends if you want to chat. Totally understand the confusion I had a mess of a first few days with RVR as well.

To get you up and running, here’s what you’ve gotta do after you clone the repo. In the Sphero sdk directory (which I renamed sphero to save myself typing in the whole dang thing every time I want to cd into it)

  1. run sudo npm install to install the required packages. It might error out let me know if it does
  2. run sudo npm run build to transpile typescript to javascript and build it into the dist folder
  3. run sudo npm run start to start the server

Once thats running, you should have Swagger at the url I mentioned. Typing the steps from memory so lemme know if it doesn’t work.

edit: also maybe do a search for swagger.json to see if it exists in the python repo?

1 Like

Spot on, thanks for clearing that up. Looks like the swagger / rest api is running now.

I’m surprised that the swagger page does not give more info about the expected values.
Have to check the documentation.

Thanks again.

1 Like

Not a problem! Expected values would be nice yes. For targetID its always either 1 or 2, and if it fails you’ll know it. Check the example code for actual endpoints, swagger is out of date on certain endpoints like sensorStreaming.

1 Like

Yes, just found that /sensorControl/stopStreaming does not seem to work.

1 Like

LED control endpoints do not work either lol. Swagger.json needs updated. Actual endpoint is sensorControl/startSensorStreaming for your code in the future.

1 Like

StartSensorStreaming seemed to work, stop does not.

1 Like

Actual endpoint for stopping stream is sensorControl/stopSensorStreaming, when I was using my raspberry pi zero w I had to use sensor/clearStreamingService/2 to truly clear out the sensor streaming but according to my notes that borked the service and made it so I couldn’t restart it… so dont do that workaround

1 Like

The python rest versions work now, once the rest api is started using node.
Maybe the documentation should be updated to mention that.

Thanks again for your help.

1 Like

My pleasure, hope you make some great stuff!

1 Like