Hi.
No doubt the OTA is very good tool. Fed up of removing boards from a place, bring them to the PC and upload corrected code....
So, I succeeded to make a capsulated templates that can be very easily tailored to any code, providing that the board is with WiFi capabilities (8266 or 32 eg.). Only I had to add it to an existing ISP network or separate mesh network.
I would like to share this experience here....
A. In the main .ino file the following must be added:
#include "b_OTA_constants.h" // local header file that contains network credentials and board IDs, specific to the your particular board code.
#include "OTA.h" // a header template that lives in your /libraries folder (refer to IDE-File-Preferences....)
B. In setup() function the following is added:
setups_OTA(otaConfig); // refers to OTA.h
C. In loops() function the following is added:
OTA_handle(); // refers to OTA.h
D. In your /libraries folder there is also a header named OTA.cpp
E. The b_OTA_constants.h structure is as follows:
(Remark: the 'b_' prefix is only to position the header file bellow the main .ino in the explorer, while the sketch name main .ino is prefixed 'a_'. Just for convenience, for nothing else)
#pragma once
#include <OTA.h>
static const OTAConfig otaConfig {
"network_ssid",
"network_password",
IPAddress(XXX, XXX, XXX, XXX), // board assigned IP
IPAddress(XXX, XXX, XX, X), // gateway
IPAddress(255, 255, 255, 0), // subnet
"ota_password",
"host_name",
ota_port
};
That's it!
- Just tailor the above to your code,
- perform initial upload via USB,
- open serial to verify the OTA is configured properly
- then fix the board to your project PCB
and update your current code if mecessary.
If interested, I am always ready to share all details here, or discuss any ideas for improvement...