From f39422d23c303c24dfc55d9bf2b0388fec8a4758 Mon Sep 17 00:00:00 2001 From: 1technophile Date: Sat, 25 Mar 2017 21:25:23 +0100 Subject: [PATCH] Add advanced network parameters #31 --- OpenMQTTGateway.ino | 24 +++++++++++++++++++++--- User_config.h | 11 ++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/OpenMQTTGateway.ino b/OpenMQTTGateway.ino index 980457b..87b3700 100644 --- a/OpenMQTTGateway.ino +++ b/OpenMQTTGateway.ino @@ -17,6 +17,8 @@ - crankyoldgit - Spudtater - rickybrent + - ekim from Home assistant forum + - ronvl from Home assistant forum IMPORTANT NOTE: On arduino connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library IRremote/IRremoteInt.h so as to free pin D3 for RF RECEIVER PIN @@ -123,7 +125,7 @@ void setup() setup_wifi(); #else //Begining ethernet connection in case of Arduino + W5100 - Ethernet.begin(mac, ip); + setup_ethernet(); #endif delay(1500); @@ -150,15 +152,31 @@ void setup_wifi() { // We start by connecting to a WiFi network trc(F("Connecting to ")); trc(wifi_ssid); - + IPAddress ip_adress(ip); + IPAddress gateway_adress(gateway); + IPAddress subnet_adress(subnet); + IPAddress dns_adress(dns); WiFi.begin(wifi_ssid, wifi_password); - + WiFi.config(ip_adress,gateway_adress,subnet_adress); //Uncomment this line if you want to use advanced network config + trc("OpenMQTTGateway ip adress: "); + Serial.println(WiFi.localIP()); + while (WiFi.status() != WL_CONNECTED) { delay(500); trc(F(".")); } trc(F("WiFi connected")); } +#else +void setup_ethernet() { + + Ethernet.begin(mac, ip); //Comment and uncomment the following line if you want to use advanced network config + //Ethernet.begin(mac, ip, dns, gateway, subnet); + trc("My IP address is: "); + trc(String(Ethernet.localIP())); + + trc(F("Ethernet connected")); +} #endif void loop() diff --git a/User_config.h b/User_config.h index 44cde69..3864ae5 100644 --- a/User_config.h +++ b/User_config.h @@ -11,10 +11,6 @@ - publish MQTT data to a different topic related to received IR signal Copyright: (c)1technophile - - Contributors: - - crankyoldgit - - Spudtater Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -48,9 +44,14 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT #define wifi_password "wifi password" #else // for arduino + W5100 const byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95 }; //W5100 ethernet shield mac adress - const byte ip[] = { 192, 168, 1, 95 }; //W5100 ethernet shield ip adress #endif +const byte ip[] = { 192, 168, 1, 99 }; //ip adress +// Advanced network config (optional) if you want to use these parameters uncomment line 158 and 172 of OpenMQTTGateway.ino +const byte gateway[] = { 192, 168, 1, 1 }; //ip adress +const byte dns[] = { 192, 168, 1, 1 }; //ip adress +const byte subnet[] = { 255, 255, 255, 0 }; //ip adress + //Addons management, comment the line if you don't use //#define ZaddonDHT true