Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ArduinoOTA and examples with MDNS.update() calls #5494

Merged
merged 6 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions libraries/ArduinoOTA/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ArduinoOTAClass::ArduinoOTAClass()
, _udp_ota(0)
, _initialized(false)
, _rebootOnSuccess(true)
, _useMDNS(true)
, _state(OTA_IDLE)
, _size(0)
, _cmd(0)
Expand Down Expand Up @@ -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());
Expand All @@ -127,12 +130,15 @@ void ArduinoOTAClass::begin() {
if(!_udp_ota->listen(IP_ADDR_ANY, _port))
return;
_udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this));
MDNS.begin(_hostname.c_str());

if (_password.length()) {
MDNS.enableArduino(_port, true);
} else {
MDNS.enableArduino(_port);
if(_useMDNS) {
MDNS.begin(_hostname.c_str());

if (_password.length()) {
MDNS.enableArduino(_port, true);
} else {
MDNS.enableArduino(_port);
}
}
_initialized = true;
_state = OTA_IDLE;
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions libraries/ArduinoOTA/ArduinoOTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,6 +76,7 @@ class ArduinoOTAClass
UdpContext *_udp_ota;
bool _initialized;
bool _rebootOnSuccess;
bool _useMDNS;
ota_state_t _state;
int _size;
int _cmd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ void loop() {
WiFi.disconnect();
}
}
if (s == WL_CONNECTED) {
MDNS.update();
}
}
// Do work:
//DNS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ void loop() {
if (last_state != AVRISP_STATE_IDLE) {
avrprog.serve();
}

if (WiFi.status() == WL_CONNECTED) {
MDNS.update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ void setup()
void loop()
{
httpServer.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,5 @@ void setup() {

void loop() {
httpServer.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ void setup(void) {

void loop(void) {
httpServer.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ void setup(void) {

void loop(void) {
httpServer.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}

void drawGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ void setup(void){

void loop(void){
server.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ void setup(void) {

void loop(void) {
server.handleClient();
delay(1);
MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,5 @@ void setup() {
void loop() {
// Handle OTA server.
ArduinoOTA.handle();
yield();
}

Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ void setup() {

void loop() {
// put your main code here, to run repeatedly:

MDNS.update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void setup(void) {
}

void loop(void) {

MDNS.update();

// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
Expand Down