PlatformIO Community

Compiling SonoffBoilerplate in PlatformIO - Help needed!


#1

I’m running into several issues as I’ve been trying to compile SonoffBoilerplate into PlatformIO. I did the following:

1- Downloaded Arduino Extension
2- Downloaded Blynk library
3- Downloaded WifiManager library
4- Downloaded MQTT library
5- Started a new project with board as “ESP8266 1MB flash” and “Arduino” as the platform
6- Placed SonoffBoilerplate.ino into “src” folder and modified platformio.ini like this:

[platformio]
src_dir = src
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino

I’m getting the following errors:

fatal error: PubSubClient.h: No such file or directory
error: no matching function for call to ‘PubSubClient::publish(char [50], String&)’
error: ‘MQTT’ does not name a type
error: expected unqualified-id before ‘&’ token
error: expected ‘)’ before ‘&’ token
error: expected initializer before ‘pub’

Any ideas?

Thank you in advance!


#2

It’s possible you didn’t install the correct MQTT library - it’s a fork of the PubSubClient library by Nick O’Leary.

Replace your platformio.ini with the below, and PlatformIO will download the correctly libraries for your project. Make sure you delete the main.cpp file, as you’ll otherwise get an error about setup() and loop() being previously declared or some other error. You don’t need to install libraries globally with PlatformIO, it’s better to do them on a per-project basis then only the libraries your project actually needs can be seen at compile time.

; 415 - Blynk
; 567 - WifiManager
; https://github.com/Imroy/pubsubclient - fork of Nick O'Leary's library 

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps =
     415
     567
     https://github.com/Imroy/pubsubclient

And by if ‘Downloaded Arduino Extension’, you mean you accepted the recommendation of VSCode to install the Arduino Extension, it would be advisable to remove it, as it is NOT what you need, and will only cause errors and problems later down the track.


#3

You were correct. I ran into a lot of issues since I installed it that way. I will remove it and other libs I have installed manually and will use the platformio.ini you provided. Hopefully this would help compiling the project.

By the way, the MQTT lib I have installed was the one you were referring to: " PubSubClient by Nick O’Leary"

Thank you!


#4

This is what happens as soon as I import the .ino file into src folder and remove main.c:


#5

Should be either .ino or .cpp. If I use the platformio.ini


[env:esp8266]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
     415
     567
     https://github.com/Imroy/pubsubclient

And save the example file into src\main.cpp, compilation works as expected.

For the C/C++ linter / code completion to work you might have to execute the “Rebuild C/C++ Project Index” target once. Press Ctrl+Shift+P and type “Rebuild”, then click on that target.


#6

Hi,

I have followed your instructions and now project compiles successfully! Thank you very much!

Regards


#7

By the way, where I can read more about the parameters passed in the platformio.ini file and how to determine dependencies for a certain project? Could you please explain this line:

lib_deps =
415
567
https://github.com/Imroy/pubsubclient


#8

Pretty much everything you’ll ever need to know about PlatformIO is on the documentation site. :wink:

What I basically did was go to to the library registry, search for the library that I wanted, got it’s ID number, and that is what you see in the file. I use the ID numbers in preference to the names in case there are multiple libraries with the same name. In the case of Ian’s (lmroy) fork of the PubSubClient library, that wasn’t on the registry, so it was a matter directly using the github version instead.


#9

Awesome! That was very clear and straightforward! Thank you again!:kissing_heart: