Errors trying to build WiFi project

hi All
first I have to say that I am new to PIO having moved across from Arduino
My project is a direct copy from an Arduino project which compiles and runs with no problems.
an excerpt from my main.cpp file is: (the whole file is quire large)

#include <Arduino.h>
#include <WiFi.h>
WiFiClient net;

#include <ArduinoOTA.h>

#include <MQTT.h>
#include <MQTTClient.h>
MQTTClient client(256);

#include <Streaming.h>
#include <EEPROM.h>
#include <Ticker.h>
#include <stdio.h>

#include <OneWire.h>
const int oneWireBus = 4;
OneWire oneWire(oneWireBus);

#include <DallasTemperature.h>
DallasTemperature sensors(&oneWire);
// use sensors.begin(); in setup

#include "variables.h"
//==============================

the first problem:
the line WiFiClient net; was showing as an error WiFiClient does not name a type

I was trying to resolve this when i had an error from PIO saying:
Can not remove temporary directory c:\Users\Dave\Documents\PlatformIO\Projects\WiFiMqtt Module\.pio\build.
Please remove it manually to avoid build issues

i did remove it manually but this error persists, i can see that PIO has replaced the directory but it comes up with the same error again and again

there are other errors being shown by the system but i am sure most of those will be resolved when i can find the solution to these two.

my project.ini file is unchanged:

;PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:fm-devkit]
platform = espressif32
board = fm-devkit
framework = arduino

i am sure i am experiencing ‘teething’ problems if anyone can point me in the right direction i would be most grateful
thanks in advance
Dave

In order to compile your project, a few libraries are needed. The easiest way to add them is to declare them in platformio.ini. Other options, which I do not recommend, are to download them and put them either in C:\Users\username\.platformio\lib or C:\Users\username\Documents\PlatformIO\Projects\projectname\lib.

To fix it:

  • Delete all contents C:\Users\ Dave\.platformio\lib
  • Delete all contents in C:\Users\Dave\Documents\PlatformIO\Projects\WiFiMqtt Module\lib
  • Remove the directory C:\Users\Dave\Documents\PlatformIO\Projects\WiFiMqtt Module\.pio
  • Add the below lines to platformio.ini
  • Compile again
lib_deps =
    617 ; MQTT
    Streaming
    DallasTemperature

As you haven’t shown the entire code, additional libraries might be needed. PlatformIO helps you finding them. Just go through the build output and look for something like this:

***************************************************************************
* Looking for DallasTemperature.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:DallasTemperature.h"
* Web  > https://platformio.org/lib/search?query=header:DallasTemperature.h
*
***************************************************************************

hi @manuelbl thank you for your interest
i went through the list of things you suggest and tried compiling again with a very similar result the main thing again being that the WiFiClien net; line still has the red underline
the build output dependency graph is:
Scanning dependencies…
Dependency Graph
MQTT 2.4.3
Streaming 5
DallasTemperature 3.8.0
OneWire 2.3.5
Ticker 1.1
EEPROM 1.0.3
OneWire 2.3.5
ArduinoOTA 1.0
Update 1.0
WiFi 1.0
ESPmDNS 1.0
Building in release mode

this lists all of my include files except MQTTClient.h which is probably included via MQTT.h
i get a lot of WiFi was not declared in this scope errors which will be caused no doubt by the initial error which i still get.
i cannot understand why there is a difference between PIO and Arduino when all of the included libs are the same.
originally i had copied all of the library files to the C:\Users\ Dave\.platformio\lib directory in an effort to keep everything together. I have now changed that to doing it the way you suggest.
would it be helpful if i posted the rest of the main.cpp file, there are also 7 other remote files which i include into main.cpp
as i said before, thank you for your help

update
in an effort to find out what is happening, from the CLI i ran
platformio lib install --save
all of my include files except 1 (WiFi.h) were saved ok, could this point to the root of the problem i wonder

Dave

We will need to see the entire code (incl. platformio.ini) and the entire output of the build task so we can reproduce it.

If it’s just two files, you can add it directly in the forum. Otherwise it would be better to publish it on GitHub or somewhere similar.

