Updated Instructions for Particle CLI on Raspberry Pi

All,

I am working through the steps to build out a disconnected updater for remote Particle devices.

The first step is to get the Particle CLI running on the Raspberry Pi. I looked at the instructions on the docs site and tried the Linux approach. The installer completed successfully, but typing Particle at the command prompt gets the “command not found”.

I then looked on the forum and could only find this post from 2017

I know things change frequently with Raspberry Pi so, this did not seem like the best path forward.

So, does anyone have a set of instructions for getting the Particle CLI running on a Raspberry Pi?

Thanks,

Chip

Things have changed over time but currently simply

sudo npm install -g particle-cli

works for me on an updated raspberry pi
edit: and using node v12.22.5

1 Like

@bpr,

Thank you. So, I think it would be helpful to detail the steps that would be needed for a customer with a new Raspian image. Here is what I have far:

  1. Make sure you have the latest:
sudo apt update            // See what is available
sudo apt full-upgrade.   // Perform the upgrade
sudo apt clean              // Free up space
sudo reboot
  1. Check to make sure you have Node and npm
node -v                       // should get a version response like v10.24.0
npm -v                        // should get a version response like 5.8.0

If you don’t get the responses listed, you need to install these

  1. Assuming these work - then use your command
sudo npm install -g particle-cli  // Test by typing "particle -v" at the command prompt - should get an information page

Here is the problem, I don’t think this is a complete install. When I put a Particle device into “listening mode” and connect it to the Raspberry Pi’s USB port, I get this error message.

The 'serialport' dependency is missing or invalid.
Please reinstall https://docs.particle.io/tutorials/developer-tools/cli/#installing
Cannot find module '@serialport/bindings'

so, I tried instruction on the particle docs page:

