PlatformIO: Can't build ArduinoCloudIoT on MKR WiFi1010

hey guys,

i have currently the problem that I can't compile ArduinoIoTCloud on MKR WiFi with PlatformIO as VS Code extension on macOS 14.5

The main Problem is that the compiler is throwing a lot of "redefinition of..." faults. I suppose that there is a problem with the buildin libraries of the board

In file included from .pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/SecureElement.h:19:0,
                 from .pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/Arduino_SecureElement.h:11,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloudTCP.h:32,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:165,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/SecureElementConfig.h:15:78: warning: backslash and newline separated by space
   defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) ||  \
                                                                               
Compiling .pio/build/mkr_wifi1010/lib4a5/src/utility/ASN1Utils.cpp.o
In file included from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/utility/wifi_drv.h:28:0,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiStorage.h:23,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFi.h:38,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiNINA.h:23,
                 from .pio/libdeps/mkr_wifi1010/Arduino_ConnectionHandler/src/Arduino_ConnectionHandler.h:44,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:27,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/WiFi101/src/WiFiClient.h:31:7: error: redefinition of 'class WiFiClient'
 class WiFiClient : public Client {
       ^~~~~~~~~~
In file included from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFi.h:35:0,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiNINA.h:23,
                 from .pio/libdeps/mkr_wifi1010/Arduino_ConnectionHandler/src/Arduino_ConnectionHandler.h:44,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:27,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiClient.h:28:7: note: previous definition of 'class WiFiClient'
 class WiFiClient : public Client {
       ^~~~~~~~~~
Compiling .pio/build/mkr_wifi1010/lib4a5/src/utility/ECCX08CSR.cpp.o
Compiling .pio/build/mkr_wifi1010/lib4a5/src/utility/ECCX08JWS.cpp.o
Archiving .pio/build/mkr_wifi1010/libcb5/libWire.a
In file included from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/PropertyContainer.h:51:0,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/CBORDecoder.h:31,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:35,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h: In member function 'virtual void CloudTelevision::setAttributesFromCloud()':
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h:229:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       setAttribute((int&)_cloud_value.pbc, "pbc");
                                       ^~~
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h:230:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       setAttribute((int&)_cloud_value.inp, "inp");

The Arduino Cloud Headers are only included in the following files:

ThingProperties:

#ifndef THINGPROPERTIES_H
#define THINGPROPERTIES_H

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include "arduino_secrets.h"

#if !(defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_LORA) || \
      defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT))
  #error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif

#if defined(BOARD_HAS_SECRET_KEY)
  #define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif

void onLedChange();

bool led;
int potentiometer;
int seconds;

void initProperties() {
#if defined(BOARD_HAS_SECRET_KEY)
  ArduinoCloud.setBoardId(BOARD_ID);
  ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
  ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
  ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
  ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);
#elif defined(BOARD_HAS_LORA)
  ArduinoCloud.addProperty(led, 1, Permission::ReadWrite).onUpdate(onLedChange);
  ArduinoCloud.addProperty(potentiometer, 2, Permission::Read).publishOnChange(10);
  ArduinoCloud.addProperty(seconds, 3, Permission::Read).publishEvery(5 * MINUTES);
#endif
}

#if defined(BOARD_HAS_ETHERNET)
  /* DHCP mode */
  //EthernetConnectionHandler ArduinoIoTPreferredConnection;
  /* Manual mode. It will fallback in DHCP mode if SECRET_OPTIONAL_IP is invalid or equal to "0.0.0.0" */
  EthernetConnectionHandler ArduinoIoTPreferredConnection(SECRET_OPTIONAL_IP, SECRET_OPTIONAL_DNS, SECRET_OPTIONAL_GATEWAY, SECRET_OPTIONAL_NETMASK);
#elif defined(BOARD_HAS_WIFI)
  WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
#elif defined(BOARD_HAS_GSM)
  GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_LORA)
  LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A);
#elif defined(BOARD_HAS_NB)
  NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#elif defined(BOARD_HAS_CATM1_NBIOT)
  CatM1ConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS);
#endif

#endif // THINGPROPERTIES_H

Arduino Secrets:

#ifndef ARDUINO_SECRETS_H
#define ARDUINO_SECRETS_H

#include <Arduino_ConnectionHandler.h>

/* A complete list of supported boards with WiFi is available here:
 * https://github.com/arduino-libraries/ArduinoIoTCloud/#what
 */
#if defined(BOARD_HAS_WIFI)
  #define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
  #define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"
#endif

/* ESP8266 ESP32 */
#if defined(BOARD_HAS_SECRET_KEY)
  #define SECRET_DEVICE_KEY "my-device-password"
