Skip to content

Commit b1c60b4

Browse files
committed
ArduinoOTA.h - support any proper Arduino networking library
1 parent a497a34 commit b1c60b4

File tree

8 files changed

+26
-28
lines changed

8 files changed

+26
-28
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ The library is a modification of the Arduino WiFi101OTA library.
3636

3737
## Supported networking libraries
3838

39+
The ArduinoOTA library will work any proper Arduino Ethernet or WiFi library. For Ethernet library add `#define OTETHERNET` before including the ArduinoOTA library. If you don't want a network port or the library doesn't support it, add `#define NO_OTA_PORT` before including the ArduinoOTA library. If you only want to use InternalStorage without the network upload from IDE, add `#define NO_OTA_NETWORK` before including the ArduinoOTA library.
40+
41+
Tested libraries are:
3942
* Ethernet library - Ethernet shields and modules with Wiznet 5100, 5200 and 5500 chips
4043
* WiFi101 - MKR 1000, Arduino WiFi101 shield and Adafruit WINC1500 WiFi shield or module
4144
* WiFiNINA - MKR 1010, MKR 4000, Nano 33 IoT and any supported MCU with attached ESP32 as SPI network adapter with WiFiNINA firmware
@@ -44,7 +47,7 @@ The library is a modification of the Arduino WiFi101OTA library.
4447
* EthernetENC - shields and modules with ENC28j60 chip
4548
* WiFi library of the Pico Core including its Ethernet network interfaces
4649

47-
EthernetENC library doesn't support UDP multicast for MDNS, so Arduino IDE will not show the network upload port.
50+
EthernetENC and WiFiEspAT with esp8266 doesn't support UDP multicast for MDNS, so Arduino IDE will not show the network upload port.
4851

4952
## Installation
5053

@@ -68,7 +71,7 @@ For upload the 'OTA programmer' technique can be configured.
6871

6972
## OTA Upload from IDE without 'network port'
7073

71-
Some of the supported networking libraries don't have the UDP.beginMulticast function and can't start a MDNS service to propagate the network port for Arduino IDE. And sometimes the MDNS port is not detected for the good libraries too. Arduino IDE doesn't yet allow to enter the IP address.
74+
Some networking libraries don't have the UDP.beginMulticast function and can't start a MDNS service to propagate the network port for Arduino IDE. And sometimes the MDNS port is not detected for the good libraries too. Arduino IDE doesn't yet allow to enter the IP address.
7275

