Hi all, I'm having a problem compiling the code below for a MKF wifi 1010. This code did work and compile, but now I get the following error below. I'm a bit confused as I don't have #include "wifi.h"
in the code? This happens on both my Mac and MacBook, but if I pull the sketch onto my windows 10 pc it works perfectly? I do have ESP32 sketches I'm working on in my cloud account that use this library. Any help or pointers would be appreciated.
In file included from /Users/steves/Library/Arduino15/RemoteSketchbook/ArduinoCloud/bcb5ccf2-2dda-472c-a448-6a408a893a0d/Hornet_detect_current_version/Hornet_detect_current_version.ino:10:0:
/Users/steves/Documents/Arduino/libraries/WiFiNINA/src/WiFiNINA.h:23:10: fatal error: WiFi.h: No such file or directory
#include "WiFi.h"
^~~~~~~~
compilation terminated.
exit status 1
Compilation error: exit status 1
this is the code:
#include "arduino_secrets.h"
/*Hornet_detect
This is the project code for use with an Arduino MKR wifi 1010 and ESP32 CAM to create an Asian Hornet
detector
*/
#include "ArduinoLowPower.h"
#include <WiFiNINA.h>
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int wifistatus = WL_IDLE_STATUS; // the Wifi radio's status
int DaylightPin = 8; //Interrupt pin taking a high to low from photoresistor
int BandpassControl = 1; //pin to switch on/off BP filter
int IRDetectControl = 2; //output pin to control IR detector
int IRDetectOutput = 3; //Pin to receive HIGH/LOW output from IR detector
int ESP32CAMControl = 4; //output pin to control CAM module
int Detect115hzPin = 7; //input for pulse output of BP filter
int HornetFrequency = 0; // Variable to store frequency of Hornet
int countUp = 0; // counter for 115hz detector
int durationTotal = 0; // Variable to store both HIGH and LOW pulse widths
unsigned long durationHigh; // Pulse HIGH variable
unsigned long durationLow; // Pulse LOW variable
void setup() {
// initialize serial communication at 9600 bits per second
Serial.begin(9600);
while (!Serial)
; //program won't run until the serial port is connected
pinMode(DaylightPin, INPUT_PULLUP); // configures interrupt pin 8 as input for photoresistor output
pinMode(BandpassControl, OUTPUT); //sets pin 1 to an output to turn on BP filter & Mic
//pinmode(115hzDetect,INPUT); // sets pin 7 as input for reading the pulse length of the signal from the BP filter
pinMode(IRDetectControl, OUTPUT); // sets pin 2 to output pin to control the IR sensor
pinMode(IRDetectOutput, INPUT); //sets pin 3 as input for the IR module detect signal
pinMode(ESP32CAMControl, OUTPUT); //sets pin 4 as deepsleep/wake control for CAM module
pinMode(Detect115hzPin, INPUT); // Sets pin 7 as 115hz pulse input
//This interrupt is waiting for a change from HIGH to LOW from photoresistor, then calls Wakeup:
LowPower.attachInterruptWakeup(DaylightPin, Wakeup, FALLING);
}
void loop() { // Need some code here to detect whether it is daylight or not. If night then goto
// BoardSleep and if dayligjht goto TurnOnWifi
Serial.println("Starting program");
if (digitalRead(DaylightPin) == LOW) { // LOW from Photoresistor = Daylight
Serial.println("Turning on BP filter");
delay(3000);
digitalWrite(BandpassControl, HIGH); //Turn on BP filter via MOSFET
delay(1000);
goto Detect115hz;
} else
BoardSleep:
delay(1000);
if (wifistatus == WL_CONNECTED) {
WiFi.disconnect();
Serial.println("Disconnecting WiFi");
delay(2000);
}
TurnOffModules:
Serial.println("Turning off WiFi module");
delay(2000);
WiFi.end(); //Turn off WiFi module
digitalWrite(IRDetectControl, LOW); //Turn off IR detector
Serial.println("Turning off IR detector");
delay(2000);
digitalWrite(ESP32CAMControl, LOW); //ESP32 CAM module deepsleep
Serial.println("Putting ESP32 CAM into deepsleep");
delay(2000);
digitalWrite(BandpassControl, LOW); // Turns off BP filter + Mic
Serial.println("Turning off BP filter");
delay(2000);
// put board to sleep
Serial.println("Board asleep");
LowPower.deepSleep();
// turn on BP filter and Microphone on wake up then goto Detect115hz
delay(2000);
Serial.println("Turning on BP filter");
digitalWrite(BandpassControl, HIGH); //Turn on BP filter
delay(1000);
Detect115hz:
// Hornet tone detection code. If hornet tone is detected the first time for more than 2 seconds
// then turn on all modules and connect wifi. When Wifi & modules are switched on then go direct to
// IRDetect
Serial.println("Waiting for Hornets...");
countUp = 1;
//delay(1000);
Detect115hzStart:
if (countUp == 10) {
digitalWrite(BandpassControl, LOW); // Turns off BP filter + Mic
goto TurnOnWiFi;
} else
durationHigh = pulseIn(Detect115hzPin, HIGH);
durationLow = pulseIn(Detect115hzPin, LOW);
durationTotal = durationHigh + durationLow;
HornetFrequency = 1000000 / durationTotal;
//if (durationTotal == 0) {
if (HornetFrequency < 104 || HornetFrequency > 126) {
countUp = 1;
goto Detect115hzStart;
} else
//HornetFrequency = 1000000 / durationTotal;
if (HornetFrequency > 104 && HornetFrequency < 126) {
Serial.print(HornetFrequency);
Serial.print(" ");
Serial.println(countUp);
delay(200);
countUp++;
//Serial.println(countUp);
goto Detect115hzStart;
} else
goto Detect115hzStart;
TurnOnWiFi:
if (wifistatus == WL_CONNECTED) {
goto IRDetect;
} else
//Serial.println("Turning on wifi module");
//while (wifistatus != WL_CONNECTED) { // attempt to connect to Wifi network
Serial.println("Turning on wifi module");
delay(2000);
Serial.print("Attempting to connect to network: ");
Serial.println(ssid);
while (wifistatus != WL_CONNECTED) { //Loop until connected to Wifi network
wifistatus = WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network:
if (wifistatus == WL_CONNECTED) {
Serial.println("WiFi Connected");
} else
Serial.println("WiFi not connected");
//delay(10000);
}
//}
delay(2000);
Serial.println("Turning on IR detector");
digitalWrite(IRDetectControl, HIGH); //Turn on IR detector
delay(2000);
Serial.println("Turning on CAM module");
digitalWrite(ESP32CAMControl, HIGH); //Turn on CAM module
delay(2000);
IRDetect: //Hornet LOS detect to activate Trigger for CAM module only when there is a stable 2 second
//115hz hornet tone and a IR detection signal.
delay(1000);
Serial.println("Waiting for IR detection");
StartIRDetect:
if (digitalRead(IRDetectOutput) == HIGH) {
goto Trigger;
} else
goto StartIRDetect;
Trigger: //This will be where the CAM module is triggered to take a picture
Serial.println("Trap triggered!");
if (digitalRead(DaylightPin) == HIGH) { // Would normally be HIGH with low light and
// LOW with day light but is LOW for test purposes
delay(2000);
goto BoardSleep;
} else
WiFi.end(); //Turn off WiFi module
digitalWrite(IRDetectControl, LOW);
digitalWrite(BandpassControl, HIGH); // Turns on BP filter + Mic
goto Detect115hz; //Detect115hzStart;
}
// This function will be called once on device wakeup
// Remeber this function(s) executes in interrupt context not in the main loop
void Wakeup() {
Serial.println("Board awake");
}