mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
WIP - Update ArduinoOTA and examples with MDNS.update() calls (#5494)
* ArduinoOTA: allow use without MDNS, add MDNS.update() in handle() * Update examples with MDNS.update() in loop * Update CaptivePortalAdvanced.ino Fix typo * Update CaptivePortalAdvanced.ino astyle * Update Arduino_Wifi_AVRISP.ino astyle
This commit is contained in:
parent
8ede8f1459
commit
e9d052c621
@ -33,6 +33,7 @@ ArduinoOTAClass::ArduinoOTAClass()
|
||||
, _udp_ota(0)
|
||||
, _initialized(false)
|
||||
, _rebootOnSuccess(true)
|
||||
, _useMDNS(true)
|
||||
, _state(OTA_IDLE)
|
||||
, _size(0)
|
||||
, _cmd(0)
|
||||
@ -103,10 +104,12 @@ void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
|
||||
_rebootOnSuccess = reboot;
|
||||
}
|
||||
|
||||
void ArduinoOTAClass::begin() {
|
||||
void ArduinoOTAClass::begin(bool useMDNS) {
|
||||
if (_initialized)
|
||||
return;
|
||||
|
||||
_useMDNS = useMDNS;
|
||||
|
||||
if (!_hostname.length()) {
|
||||
char tmp[15];
|
||||
sprintf(tmp, "esp8266-%06x", ESP.getChipId());
|
||||
@ -127,6 +130,8 @@ void ArduinoOTAClass::begin() {
|
||||
if(!_udp_ota->listen(IP_ADDR_ANY, _port))
|
||||
return;
|
||||
_udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this));
|
||||
|
||||
if(_useMDNS) {
|
||||
MDNS.begin(_hostname.c_str());
|
||||
|
||||
if (_password.length()) {
|
||||
@ -134,6 +139,7 @@ void ArduinoOTAClass::begin() {
|
||||
} else {
|
||||
MDNS.enableArduino(_port);
|
||||
}
|
||||
}
|
||||
_initialized = true;
|
||||
_state = OTA_IDLE;
|
||||
#ifdef OTA_DEBUG
|
||||
@ -348,11 +354,15 @@ void ArduinoOTAClass::_runUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
//this needs to be called in the loop()
|
||||
void ArduinoOTAClass::handle() {
|
||||
if (_state == OTA_RUNUPDATE) {
|
||||
_runUpdate();
|
||||
_state = OTA_IDLE;
|
||||
}
|
||||
|
||||
if(_useMDNS)
|
||||
MDNS.update(); //handle MDNS update as well, given that ArduinoOTA relies on it anyways
|
||||
}
|
||||
|
||||
int ArduinoOTAClass::getCommand() {
|
||||
|
@ -60,9 +60,9 @@ class ArduinoOTAClass
|
||||
void onProgress(THandlerFunction_Progress fn);
|
||||
|
||||
//Starts the ArduinoOTA service
|
||||
void begin();
|
||||
void begin(bool useMDNS = true);
|
||||
|
||||
//Call this in loop() to run the service
|
||||
//Call this in loop() to run the service. Also calls MDNS.update() when begin() or begin(true) is used.
|
||||
void handle();
|
||||
|
||||
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
|
||||
@ -76,6 +76,7 @@ class ArduinoOTAClass
|
||||
UdpContext *_udp_ota;
|
||||
bool _initialized;
|
||||
bool _rebootOnSuccess;
|
||||
bool _useMDNS;
|
||||
ota_state_t _state;
|
||||
int _size;
|
||||
int _cmd;
|
||||
|
@ -130,6 +130,9 @@ void loop() {
|
||||
WiFi.disconnect();
|
||||
}
|
||||
}
|
||||
if (s == WL_CONNECTED) {
|
||||
MDNS.update();
|
||||
}
|
||||
}
|
||||
// Do work:
|
||||
//DNS
|
||||
|
@ -70,4 +70,8 @@ void loop() {
|
||||
if (last_state != AVRISP_STATE_IDLE) {
|
||||
avrprog.serve();
|
||||
}
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
MDNS.update();
|
||||
}
|
||||
}
|
||||
|
@ -119,4 +119,5 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
httpServer.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -188,4 +188,5 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
httpServer.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -47,4 +47,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
httpServer.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -44,4 +44,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
httpServer.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
||||
void drawGraph() {
|
||||
|
@ -282,4 +282,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -75,4 +75,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -144,4 +144,5 @@ void setup(void){
|
||||
|
||||
void loop(void){
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -181,4 +181,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -315,4 +315,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -70,5 +70,5 @@ void setup(void) {
|
||||
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
delay(1);
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -238,6 +238,5 @@ void setup() {
|
||||
void loop() {
|
||||
// Handle OTA server.
|
||||
ArduinoOTA.handle();
|
||||
yield();
|
||||
}
|
||||
|
||||
|
@ -76,5 +76,5 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
MDNS.update();
|
||||
}
|
||||
|
@ -72,6 +72,9 @@ void setup(void) {
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
|
||||
MDNS.update();
|
||||
|
||||
// Check if a client has connected
|
||||
WiFiClient client = server.available();
|
||||
if (!client) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user