Is there a CLI sdk/api available to setup particle devices over serial without having to enter the same config over and over? I have about 20 devices and to set them up over serial I need to go through the same motions every time.
I was trying to create a Python wrapper around it that would parse the stdout stream using something like Pexpect (python wrapper on Expect). But it turns out that node js app uses inquirer and so it’s waiting for prompt/input which is not something Pexpect can handle.
So, how do I hack or write a script over the particle-cli app so that I can run it without interaction?
If that’s not a possibility, can I just get a list of methods that I need to execute to write wifi credentials on the device along with claiming the device? For example, the token can be acquired from the Cloud REST api. So I am guesssing along with the token and using DFU we can program the wifi data on the device.
Setting the credentials can be done over Serial. If you’ve got a serial terminal, give the following a try when in listening mode:
-hit w, then enter your SSID as prompted
-enter your security type as prompted
-enter your password as prompted.
That should do it.
If you can somehow code those interactions up in a python/node.js script, you should be good to go. The CLI is open source, so you can make adjustments as you please. Rather than waiting for prompts, you could change it to use hard-coded credentials?
Alternatively, you could create a user firmware in which you set the credentials in code. Then flash that to the device over DFU mode. If I’m not mistaken, they should then ‘stick’ until they’re purposely erased. But then you’d still have to find a way to claim it.
But you have to start with particle serial as a command right? If I were to plugin 20 devices in one go, I would have to invoke particle serial 20 times.
Yes, that's the issue. It's incredibly hard to code those interactions and that's why I posted the question.
I would love to learn how to do it. The claiming can be done over cloud api, can't it?
I think the best way would be that Particle release their API/SDK for command line, like the did for iOS and Android. I’ve emailed sales but I am still waiting.
An serial terminal will work. I just tried putty for windows to confirm. Actually, that's all the CLI does behind the scenes. It has you enter your credentials, which it then passes over to the Photon by using the said commands. If you can write a script to send those commands, that should work just fine. It should send a "w", then your SSID, followed by your security type, and finally your password. No need to use the CLI for that. You should be able to do that in python I think, if you're more comfortable with that.
This is something I initially planned to support with the CLI along with the Photon release, but I wasn’t able to make it stable enough to feel comfortable releasing at the time. This is the first request I know of for batch setup so far, so I guess now is a good time to revisit the idea!
Would you mind giving me a little write-up as far as what you envision as the ideal workflow for this kind of batch setup? Are all devices destined for the same Wi-Fi network, owned by the same user, etc.? A step-by-step list of how you’d like things to go would be helpful!
If anyone else has suggestions for making this useful for them I’d love to hear it as well.
Well, the idea is to setup photon based sensor modules at a customer’s place. They have a working wifi network that the devices need to attach to.
Say I have 20 sensors that need to be deployed. I have a usb hub where I plug in all my devices and I have a utility that recognizes photons have been plugged in. I enter the owner cloud credentials once along with the wifi credentials. The script/utility loops over them and programs the wifi on to the photons.
Ideally I would want to do this on a UI instead of command line. But the first step is a script or some sort of SDK that I can use to call the methods from the UI.
Is that what you meant by a step by step list or would you like it if it were in more detail?
This is seriously cool. So what happens when you have to setup your Photon for the first time? you still have to go through the motion of claiming it right? That's the issue.
That’s really awesome. I forgot that particle serial outputs only one line so that expect can parse it. It fails however with things like particle setup.
If you have any idea how to automate that part, that would be amazing!
I will of course be adding this type of bulk setup to the CLI itself, but I’m glad @wgbartley has a workaround in the mean time.
@pronoyc what you describe is exactly what I had envisioned. I can’t exactly guarantee this will be a high-priority thing but I will definitely be implementing it at some point (pull requests of course welcome).
Thanks @nexxy I already forked the particle-cli repo on github and I might be working on it later. That being said, I’ve already created a GUI that allows users to claim devices and set them up in bulk. I’ll release it shortly, once I am done testing.
Hey @wesner0019, sorry I haven’t been able to work on the docs or the package for a while now (work stuff). But here’s how you use it. Once you install the package, you’ll need to import the main class Particle
example: from particle import Particle
p = Particle(‘your-username’, ‘your-password’)
This will fetch existing valid tokens using the method get_valid_token . You don’t have to worry about fetching the token, it’ll do that automatically.
After that, you can use the following methods:
get_device_list
get_device_info
claim_device
get_variable