#endif

/* MKR GSM 1400 */ /* MKR NB 1500 */ /* Portenta CAT.M1/NB IoT GNSS Shield */
#if defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_CATM1_NBIOT)
  #define SECRET_PIN ""
  #define SECRET_APN ""
  #define SECRET_LOGIN ""
  #define SECRET_PASS ""
#endif

/* MKR WAN 1300/1310 */
#if defined(BOARD_HAS_LORA)
  #define SECRET_APP_EUI ""
  #define SECRET_APP_KEY ""
#endif

/* Portenta H7 + Ethernet shield */
#if defined(BOARD_HAS_ETHERNET)
  #define SECRET_OPTIONAL_IP ""
  #define SECRET_OPTIONAL_DNS ""
  #define SECRET_OPTIONAL_GATEWAY ""
  #define SECRET_OPTIONAL_NETMASK ""
#endif

#endif // ARDUINO_SECRETS_H

main.cpp:

#include "ir_receiver.hpp"
#include "iot_cli.hpp"
#include "thingproperties.h"

#include <Arduino.h>

IR_Handle _irHandle;

void setup() {

  Serial.begin(9600);

  // Defined in thingProperties.h
  //initProperties();

  // Connect to Arduino IoT Cloud
  // ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  _irHandle.init(0, true);

}

void loop() {
  //ArduinoCloud.update();

  auto ret = _irHandle.run();

  Serial.println(ret);
  delay(1000);

}

I'm entering the problem also if I only include the basic ArduinoIoTCloud example of the library

Here is my platformio.ini (please consider the things which i already tried)

; 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

[platformio]

