Skip to content

Commit bb77661

Browse files
tekka007mfalkvidd
authored andcommitted
Consolidate WiFi defines (#1110)
Great work @tekka007
1 parent e0988e6 commit bb77661

File tree

9 files changed

+139
-71
lines changed

9 files changed

+139
-71
lines changed

MyConfig.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* network topology allowing messages to be routed to nodes.
77
*
88
* Created by Henrik Ekblad <[email protected]>
9-
* Copyright (C) 2013-2017 Sensnology AB
9+
* Copyright (C) 2013-2018 Sensnology AB
1010
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
1111
*
1212
* Documentation: http://www.mysensors.org
@@ -1372,6 +1372,30 @@
13721372
*/
13731373
//#define MY_DEBUG_VERBOSE_GATEWAY
13741374

1375+
/**
1376+
* @def MY_WIFI_SSID
1377+
* @brief SSID of your WiFi network
1378+
*/
1379+
//#define MY_WIFI_SSID "MySSID"
1380+
1381+
/**
1382+
* @def MY_WIFI_BSSID
1383+
* @brief BSSID of your WiFi network
1384+
*/
1385+
//#define MY_WIFI_BSSID "MyBSSID"
1386+
1387+
/**
1388+
* @def MY_WIFI_PASSWORD
1389+
* @brief Password of your WiFi network
1390+
*/
1391+
//#define MY_WIFI_PASSWORD "MyVerySecretPassword"
1392+
1393+
/**
1394+
* @def MY_HOSTNAME
1395+
* @brief Hostname of your device
1396+
*/
1397+
//#define MY_HOSTNAME "MyHostname"
1398+
13751399
/**
13761400
* @def MY_PORT
13771401
* @brief The Ethernet TCP/UDP port to open on controller or gateway.
@@ -2172,6 +2196,10 @@
21722196
#define MY_GATEWAY_ENC28J60
21732197
#define MY_GATEWAY_ESP8266
21742198
#define MY_GATEWAY_ESP32
2199+
#define MY_WIFI_SSID
2200+
#define MY_WIFI_BSSID
2201+
#define MY_WIFI_PASSWORD
2202+
#define MY_HOSTNAME
21752203
#define MY_GATEWAY_LINUX
21762204
#define MY_GATEWAY_TINYGSM
21772205
#define MY_GATEWAY_MQTT_CLIENT

core/MyGatewayTransportEthernet.cpp

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@
2222
// global variables
2323
extern MyMessage _msgTmp;
2424

25+
// housekeeping, remove for 3.0.0
26+
#ifdef MY_ESP8266_SSID
27+
#warning MY_ESP8266_SSID is deprecated, use MY_WIFI_SSID instead!
28+
#define MY_WIFI_SSID MY_ESP8266_SSID
29+
#undef MY_ESP8266_SSID // cleanup
30+
#endif
31+
32+
#ifdef MY_ESP8266_PASSWORD
33+
#warning MY_ESP8266_PASSWORD is deprecated, use MY_WIFI_PASSWORD instead!
34+
#define MY_WIFI_PASSWORD MY_ESP8266_PASSWORD
35+
#undef MY_ESP8266_PASSWORD // cleanup
36+
#endif
37+
38+
#ifdef MY_ESP8266_BSSID
39+
#warning MY_ESP8266_BSSID is deprecated, use MY_WIFI_BSSID instead!
40+
#define MY_WIFI_BSSID MY_ESP8266_BSSID
41+
#undef MY_ESP8266_BSSID // cleanup
42+
#endif
43+
44+
#ifdef MY_ESP8266_HOSTNAME
45+
#warning MY_ESP8266_HOSTNAME is deprecated, use MY_HOSTNAME instead!
46+
#define MY_HOSTNAME MY_ESP8266_HOSTNAME
47+
#undef MY_ESP8266_HOSTNAME // cleanup
48+
#endif
49+
50+
#ifndef MY_WIFI_BSSID
51+
#define MY_WIFI_BSSID NULL
52+
#endif
53+
2554
#if defined(MY_CONTROLLER_IP_ADDRESS)
2655
IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
2756
#endif
@@ -116,45 +145,27 @@ void _w5100_spi_en(bool enable)
116145
bool gatewayTransportInit(void)
117146
{
118147
_w5100_spi_en(true);
119-
#if defined(MY_GATEWAY_ESP8266)
120-
#if defined(MY_ESP8266_SSID)
148+
149+
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
150+
#if defined(MY_WIFI_SSID)
121151
// Turn off access point
122152
WiFi.mode(WIFI_STA);
123-
#if defined(MY_ESP8266_HOSTNAME)
124-
WiFi.hostname(MY_ESP8266_HOSTNAME);
125-
#endif /* End of MY_ESP8266_HOSTNAME */
126-
#if defined(MY_IP_ADDRESS)
127-
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
128-
#endif /* End of MY_IP_ADDRESS */
129-
#ifndef MY_ESP8266_BSSID
130-
#define MY_ESP8266_BSSID NULL
131-
#endif
132-
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0, MY_ESP8266_BSSID);
133-
while (WiFi.status() != WL_CONNECTED) {
134-
wait(500);
135-
GATEWAY_DEBUG(PSTR("GWT:TIN:CONNECTING...\n"));
136-
}
137-
GATEWAY_DEBUG(PSTR("GWT:TIN:IP=%s\n"), WiFi.localIP().toString().c_str());
138-
#endif /* End of MY_ESP8266_SSID */
153+
#if defined(MY_HOSTNAME)
154+
#if defined(MY_GATEWAY_ESP8266)
155+
WiFi.hostname(MY_HOSTNAME)
139156
#elif defined(MY_GATEWAY_ESP32)
140-
#if defined(MY_ESP32_SSID)
141-
// Turn off access point
142-
WiFi.mode(WIFI_STA);
143-
#if defined(MY_ESP32_HOSTNAME)
144-
WiFi.setHostname(MY_ESP32_HOSTNAME);
157+
WiFi.setHostname(MY_HOSTNAME)
158+
#endif
145159
#endif
146160
#ifdef MY_IP_ADDRESS
147161
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
148162
#endif
149-
#ifndef MY_ESP32_BSSID
150-
#define MY_ESP32_BSSID NULL
151-
#endif
152-
(void)WiFi.begin(MY_ESP32_SSID, MY_ESP32_PASSWORD, 0, MY_ESP32_BSSID);
153-
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
163+
(void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
164+
while (WiFi.status() != WL_CONNECTED) {
154165
wait(500);
155-
GATEWAY_DEBUG(PSTR("."));
166+
GATEWAY_DEBUG(PSTR("GWT:TIN:CONNECTING...\n"));
156167
}
157-
GATEWAY_DEBUG(PSTR("IP: %s\n"), WiFi.localIP().toString().c_str());
168+
GATEWAY_DEBUG(PSTR("GWT:TIN:IP: %s\n"), WiFi.localIP().toString().c_str());
158169
#endif
159170
#elif defined(MY_GATEWAY_LINUX)
160171
// Nothing to do here

core/MyGatewayTransportMQTTClient.cpp

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@
2222

2323
#include "MyGatewayTransport.h"
2424

25+
// housekeeping, remove for 3.0.0
26+
#ifdef MY_ESP8266_SSID
27+
#warning MY_ESP8266_SSID is deprecated, use MY_WIFI_SSID instead!
28+
#define MY_WIFI_SSID MY_ESP8266_SSID
29+
#undef MY_ESP8266_SSID // cleanup
30+
#endif
31+
32+
#ifdef MY_ESP8266_PASSWORD
33+
#warning MY_ESP8266_PASSWORD is deprecated, use MY_WIFI_PASSWORD instead!
34+
#define MY_WIFI_PASSWORD MY_ESP8266_PASSWORD
35+
#undef MY_ESP8266_PASSWORD // cleanup
36+
#endif
37+
38+
#ifdef MY_ESP8266_BSSID
39+
#warning MY_ESP8266_BSSID is deprecated, use MY_WIFI_BSSID instead!
40+
#define MY_WIFI_BSSID MY_ESP8266_BSSID
41+
#undef MY_ESP8266_BSSID // cleanup
42+
#endif
43+
44+
#ifdef MY_ESP8266_HOSTNAME
45+
#warning MY_ESP8266_HOSTNAME is deprecated, use MY_HOSTNAME instead!
46+
#define MY_HOSTNAME MY_ESP8266_HOSTNAME
47+
#undef MY_ESP8266_HOSTNAME // cleanup
48+
#endif
49+
50+
#ifndef MY_WIFI_BSSID
51+
#define MY_WIFI_BSSID NULL
52+
#endif
53+
2554
#if defined MY_CONTROLLER_IP_ADDRESS
2655
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
2756
#endif
@@ -127,13 +156,13 @@ bool gatewayTransportConnect(void)
127156
GATEWAY_DEBUG(PSTR("GWT:TPC:CONNECTING...\n"));
128157
}
129158
GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"),WiFi.localIP().toString().c_str());
130-
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
159+
#elif defined(MY_GATEWAY_LINUX)
131160
#if defined(MY_IP_ADDRESS)
132161
_MQTT_ethClient.bind(_MQTT_clientIp);
133162
#endif /* End of MY_IP_ADDRESS */
134-
#elif defined(MY_GATEWAY_TINYGSM) /* Elif part of MY_GATEWAY_ESP8266 */
163+
#elif defined(MY_GATEWAY_TINYGSM)
135164
GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"), modem.getLocalIP().c_str());
136-
#else /* Else part of MY_GATEWAY_ESP8266 */
165+
#else
137166
#if defined(MY_IP_ADDRESS)
138167
Ethernet.begin(_MQTT_clientMAC, _MQTT_clientIp);
139168
#else /* Else part of MY_IP_ADDRESS */
@@ -149,7 +178,7 @@ bool gatewayTransportConnect(void)
149178
Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]);
150179
// give the Ethernet interface a second to initialize
151180
delay(1000);
152-
#endif /* End of MY_GATEWAY_ESP8266 */
181+
#endif
153182
return true;
154183
}
155184