bash <( curl -sL https://particle.io/install-cli )      // Installed successfully - told me to uninstall using npm

npm uninstall -g particle-cli                                // Then closed and opened terminal window

particle -v                                                          // This worked

particle identify                                                  // failed with the same error 'serialport' message

This gets me right back to the same error I got before. So, I tried installing serialport…

sudo npm install -g serialport

Failed at the @serialport/bindings@9.2.7 install script. It looks like it is failing in the prebuild step when installing node-gyp

So, I have the Particle CLI but I cannot us the Raspberry Pi to communicate with a Particle device over USB. I am a Raspberry novice so any help would be appreciated.

Thanks,

chip

I’ve checked how we run it internally on Pis we use to test:
downloaded from:
https://particle.io/install-cli
and we run install-particle-cli

@no1089 ,

Thanks for the tip. I tried to follow your instructions but - again - no joy.

I downloaded from the link provided by:

git clone https://github.com/particle-iot/particle-cli.git
cd particle-cli

and then

install-particle-cli

But I got a command not found message so I tried the commands in the guide:

$ npm install
$ npm start -- help

But got the same error: "Cannot find module ‘@serialport/bindings’

So, still stuck. Is there any way to focus on this serial port dependency?

Thanks,

Chip

Have you tried using neopo?

Along with the required toolchains it will also give you particle-cli.

On Raspbian:

bash <(curl -sL neopo.xyz/install)

After installation you can use it with:

particle login

If you happen to have conflicting copies of particle in your $PATH, you can use the neopo prefix:

neopo particle login

While creating neopo I’ve tried to resolve as many problems as I can related to using Particle command line tools on Raspberry Pi and other Linux hosts.

2 Likes

@nrobinson2000

Boom! Works! First time, I was able to install, log in to Particle, Identify a device in listening mode and flash Tinker. You have done a great job with this tool!

I would suggest that this becomes the default method to get the Particle CLI on the Raspberry Pi.

Now, on to the rest of the steps in Rick’s process. Please let me know if you happen to get there before me and package up the disconnected installer.

Thank you

2 Likes

@nrobinson2000 - Great work! I have to agree with @chipmc that neopo solves the problem!. I hadn’t realized serialport wouldn’t get installed properly the other way (sudo npm install -g particle-cli) for reasons that are beyond me.
@chipmc, if you also want just a stripped down particle-cli installer without all the great neopo goodies, here’s the commands (that could be scripted) to install the cli. (Tested twice this time, I promise, but only confirmed serial list, publish and monitor to be working):

#As always…
pi@raspberrypi:~ $ sudo apt update && sudo apt upgrade

pi@raspberrypi:~ $ sudo apt purge nodejs # critical to get rid of previous nodejs installation if any!

pi@raspberrypi:~ $ sudo apt autoremove

pi@raspberrypi:~ $ sudo rm -rf package-lock.json

pi@raspberrypi:~ $ sudo rm -rf node_modules

#Use audstanley latest node install script
pi@raspberrypi:~ $ wget -O - https://raw.githubusercontent.com/audstanley/NodeJs-Raspberry-Pi/master/Install-Node.sh | sudo bash; node -v;

pi@raspberrypi:~ $ sudo npm install -g npm

pi@raspberrypi:~ $ mkdir -p particle-cli
pi@raspberrypi:~ $ cd particle-cli

#next we want to let npm install modules globally w/o needing sudo
#see: Resolving EACCES permissions errors when installing packages globally | npm Docs
pi@raspberrypi:~/particle-cli $ mkdir ~/.npm-global
pi@raspberrypi:~/particle-cli $ npm config set prefix ‘~/.npm-global’
pi@raspberrypi:~/particle-cli $ sudo nano ~/.profile
#Then add “export PATH=~/.npm-global/bin:$PATH” w/o the quotes to the end of ~/.profile then save file
#Next configure npm to use new PATH
pi@raspberrypi:~/particle-cli $ source ~/.profile

pi@raspberrypi:~/particle-cli $ npm install -g @mapbox/node-pre-gyp serialport particle-cli --save

pi@raspberrypi:~/particle-cli $ particle login

pi@raspberrypi:~/particle-cli $ npm -g list
/home/pi/.npm-global/lib
├── @mapbox/node-pre-gyp@1.0.7
├── particle-cli@2.16.0
└── serialport@9.2.7

pi@raspberrypi:~/particle-cli $ particle serial list
Found 1 device connected via serial:
/dev/ttyACM0 - Photon - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

@bpr,

Thank you for this! Problem solved with Neopo but I like having a stripped down version too.

Chip

So, I wanted to summarize in case anyone finds this thread in the future. Here is the net - net:

You can install the Particle CLI on the Raspberry Pi and do all the things you can do on a PC/Mac including flashing the device.

In this thread, three solutions were proposed but only two worked for me:

  1. neopo - was the easiest and it provides benefits beyond the Particle CLI.
  2. @bpr offered a step-by-step list of commands that also worked but required more time / patience
  3. The instructions on the Particle docs allowed me to install the Particle CLI and log in. However, it did not provide any functionality that requires USB communications. Specifically, even though the Raspberry Pi is running Linux, the Linux instructions do not work. The manual process described in the docs also did not deliver full functionality.

@Colleen given that the Raspberry Pi is a popular device in the IOT / maker community, perhaps they could be updated to include one of these solutions.

@bpr and @no1089 and @nrobinson2000 - thank you all for your help!

Thanks,

Chip

3 Likes

@chipmc
Btw, I finally scripted a simple particle-cli installer with latest node install for the raspberry pi so that all you have to do is enter “sudo bash particle-cli-setup.sh” from your home directory (usually pi) in your terminal. If anyone is interested, it’s at https://gist.github.com/bprobbins/e530a4916ba7e94aada8dfa46add0770

1 Like

@bpr,

Thank you! That is awesome.

Chip

@Colleen I’ve been working on neopo (and its predecessor po-util) for several years and I always appreciate it whenever Particle users are able to use neopo to improve their Particle workflow.

If you’re interested in writing any official tutorials or documentation about it I’d be glad to help out.

2 Likes

Thanks @nrobinson2000 I think that’s a great idea that would benefit the Particle user base. Right now I have my tutorial docket full for the next couple of months or so (webhooks then workbench then Echo integrations) but will add neopo to the schedule!

1 Like