Compiling with both SinricPro and ArduinoOTA

I am using the Arduino Nano 33 IOT with Web Editor (although I have also tried with Arduino IDE 2.2.1). My goal is to use SinricPro to enable Google Home voice commands and to use ArduinoOTA for program updates. My C++ knowledge is weak.

I have successfully implemented both features in separate sketches but I am unable to combine them. The code below compiles fine:

#include <WiFiNINA_Generic.h>
//#include <WiFiNINA.h>

#include <SinricPro_Generic.h>
//#include <ArduinoOTA.h>

void setup() {}

void loop() {
  SinricPro.handle();
  //  ArduinoOTA.poll();
}

As does this code:

//#include <WiFiNINA_Generic.h>
#include <WiFiNINA.h>

//#include <SinricPro_Generic.h>
#include <ArduinoOTA.h>

void setup() {}

void loop() {
  // SinricPro.handle();
  ArduinoOTA.poll();
}

It seems that Sinric will only compile with WiFiNINA_Generic.h while ArduinoOTA will only compile with WiFiNINA.h. Removing all comments (including both WiFiNINA_Generic.h and WiFiNINA.h). causes many redeclaration errors. If I do not include WiFiNINA.h, I get a "ArduinoOTA was not declared in this scope error".

Please help!

add

#define WiFiNINA_h

before #include <ArduinoOTA.h>

Thank you very much for responding Juraj.

Unfortunately, I still can't get this to complile.

I placed the
#define WiFiNINA_h
line, in every location I could think of but could not get rid of the errors.

If I include
#include <WiFiNINA.h>
then I get multiple redeclaration errors, the first being 'redeclaration of 'WL_NO_SHIELD"'.

If I do not include
#include <WiFiNINA.h>
then I get the error: redefinition of 'class WiFiUDP' class WiFiUDP : public UDP {

Maybe I created these problems by not understanding what you meant in your troubleshooting section. I was getting the error "'ArduinoOTA' was not declared in this scope" and saw the advice below:

'ArduinoOTA' was not declared in this scope - make sure a networking library is included before the ArduinoOTA.h include

I did not know what that meant so I included the WiFiNINA.h file and the error went away. Was this the wrong file?

I thought you must use the Generic WiFiNINA

Hi Juraj,

I am not sure what you mean. I am guessing that Sinric uses WiFiNINA_Generic and ArduinoOTA uses WiFiNINA and I cannot have both libraries in the same sketch. I am also guessing that the #define WiFiNINA_h statement somehow allows ArduinoOTA to use WiFiNINA_Generic but I was unable to figure out how it does that.

The following code:

#include <SinricPro_Generic.h>
#define WiFiNINA_h
#include <ArduinoOTA.h>

void setup() {}

void loop() {
  SinricPro.handle();
  ArduinoOTA.poll();
}

produces the following error: redefinition of 'class WiFiUDP'
class WiFiUDP : public UDP

I am a newbie. Can you please explain what is happening here or provide me with a snippet that will compile?

Many thanks,
Rod

you forgot #include <WiFiNINA_Generic.h>

Sorry, I am pretty sure that <SinricPro_Generic.h> includes <WifiNINA_Generic.h> so I left it out.

The results are exactly the same with or without it so I was trying to boil it down to the minimum lines of code - my bad.

Here is the corrected code:

#include <WiFiNINA_Generic.h>
#include <SinricPro_Generic.h>
#define WiFiNINA_h
#include <ArduinoOTA.h>


void setup() {}

void loop() {
  SinricPro.handle();
  ArduinoOTA.poll();
}

The results are the same, it still produces the following error: redefinition of 'class WiFiUDP'
class WiFiUDP : public UDP

in library in ArduinoOTA.h remove on line 135 #include <WiFiUdp.h>

Thank you very much Juraj, your solution works. And I can now compile the code. Running it is still giving me grief but I will investigate that further before reporting.

Any deeper insight into this compiler problem would be greatly appreciated as I am now encountering the same problem when I include the EMailSender library. I have poked around in EMailSender.h to see if a similar fix might be available but I cannot figure it out.

Is it correct that my problems basically stemmed from including both WiFiNINA and WiFiNINA_Generic and that the fix you provided allowed ArduinoOTA to use WiFiNINA_Generic? Is it likely that I can convince EMailSender to do the same thing?

Thanks again for all of your help

WiFiNINA_Generic has wrong file names. All WiFi libraries have WiFiClient.h and WiFiUdp.h, but WiFiNINA_Generic has only WiFiClient_Generic.h and WiFiUdp_Generic.h