@@ -207,29 +236,29 @@ bool gatewayTransportInit(void)
207236
#if defined(MY_GATEWAY_ESP8266)
208237
// Turn off access point
209238
WiFi.mode(WIFI_STA);
210-
#if defined(MY_ESP8266_HOSTNAME)
211-
WiFi.hostname(MY_ESP8266_HOSTNAME);
239+
#if defined(MY_HOSTNAME)
240+
WiFi.hostname(MY_HOSTNAME);
212241
#endif /* End of MY_ESP8266_HOSTNAME */
213242
#if defined(MY_IP_ADDRESS)
214243
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
215244
#endif /* End of MY_IP_ADDRESS */
216-
#ifndef MY_ESP8266_BSSID
217-
#define MY_ESP8266_BSSID NULL
245+
#ifndef MY_WIFI_BSSID
246+
#define MY_WIFI_BSSID NULL
218247
#endif
219-
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0, MY_ESP8266_BSSID);
248+
(void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
220249
#elif defined(MY_GATEWAY_ESP32)
221250
// Turn off access point
222251
WiFi.mode(WIFI_STA);
223-
#if defined(MY_ESP32_HOSTNAME)
224-
WiFi.setHostname(MY_ESP32_HOSTNAME);
225-
#endif /* End of MY_ESP32_HOSTNAME */
252+
#if defined(MY_HOSTNAME)
253+
WiFi.setHostname(MY_HOSTNAME);
254+
#endif /* End of MY_HOSTNAME */
226255
#if defined(MY_IP_ADDRESS)
227256
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
228257
#endif /* End of MY_IP_ADDRESS */
229-
#ifndef MY_ESP32_BSSID
230-
#define MY_ESP32_BSSID NULL
258+
#ifndef MY_WIFI_BSSID
259+
#define MY_WIFI_BSSID NULL
231260
#endif
232-
(void)WiFi.begin(MY_ESP32_SSID, MY_ESP32_PASSWORD, 0, MY_ESP32_BSSID);
261+
(void)WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD, 0, MY_WIFI_BSSID);
233262
#endif
234263

