Consolidate WiFi defines (#1110)

Great work @tekka007
This commit is contained in:
tekka
2018-05-01 16:54:43 +02:00
committed by Mikael Falkvidd
parent e0988e6d9e
commit bb7766197c
9 changed files with 140 additions and 72 deletions
+29 -1
View File
@@ -6,7 +6,7 @@
* network topology allowing messages to be routed to nodes. * network topology allowing messages to be routed to nodes.
* *
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2017 Sensnology AB * Copyright (C) 2013-2018 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
* *
* Documentation: http://www.mysensors.org * Documentation: http://www.mysensors.org
@@ -1372,6 +1372,30 @@
*/ */
//#define MY_DEBUG_VERBOSE_GATEWAY //#define MY_DEBUG_VERBOSE_GATEWAY
/**
* @def MY_WIFI_SSID
* @brief SSID of your WiFi network
*/
//#define MY_WIFI_SSID "MySSID"
/**
* @def MY_WIFI_BSSID
* @brief BSSID of your WiFi network
*/
//#define MY_WIFI_BSSID "MyBSSID"
/**
* @def MY_WIFI_PASSWORD
* @brief Password of your WiFi network
*/
//#define MY_WIFI_PASSWORD "MyVerySecretPassword"
/**
* @def MY_HOSTNAME
* @brief Hostname of your device
*/
//#define MY_HOSTNAME "MyHostname"
/** /**
* @def MY_PORT * @def MY_PORT
* @brief The Ethernet TCP/UDP port to open on controller or gateway. * @brief The Ethernet TCP/UDP port to open on controller or gateway.
@@ -2172,6 +2196,10 @@
#define MY_GATEWAY_ENC28J60 #define MY_GATEWAY_ENC28J60
#define MY_GATEWAY_ESP8266 #define MY_GATEWAY_ESP8266
#define MY_GATEWAY_ESP32 #define MY_GATEWAY_ESP32
#define MY_WIFI_SSID
#define MY_WIFI_BSSID
#define MY_WIFI_PASSWORD
#define MY_HOSTNAME
#define MY_GATEWAY_LINUX #define MY_GATEWAY_LINUX
#define MY_GATEWAY_TINYGSM #define MY_GATEWAY_TINYGSM
#define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_MQTT_CLIENT
+42 -31
View File
@@ -22,6 +22,35 @@
// global variables // global variables
extern MyMessage _msgTmp; extern MyMessage _msgTmp;
// housekeeping, remove for 3.0.0
#ifdef MY_ESP8266_SSID
#warning MY_ESP8266_SSID is deprecated, use MY_WIFI_SSID instead!
#define MY_WIFI_SSID MY_ESP8266_SSID
#undef MY_ESP8266_SSID // cleanup
#endif
#ifdef MY_ESP8266_PASSWORD
#warning MY_ESP8266_PASSWORD is deprecated, use MY_WIFI_PASSWORD instead!
#define MY_WIFI_PASSWORD MY_ESP8266_PASSWORD
#undef MY_ESP8266_PASSWORD // cleanup
#endif
#ifdef MY_ESP8266_BSSID
#warning MY_ESP8266_BSSID is deprecated, use MY_WIFI_BSSID instead!
#define MY_WIFI_BSSID MY_ESP8266_BSSID
#undef MY_ESP8266_BSSID // cleanup
#endif
#ifdef MY_ESP8266_HOSTNAME
#warning MY_ESP8266_HOSTNAME is deprecated, use MY_HOSTNAME instead!
#define MY_HOSTNAME MY_ESP8266_HOSTNAME
#undef MY_ESP8266_HOSTNAME // cleanup
#endif
#ifndef MY_WIFI_BSSID
#define MY_WIFI_BSSID NULL
#endif
#if defined(MY_CONTROLLER_IP_ADDRESS) #if defined(MY_CONTROLLER_IP_ADDRESS)
IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS); IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
#endif #endif
@@ -116,45 +145,27 @@ void _w5100_spi_en(bool enable)
bool gatewayTransportInit(void) bool gatewayTransportInit(void)
{ {
_w5100_spi_en(true); _w5100_spi_en(true);
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
#if defined(MY_WIFI_SSID)
// Turn off access point
WiFi.mode(WIFI_STA);
#if defined(MY_HOSTNAME)
#if defined(MY_GATEWAY_ESP8266) #if defined(MY_GATEWAY_ESP8266)
#if defined(MY_ESP8266_SSID) WiFi.hostname(MY_HOSTNAME)
// Turn off access point
WiFi.mode(WIFI_STA);
#if defined(MY_ESP8266_HOSTNAME)
WiFi.hostname(MY_ESP8266_HOSTNAME);
#endif /* End of MY_ESP8266_HOSTNAME */
#if defined(MY_IP_ADDRESS)
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
#endif /* End of MY_IP_ADDRESS */
#ifndef MY_ESP8266_BSSID
#define MY_ESP8266_BSSID NULL
#endif
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0, MY_ESP8266_BSSID);
while (WiFi.status() != WL_CONNECTED) {
wait(500);
GATEWAY_DEBUG(PSTR("GWT:TIN:CONNECTING...\n"));
}
GATEWAY_DEBUG(PSTR("GWT:TIN:IP=%s\n"), WiFi.localIP().toString().c_str());
#endif /* End of MY_ESP8266_SSID */
#elif defined(MY_GATEWAY_ESP32) #elif defined(MY_GATEWAY_ESP32)
#if defined(MY_ESP32_SSID) WiFi.setHostname(MY_HOSTNAME)
// Turn off access point #endif
WiFi.mode(WIFI_STA);
#if defined(MY_ESP32_HOSTNAME)
WiFi.setHostname(MY_ESP32_HOSTNAME);
#endif #endif
#ifdef MY_IP_ADDRESS #ifdef MY_IP_ADDRESS
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp); WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
#endif #endif
#ifndef MY_ESP32_BSSID (void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
#define MY_ESP32_BSSID NULL while (WiFi.status() != WL_CONNECTED) {
#endif
(void)WiFi.begin(MY_ESP32_SSID, MY_ESP32_PASSWORD, 0, MY_ESP32_BSSID);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
wait(500); wait(500);
GATEWAY_DEBUG(PSTR(".")); GATEWAY_DEBUG(PSTR("GWT:TIN:CONNECTING...\n"));
} }
GATEWAY_DEBUG(PSTR("IP: %s\n"), WiFi.localIP().toString().c_str()); GATEWAY_DEBUG(PSTR("GWT:TIN:IP: %s\n"), WiFi.localIP().toString().c_str());
#endif #endif
#elif defined(MY_GATEWAY_LINUX) #elif defined(MY_GATEWAY_LINUX)
// Nothing to do here // Nothing to do here
+44 -15
View File
@@ -22,6 +22,35 @@
#include "MyGatewayTransport.h" #include "MyGatewayTransport.h"
// housekeeping, remove for 3.0.0
#ifdef MY_ESP8266_SSID
#warning MY_ESP8266_SSID is deprecated, use MY_WIFI_SSID instead!
#define MY_WIFI_SSID MY_ESP8266_SSID
#undef MY_ESP8266_SSID // cleanup
#endif
#ifdef MY_ESP8266_PASSWORD
#warning MY_ESP8266_PASSWORD is deprecated, use MY_WIFI_PASSWORD instead!
#define MY_WIFI_PASSWORD MY_ESP8266_PASSWORD
#undef MY_ESP8266_PASSWORD // cleanup
#endif
#ifdef MY_ESP8266_BSSID
#warning MY_ESP8266_BSSID is deprecated, use MY_WIFI_BSSID instead!
#define MY_WIFI_BSSID MY_ESP8266_BSSID
#undef MY_ESP8266_BSSID // cleanup
#endif
#ifdef MY_ESP8266_HOSTNAME
#warning MY_ESP8266_HOSTNAME is deprecated, use MY_HOSTNAME instead!
#define MY_HOSTNAME MY_ESP8266_HOSTNAME
#undef MY_ESP8266_HOSTNAME // cleanup
#endif
#ifndef MY_WIFI_BSSID
#define MY_WIFI_BSSID NULL
#endif
#if defined MY_CONTROLLER_IP_ADDRESS #if defined MY_CONTROLLER_IP_ADDRESS
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS); IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
#endif #endif
@@ -127,13 +156,13 @@ bool gatewayTransportConnect(void)
GATEWAY_DEBUG(PSTR("GWT:TPC:CONNECTING...\n")); GATEWAY_DEBUG(PSTR("GWT:TPC:CONNECTING...\n"));
} }
GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"),WiFi.localIP().toString().c_str()); GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"),WiFi.localIP().toString().c_str());
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */ #elif defined(MY_GATEWAY_LINUX)
#if defined(MY_IP_ADDRESS) #if defined(MY_IP_ADDRESS)
_MQTT_ethClient.bind(_MQTT_clientIp); _MQTT_ethClient.bind(_MQTT_clientIp);
#endif /* End of MY_IP_ADDRESS */ #endif /* End of MY_IP_ADDRESS */
#elif defined(MY_GATEWAY_TINYGSM) /* Elif part of MY_GATEWAY_ESP8266 */ #elif defined(MY_GATEWAY_TINYGSM)
GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"), modem.getLocalIP().c_str()); GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"), modem.getLocalIP().c_str());
#else /* Else part of MY_GATEWAY_ESP8266 */ #else
#if defined(MY_IP_ADDRESS) #if defined(MY_IP_ADDRESS)
Ethernet.begin(_MQTT_clientMAC, _MQTT_clientIp); Ethernet.begin(_MQTT_clientMAC, _MQTT_clientIp);
#else /* Else part of MY_IP_ADDRESS */ #else /* Else part of MY_IP_ADDRESS */
@@ -149,7 +178,7 @@ bool gatewayTransportConnect(void)
Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]); Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]);
// give the Ethernet interface a second to initialize // give the Ethernet interface a second to initialize
delay(1000); delay(1000);
#endif /* End of MY_GATEWAY_ESP8266 */ #endif
return true; return true;
} }
@@ -207,29 +236,29 @@ bool gatewayTransportInit(void)
#if defined(MY_GATEWAY_ESP8266) #if defined(MY_GATEWAY_ESP8266)
// Turn off access point // Turn off access point
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
#if defined(MY_ESP8266_HOSTNAME) #if defined(MY_HOSTNAME)
WiFi.hostname(MY_ESP8266_HOSTNAME); WiFi.hostname(MY_HOSTNAME);
#endif /* End of MY_ESP8266_HOSTNAME */ #endif /* End of MY_ESP8266_HOSTNAME */
#if defined(MY_IP_ADDRESS) #if defined(MY_IP_ADDRESS)
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp); WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
#endif /* End of MY_IP_ADDRESS */ #endif /* End of MY_IP_ADDRESS */
#ifndef MY_ESP8266_BSSID #ifndef MY_WIFI_BSSID
#define MY_ESP8266_BSSID NULL #define MY_WIFI_BSSID NULL
#endif #endif
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0, MY_ESP8266_BSSID); (void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
#elif defined(MY_GATEWAY_ESP32) #elif defined(MY_GATEWAY_ESP32)
// Turn off access point // Turn off access point
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
#if defined(MY_ESP32_HOSTNAME) #if defined(MY_HOSTNAME)
WiFi.setHostname(MY_ESP32_HOSTNAME); WiFi.setHostname(MY_HOSTNAME);
#endif /* End of MY_ESP32_HOSTNAME */ #endif /* End of MY_HOSTNAME */
#if defined(MY_IP_ADDRESS) #if defined(MY_IP_ADDRESS)
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp); WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
#endif /* End of MY_IP_ADDRESS */ #endif /* End of MY_IP_ADDRESS */
#ifndef MY_ESP32_BSSID #ifndef MY_WIFI_BSSID
#define MY_ESP32_BSSID NULL #define MY_WIFI_BSSID NULL
#endif #endif
(void)WiFi.begin(MY_ESP32_SSID, MY_ESP32_PASSWORD, 0, MY_ESP32_BSSID); (void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
#endif #endif
gatewayTransportConnect(); gatewayTransportConnect();
+4 -4
View File
@@ -32,18 +32,18 @@
#define MY_DEBUG #define MY_DEBUG
// Enables and select radio type (if attached) // Enables and select radio type (if attached)
#define MY_RADIO_NRF24 #define MY_RADIO_RF24
//#define MY_RADIO_RFM69 //#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95 //#define MY_RADIO_RFM95
#define MY_GATEWAY_ESP32 #define MY_GATEWAY_ESP32
#define MY_ESP32_SSID "MySSID" #define MY_WIFI_SSID "MySSID"
#define MY_ESP32_PASSWORD "MyVerySecretPassword" #define MY_WIFI_PASSWORD "MyVerySecretPassword"
// Set the hostname for the WiFi Client. This is the hostname // Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static. // it will pass to the DHCP server if not static.
#define MY_ESP32_HOSTNAME "ESP32_GW" #define MY_HOSTNAME "ESP32_GW"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,1,100 //#define MY_IP_ADDRESS 192,168,1,100
@@ -32,7 +32,7 @@
#define MY_DEBUG #define MY_DEBUG
// Enables and select radio type (if attached) // Enables and select radio type (if attached)
#define MY_RADIO_NRF24 #define MY_RADIO_RF24
//#define MY_RADIO_RFM69 //#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95 //#define MY_RADIO_RFM95
@@ -51,12 +51,12 @@
//#define MY_MQTT_PASSWORD "password" //#define MY_MQTT_PASSWORD "password"
// Set WIFI SSID and password // Set WIFI SSID and password
#define MY_ESP32_SSID "MySSID" #define MY_WIFI_SSID "MySSID"
#define MY_ESP32_PASSWORD "MyVerySecretPassword" #define MY_WIFI_PASSWORD "MyVerySecretPassword"
// Set the hostname for the WiFi Client. This is the hostname // Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static. // it will pass to the DHCP server if not static.
#define MY_ESP32_HOSTNAME "ESP32_MQTT_GW" #define MY_HOSTNAME "ESP32_MQTT_GW"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,178,87 //#define MY_IP_ADDRESS 192,168,178,87
+3 -3
View File
@@ -64,15 +64,15 @@
#define MY_GATEWAY_ESP8266 #define MY_GATEWAY_ESP8266
#define MY_ESP8266_SSID "MySSID" #define MY_WIFI_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyVerySecretPassword" #define MY_WIFI_PASSWORD "MyVerySecretPassword"
// Enable UDP communication // Enable UDP communication
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
// Set the hostname for the WiFi Client. This is the hostname // Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static. // it will pass to the DHCP server if not static.
//#define MY_ESP8266_HOSTNAME "sensor-gateway" //#define MY_HOSTNAME "sensor-gateway"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,178,87 //#define MY_IP_ADDRESS 192,168,178,87
@@ -70,12 +70,12 @@
//#define MY_MQTT_PASSWORD "password" //#define MY_MQTT_PASSWORD "password"
// Set WIFI SSID and password // Set WIFI SSID and password
#define MY_ESP8266_SSID "MySSID" #define MY_WIFI_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyVerySecretPassword" #define MY_WIFI_PASSWORD "MyVerySecretPassword"
// Set the hostname for the WiFi Client. This is the hostname // Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static. // it will pass to the DHCP server if not static.
// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway" // #define MY_HOSTNAME "mqtt-sensor-gateway"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,178,87 //#define MY_IP_ADDRESS 192,168,178,87
@@ -65,12 +65,12 @@
#define MY_GATEWAY_ESP8266 #define MY_GATEWAY_ESP8266
#define MY_ESP8266_SSID "MySSID" #define MY_WIFI_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyVerySecretPassword" #define MY_WIFI_PASSWORD "MyVerySecretPassword"
// Set the hostname for the WiFi Client. This is the hostname // Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static. // it will pass to the DHCP server if not static.
// #define MY_ESP8266_HOSTNAME "sensor-ota-gateway" // #define MY_HOSTNAME "sensor-ota-gateway"
// Enable UDP communication // Enable UDP communication
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below //#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
+8 -8
View File
@@ -240,6 +240,7 @@ MY_GATEWAY_ESP8266 LITERAL1
MY_GATEWAY_MQTT_CLIENT LITERAL1 MY_GATEWAY_MQTT_CLIENT LITERAL1
MY_GATEWAY_SERIAL LITERAL1 MY_GATEWAY_SERIAL LITERAL1
MY_GATEWAY_W5100 LITERAL1 MY_GATEWAY_W5100 LITERAL1
MY_HOSTNAME LITERAL1
MY_INCLUSION_BUTTON_EXTERNAL_PULLUP LITERAL1 MY_INCLUSION_BUTTON_EXTERNAL_PULLUP LITERAL1
MY_MQTT_CLIENT_ID LITERAL1 MY_MQTT_CLIENT_ID LITERAL1
MY_MQTT_CLIENT_PUBLISH_RETAIN LITERAL1 MY_MQTT_CLIENT_PUBLISH_RETAIN LITERAL1
@@ -248,6 +249,9 @@ MY_MQTT_PUBLISH_TOPIC_PREFIX LITERAL1
MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1 MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1
MY_MQTT_USER LITERAL1 MY_MQTT_USER LITERAL1
MY_W5100_SPI_EN LITERAL1 MY_W5100_SPI_EN LITERAL1
MY_WIFI_SSID LITERAL1
MY_WIFI_BSSID LITERAL1
MY_WIFI_PASSWORD LITERAL1
# Ethernet # Ethernet
MY_CONTROLLER_IP_ADDRESS LITERAL1 MY_CONTROLLER_IP_ADDRESS LITERAL1
@@ -265,17 +269,9 @@ MY_PORT LITERAL1
MY_USE_UDP LITERAL1 MY_USE_UDP LITERAL1
# ESP32 # ESP32
MY_ESP32_SSID LITERAL1
MY_ESP32_PASSWORD LITERAL1
MY_ESP32_BSSID LITERAL1
MY_ESP32_HOSTNAME LITERAL1
# ESP8266 # ESP8266
MY_ESP8266_BSSID LITERAL1
MY_ESP8266_HOSTNAME LITERAL1
MY_ESP8266_PASSWORD LITERAL1
MY_ESP8266_SERIAL_MODE LITERAL1 MY_ESP8266_SERIAL_MODE LITERAL1
MY_ESP8266_SSID LITERAL1
# Blacklist - autodefines that are used internally and should not be highlighted, hence commented. # Blacklist - autodefines that are used internally and should not be highlighted, hence commented.
# MY_CAP_ARCH # MY_CAP_ARCH
@@ -347,6 +343,10 @@ MY_ESP8266_SSID LITERAL1
# MY_RF69_RESET # MY_RF69_RESET
# MY_RF69_SPI_CS # MY_RF69_SPI_CS
# MY_TRANSPORT_DONT_CARE_MODE # MY_TRANSPORT_DONT_CARE_MODE
# MY_ESP8266_BSSID LITERAL1
# MY_ESP8266_HOSTNAME LITERAL1
# MY_ESP8266_PASSWORD LITERAL1
# MY_ESP8266_SSID LITERAL1
# Blacklist - descriptional only # Blacklist - descriptional only
# MY_XYZ_POWER_PIN # MY_XYZ_POWER_PIN