The Particle Libraries 2.0 works great!

I’ve built up quite a few Photon C++ files as part of my RV home automation projects, and have been noodling over how best to share these. I’d decided to release all the source on Github, but realized that just throwing a few dozen files out there probably wouldn’t benefit anybody. Well, when I saw Particle’s recent announcement for the libraries 2.0, it looked like exactly what I was looking for.

I’m delighted to say at this point that it appears to working great, and has simplified the process that I’ve been using to date. I currently use a combination of Git, shell scripts, shared C++ files, and the particle cloud compiler and flash to build the files for each of my controllers. It’s quick and works reliably, but it’s complicated and I dread trying to document and explain to someone else how to do the same thing.

So instead, it looks like Particle’s libraries 2.0 is going to make sharing quite easy.

First, I converted all my shared files into a single IoT library. This was fairly easy using the Particle CLI library functions.

Then I created several examples and included them in the IoT library’s examples directory. One of the cool things about these are that they can be built using the CLI, Particle Dev, or the cloud IDE. And since they’re a single file about a page long, any of those options work well.

Finally, I converted each of my controller’s source directories to use the Particle project format which creates a project.properties file. This allows then adding the IoT library to the project.

So now to build a project I need only run ‘particle compile photon’ in the project’s directory. To flash the project to the device, I use a shortcut where I name the project’s directory the exact same thing as the controller’s name. Then I can run the command ‘particle flash ${PWD##*/}’ and it compiles and flashes the code to the device with the same name as the directory.

And of course I created aliases in my .bash_profile so I can run them using just ‘b’ or ‘f’ from within any project directory.

The library code is probably still quite buggy, but I’ll be actively updating as issues are found. I’d love to hear your experiences with it, and reports of any problems. The source code is on GitHub at https://github.com/rlisle/ParticleIoT.git, and the ready-to-use library uploaded and published on particle.io under the name “IoT”.

Leave a Reply

Your email address will not be published. Required fields are marked *