1
0
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:
Develo 2018-12-14 03:29:32 -03:00 committed by GitHub
parent 8ede8f1459
commit e9d052c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 41 additions and 11 deletions

View File

@ -33,6 +33,7 @@ ArduinoOTAClass::ArduinoOTAClass()
, _udp_ota(0) , _udp_ota(0)
, _initialized(false) , _initialized(false)
, _rebootOnSuccess(true) , _rebootOnSuccess(true)
, _useMDNS(true)
, _state(OTA_IDLE) , _state(OTA_IDLE)
, _size(0) , _size(0)
, _cmd(0) , _cmd(0)
@ -103,10 +104,12 @@ void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
_rebootOnSuccess = reboot; _rebootOnSuccess = reboot;
} }
void ArduinoOTAClass::begin() { void ArduinoOTAClass::begin(bool useMDNS) {
if (_initialized) if (_initialized)
return; return;
_useMDNS = useMDNS;
if (!_hostname.length()) { if (!_hostname.length()) {
char tmp[15]; char tmp[15];
sprintf(tmp, "esp8266-%06x", ESP.getChipId()); sprintf(tmp, "esp8266-%06x", ESP.getChipId());
@ -127,6 +130,8 @@ void ArduinoOTAClass::begin() {
if(!_udp_ota->listen(IP_ADDR_ANY, _port)) if(!_udp_ota->listen(IP_ADDR_ANY, _port))
return; return;
_udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this)); _udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this));
if(_useMDNS) {
MDNS.begin(_hostname.c_str()); MDNS.begin(_hostname.c_str());
if (_password.length()) { if (_password.length()) {
@ -134,6 +139,7 @@ void ArduinoOTAClass::begin() {
} else { } else {
MDNS.enableArduino(_port); MDNS.enableArduino(_port);
} }
}
_initialized = true; _initialized = true;
_state = OTA_IDLE; _state = OTA_IDLE;
#ifdef OTA_DEBUG #ifdef OTA_DEBUG
@ -348,11 +354,15 @@ void ArduinoOTAClass::_runUpdate() {
} }
} }
//this needs to be called in the loop()
void ArduinoOTAClass::handle() { void ArduinoOTAClass::handle() {
if (_state == OTA_RUNUPDATE) { if (_state == OTA_RUNUPDATE) {
_runUpdate(); _runUpdate();
_state = OTA_IDLE; _state = OTA_IDLE;
} }
if(_useMDNS)
MDNS.update(); //handle MDNS update as well, given that ArduinoOTA relies on it anyways
} }
int ArduinoOTAClass::getCommand() { int ArduinoOTAClass::getCommand() {

View File

@ -60,9 +60,9 @@ class ArduinoOTAClass
void onProgress(THandlerFunction_Progress fn); void onProgress(THandlerFunction_Progress fn);
//Starts the ArduinoOTA service //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(); void handle();
//Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS //Gets update command type after OTA has started. Either U_FLASH or U_SPIFFS
@ -76,6 +76,7 @@ class ArduinoOTAClass
UdpContext *_udp_ota; UdpContext *_udp_ota;
bool _initialized; bool _initialized;
bool _rebootOnSuccess; bool _rebootOnSuccess;
bool _useMDNS;
ota_state_t _state; ota_state_t _state;
int _size; int _size;
int _cmd; int _cmd;

View File

@ -130,6 +130,9 @@ void loop() {
WiFi.disconnect(); WiFi.disconnect();
} }
} }
if (s == WL_CONNECTED) {
MDNS.update();
}
} }
// Do work: // Do work:
//DNS //DNS

View File

@ -70,4 +70,8 @@ void loop() {
if (last_state != AVRISP_STATE_IDLE) { if (last_state != AVRISP_STATE_IDLE) {
avrprog.serve(); avrprog.serve();
} }
if (WiFi.status() == WL_CONNECTED) {
MDNS.update();
}
} }

View File

@ -119,4 +119,5 @@ void setup()
void loop() void loop()
{ {
httpServer.handleClient(); httpServer.handleClient();
MDNS.update();
} }

View File

@ -188,4 +188,5 @@ void setup() {
void loop() { void loop() {
httpServer.handleClient(); httpServer.handleClient();
MDNS.update();
} }

View File

@ -47,4 +47,5 @@ void setup(void) {
void loop(void) { void loop(void) {
httpServer.handleClient(); httpServer.handleClient();
MDNS.update();
} }

View File

@ -44,4 +44,5 @@ void setup(void) {
void loop(void) { void loop(void) {
httpServer.handleClient(); httpServer.handleClient();
MDNS.update();
} }

View File

@ -130,6 +130,7 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
MDNS.update();
} }
void drawGraph() { void drawGraph() {

View File

@ -282,4 +282,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
MDNS.update();
} }

View File

@ -75,4 +75,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
MDNS.update();
} }

View File

@ -144,4 +144,5 @@ void setup(void){
void loop(void){ void loop(void){
server.handleClient(); server.handleClient();
MDNS.update();
} }

View File

@ -181,4 +181,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
MDNS.update();
} }

View File

@ -315,4 +315,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
MDNS.update();
} }

View File

@ -70,5 +70,5 @@ void setup(void) {
void loop(void) { void loop(void) {
server.handleClient(); server.handleClient();
delay(1); MDNS.update();
} }

View File

@ -238,6 +238,5 @@ void setup() {
void loop() { void loop() {
// Handle OTA server. // Handle OTA server.
ArduinoOTA.handle(); ArduinoOTA.handle();
yield();
} }

View File

@ -76,5 +76,5 @@ void setup() {
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
MDNS.update();
} }

View File

@ -72,6 +72,9 @@ void setup(void) {
} }
void loop(void) { void loop(void) {
MDNS.update();
// Check if a client has connected // Check if a client has connected
WiFiClient client = server.available(); WiFiClient client = server.available();
if (!client) { if (!client) {