[env:mkr_wifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps = 
	z3t0/IRremote@^4.4.0
	arduino-libraries/ArduinoIoTCloud@^2.0.3
	jandrassy/ArduinoOTA@^1.1.0
	#arduino-libraries/ArduinoIoTCloudBearSSL@^1.1.2
	#arduino-libraries/ArduinoECCX08@^1.3.8
	#arduino-libraries/WiFiNINA@^1.8.0
	arduino-libraries/Arduino_ConnectionHandler@^0.9.0

#Didnt work also with/without following lines
board_build.mcu = samd21g18a
board_build.f_cpu = 48000000L
upload_protocol = sam-ba

lib_extra_dirs = .pio/libdeps/mkr_wifi1010/ArduinoECCX08
lib_ignore = mkr_wifi1010, WiFi101, 
lib_ldf_mode = deep

I've tried several things:

  • all lib_ldf_modes (each mode is triggering different compiling errors)
  • including different Wi-Fi libraries
  • no include of extra Wi-Fi libraries
  • The fault is gone if i remove the <ArduinoCloudIoT.h>

Hi @alexandertonn.

The "WiFi101" library is being found for this #include directive in the "WiFiNINA" library:

That #include is intended to target the header file of that name in the WiFiNINA library, not in the WiFi101 library.

Is there a reason you commented this out? I don't have any experience with PlatformIO, but I think that if you explicitly specify a dependency on the WiFiNINA library, this will cause it to be given priority by the Library Dependency Finder

It is strange that it found the library even though you have it in this field. I wonder if the problem is the trailing comma? The INI file format is not well defined so it is not clear whether or not trailing commas on arrays are supported or not.

The definitions in the .ini are for testing purpose, but it makes not difference if i remove these lines.

; 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

[platformio]

[env:mkr_wifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps = 
	z3t0/IRremote@^4.4.0
	arduino-libraries/ArduinoIoTCloud@^2.0.3
	jandrassy/ArduinoOTA@^1.1.0
	arduino-libraries/WiFiNINA@^1.8.0
	arduino-libraries/Arduino_ConnectionHandler@^0.9.0

#Didnt work also with/without following lines
board_build.mcu = samd21g18a
board_build.f_cpu = 48000000L
upload_protocol = sam-ba

lib_ldf_mode = deep

Temrinal Output:

In file included from .pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/SecureElement.h:19:0,
                 from .pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/Arduino_SecureElement.h:11,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloudTCP.h:32,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:165,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/Arduino_SecureElement/src/SecureElementConfig.h:15:78: warning: backslash and newline separated by space
   defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) ||  \
                                                                               
Compiling .pio/build/mkr_wifi1010/lib7d1/WiFiNINA/utility/wifi_drv.cpp.o
Compiling .pio/build/mkr_wifi1010/libcb5/Wire/Wire.cpp.o
Compiling .pio/build/mkr_wifi1010/lib889/ArduinoECCX08/ECCX08.cpp.o
In file included from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/utility/wifi_drv.h:28:0,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiStorage.h:23,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFi.h:38,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiNINA.h:23,
                 from .pio/libdeps/mkr_wifi1010/Arduino_ConnectionHandler/src/Arduino_ConnectionHandler.h:44,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:27,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/WiFi101/src/WiFiClient.h:31:7: error: redefinition of 'class WiFiClient'
 class WiFiClient : public Client {
       ^~~~~~~~~~
In file included from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFi.h:35:0,
                 from .pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiNINA.h:23,
                 from .pio/libdeps/mkr_wifi1010/Arduino_ConnectionHandler/src/Arduino_ConnectionHandler.h:44,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:27,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/WiFiNINA/src/WiFiClient.h:28:7: note: previous definition of 'class WiFiClient'
 class WiFiClient : public Client {
       ^~~~~~~~~~
Compiling .pio/build/mkr_wifi1010/lib889/ArduinoECCX08/utility/ASN1Utils.cpp.o
Compiling .pio/build/mkr_wifi1010/lib889/ArduinoECCX08/utility/ECCX08CSR.cpp.o
In file included from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/PropertyContainer.h:51:0,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/CBORDecoder.h:31,
                 from .pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/ArduinoIoTCloud.h:35,
                 from src/thingproperties.h:4,
                 from src/main.cpp:3:
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h: In member function 'virtual void CloudTelevision::setAttributesFromCloud()':
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h:229:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       setAttribute((int&)_cloud_value.pbc, "pbc");
                                       ^~~
.pio/libdeps/mkr_wifi1010/ArduinoIoTCloud/src/cbor/../property/types/automation/CloudTelevision.h:230:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
       setAttribute((int&)_cloud_value.inp, "inp");
                                       ^~~
*** [.pio/build/mkr_wifi1010/src/main.cpp.o] Error 1

It is strange that it found the library even though you have it in this field.

This is what confusing me and this is the reason why i think that there is a problem with the build in libraries, because the mkr board in platformio is coming with wifi libraries:

Yes... i cleaned up the project and rebuild it several times.

Do you have a copy of the WiFi101 library stored in the lib subfolder of your project?

I'm quite out of my depth when it comes to PlatformIO so if any of the other forum helpers have experience with PlatformIO, please feel free to jump in (as you would be in any case, but especially so here :slight_smile: ).

Nope. The dirs "lib" and "include" are empty. Basically they are made for including external libraries but it's recommended to do the lib includes through the platformio.ini. But the very strange thing is: If i try to paste the lib (ArduinoCloudIoT or WifiNINA) by git clone into the "lib" dir the compiler isn't recognizing it, But in my projects with AVR Boards it works fine.

Are you absolutely set on using PlatformIO? I'm confident you wouldn't have this problem if you used one of Arduino's development tools (Arduino IDE, Arduino CLI, Arduino Cloud Editor).

If you don't like Arduino's tools, I think you would also have success using Microsoft's "Arduino" extension for VS Code / VSCodum, since it uses Arduino CLI to compile the sketch.

You will also be likely to get more help here when using one of Arduino's tools simply because more of the helpers have experience using them (though I know that some of the helpers use PlatformIO as well).

But that isn't to say that you are necessarily out of luck if you won't switch tools. I'm only mentioning a potential solution.

Nevertheless thank you that you tried to help me :slight_smile:

But good news. I found it and now i can compile it. Sometime it's helpfull to read the docs :smiley:

I have read up on the handling of the library dependency finding of PlatformIO because i already assumed that something went wrong with the library linking.

https://docs.platformio.org/en/latest/librarymanager/ldf.html#ldf-mode

I was able to compile it with lib_ldf_mode = chain and listing the dependencies of ArduinoCloud manually in the platformio.ini

[platformio]

[env:mkr_wifi1010]
platform = atmelsam
board = mkrwifi1010
framework = arduino
lib_deps = 
	z3t0/IRremote@^4.4.0  # Not necessary for Arduino Cloud - only for my use case

	# Arduino Cloud and all dependencies
	ArduinoIoTCloud
	Arduino_ConnectionHandler
	Arduino_DebugUtils
	WiFiNINA
	ArduinoMqttClient
	Arduino_SecureElement
	ArduinoECCX08
	Wire
	SPI
	SNU 
	ArduinoHttpClient
	RTCZero
	Adafruit SleepyDog Library

board_build.mcu = samd21g18a	# not necessary for Arduino Cloud
board_build.f_cpu = 48000000L # not necessary for Arduino Cloud
upload_protocol = sam-ba 		# not necessary for Arduino Cloud

lib_ldf_mode = chain 
2 Likes