Hello All,
My project has progressed some from here: Nano 33 iot RTC DS3231 and Low Power library, eventually with ArduinoOTA - Programming Questions - Arduino Forum
I am now having problems integrating the ArduinoOTA portion. I only want to connect to the wifi network when the relays are ON, the Arduino is not in low power mode.
I have a modified Arduino IDE v1.8.12, as per here: OTA_Mode - No Network port is shown ! - Installation & Troubleshooting - Arduino Forum
I can see the Arduino when it only has the Example OTA sketch.
I need to be able to update the sketch via wifi as the Arduino will be in a sealed box. Yes, my arduino_secrets.h is filled in properly. Don't bother with the "Reboot your router or restart Arduino IDE". I have done both of those, no change.
My problem is that the port never shows up in my Arduino IDE, using my sketch. It shows up every time using the example sketch. I still only want it to connect to wifi when the relayPin is LOW / Arduino is awake.
/*
Pins:
7 - relay pin, active LOW
SDA - Ext RTC
SCL - Ext RTC
Turns on a relay at a set time of day for a certain length of time
Updated to sketch via wifi. Uses an external RTC (DS3231) to set the time on the nano's RTC. Uses the Nano's RTC to set an alarm for a specific time.
*/
#include <RTCZero.h>
#include <RTClib.h>
#include <WiFiNINA.h>
#include <ArduinoOTA.h>
#include "arduino_secrets.h"
/////please enter your sensitive data in the Secret tab/arduino_secrets.h
///// Wifi Settings ///////
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int status = WL_IDLE_STATUS;
/* Create an rtc object */
RTCZero rtc;
RTC_DS3231 extrtc;
///* Change these values to set the current initial time */
//const byte seconds = 0;
//const byte minutes = 00;
//const byte hours = 17;
//
///* Change these values to set the current initial date */
//const byte day = 17;
//const byte month = 11;
//const byte year = 15;
boolean awake = false;
const int relayPin = 7; // use this pin to drive the Relays
const long timeON = 600000;
//21600000;
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setAlarm () {
rtc.setAlarmTime(15, 22, 00);
rtc.enableAlarm(rtc.MATCH_HHMMSS);
rtc.attachInterrupt(alarmMatch);
}
void setup()
{
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
Serial.begin(115200);
if (! extrtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (extrtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
extrtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// setSyncProvider(extrtc.get); // the function to get the time from the RTC
DateTime now = extrtc.now();
rtc.begin();
rtc.setTime(now.hour(), now.minute(), now.second());
rtc.setDate(now.day(), now.month(), now.year());
setAlarm();
rtc.standbyMode();
}
void loop()
{
if (awake) {
Serial.begin(115200);
digitalWrite(relayPin, LOW);
digitalWrite(LED_BUILTIN, HIGH);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
}
long timeSoFar = 0;
while (timeSoFar < timeON) {
// start the WiFi OTA library with internal (flash) based storage
ArduinoOTA.begin(WiFi.localIP(), "Arduino nano 33 iot", "Eastwind3", InternalStorage);
ArduinoOTA.poll();
// you're connected now, so print out the status:
printWifiStatus();
delay(60000);
timeSoFar -= 60000;
}
// delay(timeON); //3 hours in ms, 10800000
Serial.println("Alarm Match!");
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(relayPin, HIGH);
awake = false;
}
rtc.standbyMode(); // Sleep until next alarm match
}
void alarmMatch()
{
awake = true;
}