2023-02-20 at 5:33 PM #17614Laura DeCiccoParticipant
I’ve mostly converted from the basic Arduino IDE to VSCode/Platform IO. The main reason I made the switch was library management. I love every aspect so far (code completion, integrated Git tools, etc), but I’m still struggling with how to best use the platformio.ini file to manage required libraries for a project.
For example, this is an example file that has worked for me:INI1234567891011121314151617181920212223242526272829[platformio]description = ModularSensors example intended for DRWI users with CTD, turbidity, and a EnviroDIY SIM7080G LTE modem[env:mayfly]monitor_speed = 57600board = mayflyplatform = atmelavrframework = arduinolib_ldf_mode = deep+lib_ignore =RTCZeroAdafruit NeoPixelAdafruit GFX LibraryAdafruit SSD1306Adafruit ADXL343Adafruit STMPE610Adafruit TouchScreenAdafruit ILI9341build_flags =-DSDI12_EXTERNAL_PCINT-DNEOSWSERIAL_EXTERNAL_PCINT-DMQTT_MAX_PACKET_SIZE=240-DTINY_GSM_RX_BUFFER=64-DTINY_GSM_YIELD_MS=2lib_deps =envirodiy/EnviroDIY_ModularSensors; ^^ Use this when working from an official release of the library; https://github.com/EnviroDIY/ModularSensors.git#develop; ^^ Use this when if you want to pull from the develop branch
But now I’d like to add some MQTT communication to my main.cpp. To start, I was hoping to follow the beginning of this tutorial:
What’s the best way to use the .ini file to get the ArduinoMqttClient library installed for this project?
Things I’ve tried:
I’ve added: arduino-libraries/ArduinoMqttClient
to a new line in the lib_deps
I’ve tried opening the Arduino IDE and installing the ArduinoMqttClient from there.
For both of those, I still get the red squiggly mark under:
With the hover message “Can’t open the source file ArduinoMqttClient.h”
Any tips on how to manage libraries via the .ini file and how to add new libraries would be appreciated. Similarly, are there suggestions for when/how to update libraries? At one point I clicked a button that updated some of the Adafruit libraries and got stuck because the ModularSensor library was looking for an older version (which I’d rather not have to deal with again if possible).
Thanks for any info and sorry if this topic was discussed before. I did search the forum, but I wouldn’t be surprised if I missed a pertinent discussion.
This is the best conversation I came across:
2023-02-20 at 8:06 PM #17616neilh20Participant
@ldecicco congrats on trying the platformio – it has a lot of professional capability, but like anything – getting in a fancy plane(!) there are lots of bells and whistles that can go off.
For “new” libs there are at least two ways to work with them, a) put the full path to them under libdeps
and in the platformio.ini12lib_deps =https://github.com/arduino-libraries/ArduinoMqttClient
This pulls into your directory under .pio\libdeps\mayfly
b) clone to directory <lib> – that is go to the directory lib and run
git clone firstname.lastname@example.org:arduino-libraries/ArduinoMqttClient.git
Check that its been installed correctly and builds OK. Also then need to make sure its also not specified in platformio.ini as it will also be pulled in to .pio\libdeps\mayfly and compile there instead.
To be able to modify a lib, there are a couple more stages – assuming you have a github account, first on github fork the lib, then clone it into the local lib directory. Check that its building ok from that directory. Then make modifications, finally “git push” back to your forked repo.
For a number of examples, you could look at my forks in
https://github.com/neilh10/ModularSensors/tree/release1/examples/tu_xx01 – and say how I manage TinyGSM – the amazing AT interface lib ~ see
https://github.com/neilh10/TinyGSM.git<span class=”pl-c”>#rel1 ;Bug fixes over Envirodiy</span>
It is very powerful, however does require a lot of learning by doing and also checking out other examples.
It does also require following how git works – for instance on a repo fork I try and add to a different “branch” than what the source uses. so envirodiy specifies “master”, but I create and add to “release1”, and then in the repo make that the source branch.
To understand git, I prefer the cmd line interface, as I don’t quite trust what the gui github client to tell me what its doing. I do use the vsc git for looking at differences. I often make small changes, say in a comment, just to test out how it works, and verify that its getting to the online repo correctly. I keep a “<project>-diary.docx” of what I’ve done that works. Its pretty amazing, however it can take some curating to know the sequences to make it work.
Hope that works for you
2023-02-24 at 2:20 PM #17621Laura DeCiccoParticipant
Thanks @neilh20, I think I needed to run
pio pkg install. Now that I have done that – the libraries do indeed clone then install automatically when I update the .ini file.
I’m still not sure I fully appreciate the power of the .ini file and pio commands…but that will come with time I guess.
Git is a critical part of my daily work-life, and I’ll always try to get everyone I know to use it!
2023-02-24 at 4:09 PM #17627neilh20Participant
Great @ldecicco – one area to note with “pio pkg install” is how it becomes part of your build process. I like to have a development build environment tree. Then a final “release” environment – and attempt to take a full snapshot of all libs used. I encapsulate the difference in text instructions and operation of the platformio.ini.
- You must be logged in to reply to this topic.