7376
The workaround is to configure a fake programmer for Arduino OTA. You can use [my_boards](https://github.com/jandrassy/my_boards) as starting point. For Arduino Mega it is the best option for all ArduinoOTA aspects, for other boards it gives you control about your custom settings. In your copy of my_boards in programmers.txt, configure the IP address and restart the IDE. Note: the esp boards packages can't be used as referenced packages in my_boards style.
7477

examples/ATmega_SD/ATmega_SD.ino

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <SPI.h>
2121
#include <SD.h>
2222
#include <Ethernet.h>
23+
#define OTETHERNET
2324
#include <ArduinoOTA.h>
2425

2526
// Enter a MAC address for your controller below.

examples/Advanced/OTASketchDownload/OTASketchDownload.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
by Juraj Andrassy
1717
*/
1818

19-
#include <ArduinoOTA.h> // only for InternalStorage
2019
#include <Ethernet.h>
2120
#include <ArduinoHttpClient.h>
2221

22+
#define NO_OTA_NETWORK
23+
#include <ArduinoOTA.h> // only for InternalStorage
24+
2325
const short VERSION = 1;
2426

2527
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

examples/Advanced/OTASketchDownloadWifi/OTASketchDownloadWifi.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
based on Juraj Andrassy sample sketch 'OTASketchDownload'
2121
*/
2222

23-
#include <ArduinoOTA.h> // only for InternalStorage
2423
#include <WiFiNINA.h>
2524
#include <ArduinoHttpClient.h>
2625

26+
#define NO_OTA_NETWORK
27+
#include <ArduinoOTA.h> // only for InternalStorage
28+
2729
// Please enter your WiFi sensitive data in the arduino_secrets.h file
2830
#include "arduino_secrets.h"
2931

examples/Advanced/SD2Flash2BootAVRHex/SD2Flash2BootAVRHex.ino

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
by Juraj Andrassy
1111
*/
1212

13+
#define NO_OTA_NETWORK
1314
#include <ArduinoOTA.h> // include before SD.h (to not intialize SDStorage)
1415
#include <SD.h>
1516
#include "kk_ihex_read.h"

examples/OTEthernet/OTEthernet.ino

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <SPI.h>
2121
#include <Ethernet.h>
22+
#define OTETHERNET
2223
#include <ArduinoOTA.h>
2324

2425
//#define Serial SerialUSB

examples/OTEthernet_SD/OTEthernet_SD.ino

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <SPI.h>
2121
#include <SD.h>
2222
#include <Ethernet.h>
23+
#define OTETHERNET
2324
#include <ArduinoOTA.h>
2425
#include <SDU.h>
2526

src/ArduinoOTA.h

+11-24
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,32 @@ class ArduinoOTAMdnsClass : public ArduinoOTAClass<NetServer, NetClient> {
116116

117117
};
118118

119-
#if defined(NO_OTA_NETWORK)
120-
// Disable network libraries
121-
#elif defined(ethernet_h_) || defined(ethernet_h) // Ethernet library
119+
#ifndef NO_OTA_NETWORK
120+
121+
#if defined(ethernet_h_) || defined(ethernet_h) || defined(UIPETHERNET_H)
122+
#define OTETHERNET
123+
#endif
124+
#if defined(UIPETHERNET_H) || defined(WIFIESPAT1) // no UDP multicast implementation
125+
#define NO_OTA_PORT
126+
#endif
127+
128+
#ifdef OTETHERNET
122129
#ifdef NO_OTA_PORT
123130
ArduinoOTAClass <EthernetServer, EthernetClient> ArduinoOTA;
124131
#else
125132
ArduinoOTAMdnsClass <EthernetServer, EthernetClient, EthernetUDP> ArduinoOTA;
126133
#endif
127134

128-
#elif defined(UIPETHERNET_H) // no UDP multicast implementation yet
129-
ArduinoOTAClass <EthernetServer, EthernetClient> ArduinoOTA;
130-
131-
#elif defined(WiFiNINA_h) || defined(WIFI_H) || defined(WiFiS3_h) || defined(ESP8266) || defined(ESP32) // NINA, WiFi101 and Espressif WiFi
132-
#ifdef NO_OTA_PORT
133-
ArduinoOTAClass <WiFiServer, WiFiClient> ArduinoOTA;
134135
#else
135-
#include <WiFiUdp.h>
136-
ArduinoOTAMdnsClass <WiFiServer, WiFiClient, WiFiUDP> ArduinoOTA;
137-
#endif
138-
139-
#elif defined(_WIFI_ESP_AT_H_) && !defined(WIFIESPAT1) && !defined(NO_OTA_PORT) // WiFiEspAT with AT2 has UDP multicast
140-
ArduinoOTAMdnsClass <WiFiServer, WiFiClient, WiFiUDP> ArduinoOTA;
141-
142-
#elif defined(WiFi_h) || defined(_WIFI_ESP_AT_H_) // WiFi, WiFiLink and WiFiEspAT lib (no UDP multicast) for WiFiLink the firmware handles mdns
143-
ArduinoOTAClass <WiFiServer, WiFiClient> ArduinoOTA;
144-
145-
#elif defined(_WIFISPI_H_INCLUDED) // no UDP multicast implementation
146-
ArduinoOTAClass <WiFiSpiServer, WiFiSpiClient> ArduinoOTA;
147136

148-
#elif defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)
149137
#ifdef NO_OTA_PORT
150138
ArduinoOTAClass <WiFiServer, WiFiClient> ArduinoOTA;
151139
#else
152140
#include <WiFiUdp.h>
153141
ArduinoOTAMdnsClass <WiFiServer, WiFiClient, WiFiUDP> ArduinoOTA;
154142
#endif
143+
#endif
155144

156-
#else
157-
#warning "Network library not included or not supported"
158145
#endif
159146

160147
#endif

0 commit comments

Comments
 (0)