Skip to content

Commit 5d4c788

Browse files
committed
Arduino: Automatic set advanced network config
when first value of dns or gateway is filled #268
1 parent cd3a2a0 commit 5d4c788

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

OpenMQTTGateway.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,14 @@ void setup_wifimanager(){
527527

528528
#else // Arduino case
529529
void setup_ethernet() {
530-
Ethernet.begin(mac, ip); //Comment and uncomment the following line if you want to use advanced network config
531-
//Ethernet.begin(mac, ip, Dns, gateway, subnet);
530+
if (gateway[0] != 0 || Dns[0]!=0)
531+
{
532+
trc(F("Advanced ethernet config"));
533+
Ethernet.begin(mac, ip, Dns, gateway, subnet);
534+
}else{
535+
trc(F("Simple ethernet config"));
536+
Ethernet.begin(mac, ip);
537+
}
532538
trc(F("OpenMQTTGateway ip: "));
533539
Serial.println(Ethernet.localIP());
534540
trc(F("Ethernet ok"));

User_config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ char mqtt_port[6] = "1883";
6868
#endif
6969

7070
const byte ip[] = { 192, 168, 1, 99 }; //ip adress
71-
// Advanced network config (optional) if you want to use these parameters uncomment line 158, 172 and comment line 171 of OpenMQTTGateway.ino
72-
const byte gateway[] = { 192, 168, 1, 1 }; //ip adress
73-
const byte Dns[] = { 192, 168, 1, 1 }; //ip adress
71+
const byte gateway[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
72+
const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
7473
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
7574

7675
/*-------------DEFINE YOUR OTA PARAMETERS BELOW----------------*/

0 commit comments

Comments
 (0)