235264
gatewayTransportConnect();

examples/GatewayESP32/GatewayESP32.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
#define MY_DEBUG
3333

3434
// Enables and select radio type (if attached)
35-
#define MY_RADIO_NRF24
35+
#define MY_RADIO_RF24
3636
//#define MY_RADIO_RFM69
3737
//#define MY_RADIO_RFM95
3838

3939
#define MY_GATEWAY_ESP32
4040

41-
#define MY_ESP32_SSID "MySSID"
42-
#define MY_ESP32_PASSWORD "MyVerySecretPassword"
41+
#define MY_WIFI_SSID "MySSID"
42+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
4343

4444
// Set the hostname for the WiFi Client. This is the hostname
4545
// it will pass to the DHCP server if not static.
46-
#define MY_ESP32_HOSTNAME "ESP32_GW"
46+
#define MY_HOSTNAME "ESP32_GW"
4747

4848
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
4949
//#define MY_IP_ADDRESS 192,168,1,100

examples/GatewayESP32MQTTClient/GatewayESP32MQTTClient.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define MY_DEBUG
3333

3434
// Enables and select radio type (if attached)
35-
#define MY_RADIO_NRF24
35+
#define MY_RADIO_RF24
3636
//#define MY_RADIO_RFM69
3737
//#define MY_RADIO_RFM95
3838

@@ -51,12 +51,12 @@
5151
//#define MY_MQTT_PASSWORD "password"
5252

5353
// Set WIFI SSID and password
54-
#define MY_ESP32_SSID "MySSID"
55-
#define MY_ESP32_PASSWORD "MyVerySecretPassword"
54+
#define MY_WIFI_SSID "MySSID"
55+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
5656

5757
// Set the hostname for the WiFi Client. This is the hostname
5858
// it will pass to the DHCP server if not static.
59-
#define MY_ESP32_HOSTNAME "ESP32_MQTT_GW"
59+
#define MY_HOSTNAME "ESP32_MQTT_GW"
6060

