From f287e4ee95229ac451c6702c86930b6b8dfa2df3 Mon Sep 17 00:00:00 2001 From: Kirk Davis Date: Sat, 28 May 2016 20:36:18 -0600 Subject: [PATCH] Allow setting the hostname Allows setting the hostname if MY_ESP6266_HOSTNAME is defined. --- libraries/MySensors/core/MyGatewayTransportEthernet.cpp | 3 +++ libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp | 3 +++ .../MySensors/examples/GatewayESP8266/GatewayESP8266.ino | 4 ++++ .../GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/libraries/MySensors/core/MyGatewayTransportEthernet.cpp b/libraries/MySensors/core/MyGatewayTransportEthernet.cpp index 4b70655..0cecce6 100644 --- a/libraries/MySensors/core/MyGatewayTransportEthernet.cpp +++ b/libraries/MySensors/core/MyGatewayTransportEthernet.cpp @@ -103,6 +103,9 @@ bool gatewayTransportInit() { #if defined(MY_ESP8266_SSID) // Turn off access point WiFi.mode (WIFI_STA); + #if defined(MY_ESP8266_HOSTNAME) + WiFi.hostname(MY_EPS8266_HOSTNAME); + #endif (void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD); #ifdef MY_IP_ADDRESS WiFi.config(_ethernetGatewayIP, gateway, subnet); diff --git a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp index a2c1d6c..326d349 100644 --- a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp +++ b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp @@ -167,6 +167,9 @@ bool gatewayTransportInit() { #if defined(MY_GATEWAY_ESP8266) // Turn off access point WiFi.mode (WIFI_STA); + #if defined(MY_ESP8266_HOSTNAME) + WiFi.hostname(MY_ESP8266_HOSTNAME); + #endif (void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD); #ifdef MY_IP_ADDRESS WiFi.config(_clientIp, _gatewayIp, _subnetIp); diff --git a/libraries/MySensors/examples/GatewayESP8266/GatewayESP8266.ino b/libraries/MySensors/examples/GatewayESP8266/GatewayESP8266.ino index 803eb7d..142a1b4 100644 --- a/libraries/MySensors/examples/GatewayESP8266/GatewayESP8266.ino +++ b/libraries/MySensors/examples/GatewayESP8266/GatewayESP8266.ino @@ -86,6 +86,10 @@ // Enable UDP communication //#define MY_USE_UDP +// Set the hostname for the WiFi Client. This is the hostname +// it will pass to the DHCP server if not static. +// #define MY_ESP8266_HOSTNAME "sensor-gateway" + // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 diff --git a/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino b/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino index 60d052e..1e77c3c 100644 --- a/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino +++ b/libraries/MySensors/examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino @@ -88,6 +88,10 @@ #define MY_ESP8266_SSID "MySSID" #define MY_ESP8266_PASSWORD "MyVerySecretPassword" +// Set the hostname for the WiFi Client. This is the hostname +// it will pass to the DHCP server if not static. +// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway" + // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) #define MY_IP_ADDRESS 192,168,178,87