Sphero SDK & the REST API

Hi folks,

So I have recently been keen to play with the RVR I bought many moons ago along with a new raspberry pi 4. I don’t know Python and was very excited to read this in the documentation:

“the asyncio version is it enables users to communicate with RVR using the REST API. This means you can control RVR over the web! We’ve included samples using both the serial port, and the REST API for your convenience.”

I have tried and failed to get the Nodejs SDK working. Does anyone have any advice on what I can do get the Python REST API working?

I dont think there is a Python REST API. Your best bet might be to try and get the Node.js SDK working. Got mine up and running after a couple of hours of troubleshooting. Given that they do advertise this for “hackers” I feel there was a bit too much of the “hacking” involved getting node.js set up.

Thanks for the response. Yes, I am getting g the feeling this is for hackers only and only if you know the languages Python or Nodejs. Both are excellent languages I am sure but I feel Sphero are missing a big trick here and could learn a lot from large software organisations in producing a solid, well documented API. With this developers could consume the API at a high level and do all sorts of wonderful things such as integrating with AI etc.
So far the only way I have managed to get it working with the Pi is to buy a version 3B+ and use the pre-configured image with Python.
If it had a decent API that could be consumed by .NET Core then the RVR would be amazing. Maybe it’s just me? I am now looking at creating a one based on someone else’s efforts but to be honest I don’t know the low level stuff and it’s a bit daunting. Perhaps I will find someone to help me with the low level stuff, I could knock up a C# .NET Core RESTful API and someone help me with the low level instruction bit. Any takers?

I agree with you.

I’m not that used to these kind of projects, so all of my thoughts come from other kinds of procjets. I do feel that I have spent way to much time looking around the sdk website trying to figure things out. The documentation that is found here: Sensor · Sphero Public SDK i dont feel is documented in any readable form.

I’m having problems of my own right now, since my unit wont respond to commands, but thats another story.

Even though there is the low level API you could design your own SDK around i dont feel like that is how they advertise the product. I came here for a high level API/SDK that i could use and incorporate with other high level APIs.

And from reading on this forum, there seems to be problems with some endpoints in the node.js REST API anyway. That thread was quite old (maybe a year?) but looking at the spheros github repo there hasn’t been any activity on the node.js SDK for over 13 months.

First glance this seemed like a something that would intrest me and get into some personal projects, outside of professonal life, but has been more of a headache trying to get things set up. Not that this is bad, but i dont feel this is close to what was advertised.

Totally agree. The codebase for Nodejs looks stale and I hear on the grapevine that it will no longer be supported because the developers have left the company. I sincerely hope the Nodejs gets updated and better documentation gets produced but I doubt it will happen.

So this is leaving one to learn Python and have all custom code on the Pi itself. With an externally accessible API the processing could be done on the cloud and the potential endless.

The RVR has enormous potential and is amazing achievement but clearly the take up has been hampered by not being as accessible through an API + good documentation. You supply these, and everyone can get hooked onto your product. To be fair, Sphero have a lot of products and perhaps their main market overall is aimed at customers who just use the proprietary scratch.

The fact that Nodejs is no longer supported is sad news.

Even tough the main market might be aimed at something else, this product was marketed in quite a specific way I would say. If I wanted to dig into low level APIs i could have gone with loads of other products, the main selling point for me was that there was an SDK and a fully functioning REST API. A simple installation guild for the Nodejs SDK would have been nice.

I might return mine and give this up. You could of course create the APIs yourself, but that’s not something I see myself getting done in the weekends in a reasonable time frame.

Are you able to tell me the steps required to get the Nodejs REST API working?

To be honest my previous nodejs experience was one project in university a couple of years ago, I have no idea if my solution is the preferred one when it comes to node.

One of the problems I had was related to the library used to get nodejs to communicate with the serial port. This was solved by using an earlier version of node. I think version 12 of node was the one that worked for me.

I had to build that library beforehand with some kind of flag. Not sure why this was needed. Can’t remember the exact flag or the name of the library right now. If you look through the build error logs if “npm install” fails its most likely the culprit library.