6161
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
6262
//#define MY_IP_ADDRESS 192,168,178,87

examples/GatewayESP8266/GatewayESP8266.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464

6565
#define MY_GATEWAY_ESP8266
6666

67-
#define MY_ESP8266_SSID "MySSID"
68-
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
67+
#define MY_WIFI_SSID "MySSID"
68+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
6969

7070
// Enable UDP communication
7171
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
7272

7373
// Set the hostname for the WiFi Client. This is the hostname
7474
// it will pass to the DHCP server if not static.
75-
//#define MY_ESP8266_HOSTNAME "sensor-gateway"
75+
//#define MY_HOSTNAME "sensor-gateway"
7676

7777
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
7878
//#define MY_IP_ADDRESS 192,168,178,87

examples/GatewayESP8266MQTTClient/GatewayESP8266MQTTClient.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
//#define MY_MQTT_PASSWORD "password"
7171

7272
// Set WIFI SSID and password
73-
#define MY_ESP8266_SSID "MySSID"
74-
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
73+
#define MY_WIFI_SSID "MySSID"
74+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
7575

7676
// Set the hostname for the WiFi Client. This is the hostname
7777
// it will pass to the DHCP server if not static.
78-
// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
78+
// #define MY_HOSTNAME "mqtt-sensor-gateway"
7979

8080
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
8181
//#define MY_IP_ADDRESS 192,168,178,87

examples/GatewayESP8266OTA/GatewayESP8266OTA.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565

6666
#define MY_GATEWAY_ESP8266
6767

68-
#define MY_ESP8266_SSID "MySSID"
69-
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
68+
#define MY_WIFI_SSID "MySSID"
69+
#define MY_WIFI_PASSWORD "MyVerySecretPassword"
7070

7171
// Set the hostname for the WiFi Client. This is the hostname
7272
// it will pass to the DHCP server if not static.
73-
// #define MY_ESP8266_HOSTNAME "sensor-ota-gateway"
73+
// #define MY_HOSTNAME "sensor-ota-gateway"
7474

7575
// Enable UDP communication
7676
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below

keywords.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ MY_GATEWAY_ESP8266 LITERAL1
240240
MY_GATEWAY_MQTT_CLIENT LITERAL1
241241
MY_GATEWAY_SERIAL LITERAL1
242242
MY_GATEWAY_W5100 LITERAL1
243+
MY_HOSTNAME LITERAL1
243244
MY_INCLUSION_BUTTON_EXTERNAL_PULLUP LITERAL1
244245
MY_MQTT_CLIENT_ID LITERAL1
245246
MY_MQTT_CLIENT_PUBLISH_RETAIN LITERAL1
@@ -248,6 +249,9 @@ MY_MQTT_PUBLISH_TOPIC_PREFIX LITERAL1
248249
MY_MQTT_SUBSCRIBE_TOPIC_PREFIX LITERAL1
249250
MY_MQTT_USER LITERAL1
250251
MY_W5100_SPI_EN LITERAL1
252+
MY_WIFI_SSID LITERAL1
253+
MY_WIFI_BSSID LITERAL1
254+
MY_WIFI_PASSWORD LITERAL1
251255

252256
# Ethernet
253257
MY_CONTROLLER_IP_ADDRESS LITERAL1
@@ -265,17 +269,9 @@ MY_PORT LITERAL1
265269
MY_USE_UDP LITERAL1
266270

267271
# ESP32
268-
MY_ESP32_SSID LITERAL1
269-
MY_ESP32_PASSWORD LITERAL1
270-
MY_ESP32_BSSID LITERAL1
271-
MY_ESP32_HOSTNAME LITERAL1
272272

273273
# ESP8266
274-
MY_ESP8266_BSSID LITERAL1
275-
MY_ESP8266_HOSTNAME LITERAL1
276-
MY_ESP8266_PASSWORD LITERAL1
277274
MY_ESP8266_SERIAL_MODE LITERAL1
278-
MY_ESP8266_SSID LITERAL1
279275

280276
# Blacklist - autodefines that are used internally and should not be highlighted, hence commented.
281277
# MY_CAP_ARCH
@@ -347,6 +343,10 @@ MY_ESP8266_SSID LITERAL1
347343
# MY_RF69_RESET
348344
# MY_RF69_SPI_CS
349345
# MY_TRANSPORT_DONT_CARE_MODE
346+
# MY_ESP8266_BSSID LITERAL1
347+
# MY_ESP8266_HOSTNAME LITERAL1
348+
# MY_ESP8266_PASSWORD LITERAL1
349+
# MY_ESP8266_SSID LITERAL1
350350

351351
# Blacklist - descriptional only
352352
# MY_XYZ_POWER_PIN

0 commit comments

Comments
 (0)