I need to be able to upload sketches OTA over wifi because for my project the arduino will be located in a remote location and I need to be able to upload updates to the code remotely. However I can't figure out how to make it work...
I have tried a couple different libraries but from what I've read, the ArduinoOTA library is what should be used for this board. GitHub - JAndrassy/ArduinoOTA: Arduino library to upload sketch over network to Arduino board with WiFi or Ethernet libraries
I am already able to connect to wifi, can successfully communicate and receive data from the arduino over wifi. However, I still cannot upload a sketch OTA.
I'm using the example sketch from github, but changing to WiFiNINA library:
/*
This example connects to an WPA encrypted WiFi network.
Then it prints the MAC address of the Wifi shield,
the IP address obtained, and other network details.
It then polls for sketch updates over WiFi, sketches
can be updated by selecting a network port from within
the Arduino IDE: Tools -> Port -> Network Ports ...
Circuit:
* WiFi shield attached
created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe
modified 16 January 2017
by Sandeep Mistry
*/
#include <SPI.h>
#include <WiFiNINA.h>
#include <ArduinoOTA.h>
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
/////// Wifi Settings ///////
char ssid[] = "myssid"; // your network SSID (name)
char pass[] = "wifipassword"; // your network password
int status = WL_IDLE_STATUS;
void setup() {
//Initialize serial:
Serial.begin(9600);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// 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);
}
// start the WiFi OTA library with internal (flash) based storage
ArduinoOTA.begin(WiFi.localIP(), "Arduino", "password", InternalStorage);
// you're connected now, so print out the status:
printWifiStatus();
}
void loop() {
// check for WiFi OTA updates
ArduinoOTA.poll();
// add your normal loop code below ...
}
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");
}
This sketch uploads successfully over USB but then if I try to re-upload this sketch, or any other sketch from IDE after selecting the network port, it compiles but then just hangs indefinitely on:
"Sketch uses 63804 bytes (24%) of program storage space. Maximum is 262144 bytes.
Global variables use 4360 bytes of dynamic memory."
No error message or anything. If I connect USB and select the serial port, the sketch uploads fine.
Am I doing something wrong?