Visual Studio Code IDE - Particle Development setup

I’m trying to make the shift to VS Code as my Particle code editor. I’ve followed some tutorials on the web, but can’t find the process for how I include particle libraries in my VS Code project? Is there some setup in VS Code that maps to a github or url to get to the libraries? Or is this a mute point since I compile in Particle CLI? I’d like to be able to get rid of the “include file not found in include path” error, if possible

When using CLI for building you just need to add a dependency entry into the project.properties file to instruct the build server to also use the library files stored there already.
This way you won’t need to download the library sources into your project just in order to re-upload them for building.

The way to add these dependencies via CLI goes via particle library add <libName> - or you figure the name and version scheme for that lib and add the entry manually.

thanks @ScruffR this really helped point me in the right direction. I got it working and I’m compiling now in VS Code. couple of observatoins, if anyone else wants to pursue this.

  1. I was using PowerShell and this did not work to add the dependencies into project.properties. I used Node.js command prompt, I navigated to my project directory and was then able to add the dependencies which created the project.properties file.
  2. I used particle docs Command Line reference to guide me through finding the library names and adding them via the Node.js CLI particle library add <libName> command.

thanks again for the help!
Brian

2 Likes

Hey Brian, just in case it improves your already working setup in any way:

cheers!
Gustavo.

I like using Particle Desktop IDE. However, not having Atom’s “Go To Declaration” work is starting to become a issue for large projects with many files. VSC is far superior to Atom, and the problem with trying VSC, is that we have to install CLI. Every time I have installed CLI on a PC I will get BSOD in Win10. So this method here will not work for me. Is there another way to get VSC to work like Particle Desktop IDE (compile in the cloud)?

Hi, I can confirm that Go To Declaration works in VS Code.
Now, if there is NO WAY to get out of the BSOD you mention on Win10 (is it a general problem?) I would go the docker way. In the case you are familiar with docker, there is an image there:


I would modify that one for removing what I do not need and adding Particle CLI.

Or, you could try to configure a task in VS Code that calls a script to compile in the cloud (is this even possible from the scripting side?)
Gustavo.

Yup, and so does code peek. I have been slowly migrating over to ESP32, and It’s actually funny you mention “…configure a task in VS Code that calls a script to compile…” because I had to do the same thing for VSC to compile for ESP32-IDF. When you said that a light bulb went off in me saying dugh, why didn’t you think of that you already did it.

So thanks for the turning on the light bulb.

cool! :bulb:
Please, if you don’t mind, post back what you do so I learn too about your experiments.

Not sure when I will get around to trying on Particle. I did make a video on how to do it with the ESP32, maybe something there can help in the meantime.

1 Like

so I tried to install libraries following your instructions.

In VSC, in the left side, I click the particle logo, then CLI
I type (following CLI instructions)

particle library add google-maps-device-locator
particle library add Ubidots

I then open

project.properties

I then see

dependencies.google-maps-device-locator=0.0.5
dependencies.Ubidots=3.0.4

excellent!

What’s next? Do I need to re-upload them for building?
What is the command?

I thought I could just type this and compile my code and that’s it. That does not work.

#include “google-maps-device-locator.h”
#include “Ubidots.h”

what am I missing?
I think it’s a CLI command.

particle library upload? (that like me own lib…)

Thanks

well, some little time off and I think I simply need to do this in CLI

particle library copy Ubidots
particle library copy google-maps-device-locator

[EDIT]
NOPE, does not work. :unamused:

These only apply for cloud builds.
Local build will always require a local copy of the library in the lib folder of your project.
Are both these libraries present there?

This is not a very helpful symptom description. Showing the actual error message(s) you get is much more telling.

Particle Workbench (VS Code) actually features a dedictated command for installing libraries correctly in your project.

Ctrl+Shift+P
image

after following your comment

Ctrl+Shift+P Particle: Install Library

both lib where install in the folder lib
for example
\eserie_connected_demo_1\lib\Ubidots\src
I have all .h and .cpp files of Ubidots
same for
\eserie_connected_demo_1\lib\google-maps-device-locator\src

then in my code, I do

#include "google-maps-device-locator.h"
#include "Ubidots.h"
const char* WEBHOOK_NAME = "Ubidots";
Ubidots ubidots("webhook", UBI_PARTICLE);

clean my app and compile
but system does not find my lib.

cannot open source file “Ubidots.h”
identifier “Ubidots” is undefined
expected a ‘)’
‘UBI_EDUCATIONAL’ defined but not used [-Wunused-variable]
ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

the string to char is the Ubidots ubidots(“webhook”, UBI_PARTICLE); line and that comes from their demo

my other question is can the cloud lib I added affect the local compilation?
This is still in my project.properties files

dependencies.google-maps-device-locator=0.0.5
dependencies.Ubidots=3.0.4

if I want to remove them, I simply delete those two lines right? since in CLI there is no command to remove

ok get ready

forget Ubidots, I simply comment it out of my code and only have the google map lib

#include “google-maps-device-locator.h”
GoogleMapsDeviceLocator locator;

and in my code I have the at their respect place

locator.withSubscribe(locationCallback).withLocatePeriodic(30);
locator.loop(); // google map API testing

now I clean and compile and get this is terminal (here is sample, not all)


../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o): In function `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()':
c:\users\g33k\.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/functional:1734: multiple definition of `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()'
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o):c:/Users/G33K/CloudStation/Projects/BRP/particle_IO/Particle_eserie_test/eserie_demo_1/eserie_connected_demo_1//src/google-maps-device-locator.cpp:17: first defined here
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o): In function `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()':
c:\users\g33k\.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/functional:1734: multiple definition of `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()'
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o):c:\users\g33k\.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/functional:1869: first defined here
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o): In function `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()':
c:\users\g33k\.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/functional:1734: multiple definition of `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()'
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o):c:\users\g33k\.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/functional:1869: first defined here
../../../build/target/user/platform-10-m/eserie_connected_demo_1/\libuser.a(google-maps-device-locator.o): In function `GoogleMapsDeviceLocator::~GoogleMapsDeviceLocator()':

multiple definition

it means it’s define at two place on my computer

target/user/platform-10-m/eserie_connected_demo_1/
and here
c:\users\g33k.particle\toolchains\gcc-arm\5.3.1\arm-none-eabi\include\c++\5.3.1/

that is why I was asking if the cloud lib I did before are causing any issue

Thank you :slight_smile:

NB - I did delete those line, then clean (local) and compile (local)
and I have same errors

Did you delete all library files that were not inside the lib folder?
During your first attempt via particle copy library you may have added some files that are now giving you grief.

Maybe start a new project completely fresh.

Maybe start a new project completely fresh.

what a simple solution :grin:

I did that and it works perfect! I got all my stuff working.

thanks @ScruffR!

1 Like