When inserted code, please put three backquotes (```) before and after the code.

Forget about the red squiggly lines for the moment. They don’t necessarily match. We will first focus on building the code.

1 Like

No, as Wifi.h is a built-in library for the ESP32 Arduino core. It should not be installed via lib_deps as it is built in.

As Manuel said, without even minimal reproducible code example it’s hard to say what’s going on on, hence the need for the code if you can make that available.

hi @manuelbl & @pfeerick
again thank you for your interest, maybe i should explain:
the original project i copied from arduino was not an attempt to use PIO in anger, more a way to start to learn about PIO which looks to me a worthy contender to carry on from the point arduino has reached.
the code i included (partially) was not to protect my code from ‘prying eyes’ if anyone wants it i will willingly give it to them, it was an attempt to keep things simple.
to this end i have created another project which is minimal but similar, the full code is:

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
WiFiClient net;

#include <MQTT.h>
#include <MQTTClient.h>
MQTTClient client(256);

#include <Streaming.h>
#include <EEPROM.h>
#include <Ticker.h>
#include <stdio.h>
#include <OneWire.h>
const int oneWireBus = 4;
OneWire oneWire(oneWireBus);

#include <DallasTemperature.h>
DallasTemperature sensors(&oneWire);

// use sensors.begin(); in setup

void setup() {
Serial.begin(115200);
sensors.begin();
}

void loop() {
Serial << "Hello World" << endl;
delay(3000);
}

the projectio.ini file is:

;PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:fm-devkit]
platform = espressif32
board = fm-devkit
framework = arduino
lib_deps =
    617 ; MQTT
    Streaming
    DallasTemperature

after compiling this code i get the following errors in the terminal window:

{
	"resource": "/c:/Users/Dave/Documents/PlatformIO/Projects/testing/src/main.cpp",
	"owner": "C/C++5",
	"code": "1696",
	"severity": 8,
	"message": "#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\\Users\\Dave\\Documents\\PlatformIO\\Projects\\testing\\src\\main.cpp).",
	"source": "C/C++",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 21
}

{
	"resource": "/c:/Users/Dave/Documents/PlatformIO/Projects/testing/src/main.cpp",
	"owner": "C/C++5",
	"code": "1696",
	"severity": 8,
	"message": "cannot open source file \"stdbool.h\" (dependency of \"Arduino.h\")",
	"source": "C/C++",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 21
}
{
	"resource": "/c:/Users/Dave/Documents/PlatformIO/Projects/testing/src/main.cpp",
	"owner": "C/C++5",
	"code": "1696",
	"severity": 8,
	"message": "cannot open source file \"stdbool.h\" (dependency of \"WiFi.h\")",
	"source": "C/C++",
	"startLineNumber": 3,
	"startColumn": 1,
	"endLineNumber": 3,
	"endColumn": 18
}
{
	"resource": "/c:/Users/Dave/Documents/PlatformIO/Projects/testing/src/main.cpp",
	"owner": "C/C++5",
	"code": "1696",
	"severity": 8,
	"message": "cannot open source file \"stdbool.h\" (dependency of \"MQTT.h\")",
	"source": "C/C++",
	"startLineNumber": 7,
	"startColumn": 1,
	"endLineNumber": 7,
	"endColumn": 18
}

that was an attempt to copy and paste the errors here from terminal

bearing in mind that this is a new minimal project:

  1. should i be getting these errors
  2. why am i getting these errors
  3. how do i guard against this happening in any future projects

one other question
the additions to projectio.ini which Manuel suggested i use, could you explain in a little more detail again so that in the future they become useful

thanks for all of your help
Dave

Can you please edit your reply and add triple backquotes around code?

ok, i’ve done that, you certainly are fast at answering

Can you also provide the output from the build task that appears in the Terminal view? You have added the contents of the Problems view.

The build output looks like so:

> Executing task in folder wifi-sample: platformio run <

Processing fm-devkit (platform: espressif32; board: fm-devkit; framework: arduino)

...

===================================================================================================== [SUCCESS] Took 14.15 seconds =====================================================================================================

Terminal will be reused by tasks, press any key to close it.

i have just re compiled the code and it comes up with success however looking at main.cpp i still have red underlines under:
#include <Arduino.h>
#include <WiFi.h>
#include <MQTT.h>
???

the output is:

> Executing task in folder testing: C:\Users\Dave\.platformio\penv\Scripts\platformio.exe run <

Processing fm-devkit (platform: espressif32; board: fm-devkit; framework: arduino)
------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/fm-devkit.html
PLATFORM: Espressif 32 1.11.1 > ESP32 FM DevKit
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0 (2.6.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MQTT> 2.4.3
|-- <Streaming> 5
|-- <DallasTemperature> 3.8.0
|   |-- <OneWire> 2.3.5
|-- <EEPROM> 1.0.3
|-- <WiFi> 1.0
|-- <OneWire> 2.3.5
|-- <Ticker> 1.1
Building in release mode
Compiling .pio\build\fm-devkit\src\main.cpp.o
Linking .pio\build\fm-devkit\firmware.elf
Retrieving maximum program size .pio\build\fm-devkit\firmware.elf
Checking size .pio\build\fm-devkit\firmware.elf
Building .pio\build\fm-devkit\firmware.bin
esptool.py v2.6
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [=         ]   5.8% (used 19044 bytes from 327680 bytes)
PROGRAM: [===       ]  25.1% (used 328405 bytes from 1310720 bytes)
======================================= [SUCCESS] Took 8.32 seconds =======================================

Terminal will be reused by tasks, press any key to close it.

if i hover over wifi or mqtt includes i get the message:
cannot open file stdbool.h a dependency of wifi or mqtt

Good news. It compiles and hopefully it uploads as well.

Now for the red squiggly lines. That’s a separate Intellisense system running in the background - and unfortunately it it gets easily confused.

To troubleshoot it:

  • Close all open files (editors) in Visual Studio Code and reopen them from the Explorer view (as the background process might associate the open file with the wrong project or no project at all)
  • Ensure that your project directory is a top level directory in the Explorer view, i.e. either the directory name appears at the same level as OPEN EDITORS or – if a workspace is at this level – at the highest level within the workspace. (Same as above, Visual Studio Code might associated the files with the wrong project.)
  • Restart Visual Studio Code (in order to restart the background process)
  • Check the Visual Studio Code extensions and disable all C/C++ related extension except C/C++ from Microsoft and PlatformIO. (You might have to Intellisense systems running in the background, one of which doesn’t understand PlatformIO projects.)
1 Like

hi @manuelbl & @pfeerick
thank you for trying to help me
i feel its only fair to tell you that i was looking upon pio as a replacement for Arduino IDE, i am a maker and as such am not really interested in trying to use a system which i have found over the last two weeks to need a tweak here, a bend there and reload this or that to see if that works.
i am sure that in the future pio will grow up to be a useful system but at the moment i have decided to stick with Arduino. I am a simple person and Arduinos simplicity (open it and start programming) appeals to me.
I wish yourselves and the programmers a big lot of luck and i will try it again in a year or two when it is a more mature system
thanks for everything
Dave

1 Like

@hoka I think I you are approaching this as an Arduino replacement. It has been created as something much more than that. It’s different, it’s not Arduino, so you do have to learn a few new things.

To be fair to the environment maybe you should have simply done a “blink” to get that to work. There’s an awful lot of strengths here that Arduino cannot match.

Are there bugs? Yes. However I can say the folks here have been more helpful than anywhere else. I moved a very large/complicated project to PlatformIO and while it was not uneventful it was the best thing I ever did.

I encourage you to give it another shot with a simple demo and build on it from there. It’s worth the time IMHO.

1 Like

In addition to what has been said above, if you do wait, don’t wait 1-2 years… wait 1-2 months… things are moving pretty quickly with PlatformIO of late… including a GUI configuration panel for setting up your board options… so less/no fiddling around in a platformio.ini and needing to know what all the options are! :slight_smile:

PlatformIO has come a long way since I first encoutered it several years ago… at that point I didn’t see the benefit, but since v3 + VSCode came along, I tried it again, and haven’t regretted it one bit. The Arduino IDE only comes out if I need to check for backwards compatibility with the Arduino IDE, or am working on a board support package for the Arduino IDE.

The keyboard input focus issue that has been plaguing PlatformIO + VSCode since June will be fixed in VSCode 1.41 (it’s in the current Insiders build of VSCode).

IntelliSense (the output you’ve been copying from the ‘Problems’ tab) is good when it works… but every now and then it really goes stupid. To be honest, I very rarely look at that tab, instead relying on the actual compile output… if it fails, it fails miserably, if it passes, it passes. I only get really annoyed when the red underlines start, and that is usually fixed by restart VSCode, opening a new window (hence a new workspace) and re-adding the project folders. Thankfully it doesn’t seem to happen too often, so I can live with that Microsoft-induced headache (IntelliSense is provided by the Microsoft C/C++ extension).