You will also need a typescript compiler installed on your Pi to build the project. More or less: you need to install typescript.

Not sure how much node experience you have, but building and running the project should be as easy as:

1, clone the repository.
2, “sudo npm install” to install the required packages
3, “sudo npm run build” to compile the typescript files
4, “sudo npm run start” to start the nodejs server

I’m pretty sure this was as easy as the 4 steps above when everything was up to date. Latest node version is at 16(?) right now and I guess these fast moving projects, like node, need some kind of regular updates if you want users to have an easy time installing and running them.

Get back to me if you don’t get it running. Good luck !

Thanks very much. I don’t have Nodejs experience but understand the instructions and will have another go at getting it working :slight_smile:

@numsey I had a go tonight but failed. so Installed Typescript complier for version 3.7.2 as this was about the time the Nodejs codebase was last committed to git. And then gulp. And ran the command “sudo npm install”, that didn’t complain too much but it failed to build. First complained about the node directory being owned by root, fixed that. Then failed to build…

node_modules/@types/node/index.d.ts:35:1 - error TS1084: Invalid ‘reference’ directive syntax. 35 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

npm ERR! errno 2
npm ERR! sphero-sdk-raspberrypi-nodejs@1.0.0 build: tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the sphero-sdk-raspberrypi-nodejs@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-01-11T20_51_44_893Z-debug.log

Oddly enough, I couldn’t locate the log file!?

Should I just try the latest version of typescript? Probably…

I did a fresh install of my Pi with the imaged supplied by Sphero.

Going to try to document my steps of getting the nodejs SKD up and running. This might come in handy if others find this thread later on :slight_smile:

I’m using:

node -v

First step is to clone the repository found here: GitHub - sphero-inc/sphero-sdk-raspberrypi-nodejs: Sphero SDK to run on Raspberry Pi using a Node.js RESTful web api and web sockets.

Place it whereever you like on your Pi. Should not matter at all. I placed mine in my home directory for simplicity.

(Installing typescipt might be done with sudo npm install, I did it manually this time)
Since your Pi does not come with typescript installed by default you need to install it. I did this using npm:

cd sphero-sdk-raspberrypi-nodejs/
npm install typescript

This installed typescript version:

node_modules/.bin/tsc -v
Version 2.9.2

You should now hopefully be able to run:

sudo npm install

That should install all dependecies needed. This will give you warning, as long as there are no errors you should be fine.

Next step is to build the project. This should be done with:

sudo npm build run

This will probably fail for you and give you an error that looks like @Smugly post above this one.
To get rid of the error you need to edit the file


and remove one of the three / on line 35.

If you now try and run:

sudo npm run build

again you will notice other errors surfacing. This is solved by editing tsconfig.json.
Under “compilerOptions” add the line “skipLibCheck”: true wherever you like. I added it last.
You should now be able to build the project with

sudo npm run build

If you manage to build the project without errors you should be able to get the node server up and running with:

sudo npm run start

The server starts in debug mode so there should be quite a lot of output.

Swagger should be running on ip-add-of-pi:2010/api-docs/

If you are unsure of the Pi’s IP address

hostname -I

Prints current local IP.

According to other posts on this forum, some endpoints in the nodejs SDK are wrong. This means that some of the commands from Swagger will not work. I have no idea which of them work and which of them dont. You will have to try it out for yourself :slight_smile:

Disclaimer: This works for me, this does not mean that it will work for others. I have no idea if skipping a Lib check is bad practice, it probably is. But seeing that most will use this for personal projects I dont see any harm in doing it.

1 Like

@numsey you are a star! Thank you very much, if I could I would buy you a drink. I can confirm the above got me working. A couple of things that threw me; I was waiting for ages for the command line to stop debug messages (doh); so browsing to the swagger url on the pi, the try it out’s will not work until you call wake with a parameter of 1. Then it worked! Next to call the API from .NET Core…Thanks again :slight_smile:

1 Like
SPHERO Email Marketing -