Skip to content

Commit 77bb94c

Browse files
authored
Cleanup MyGatewayXXX and fix MQTT (#497)
1 parent 60495ea commit 77bb94c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1136
-1022
lines changed

libraries/MySensors/MySensors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
#error You must define a unique MY_MQTT_CLIENT_ID for this MQTT client
201201
#endif
202202

203-
#include "drivers/pubsubclient/src/PubSubClient.cpp"
203+
#include "drivers/PubSubClient/PubSubClient.cpp"
204204
#include "core/MyGatewayTransport.cpp"
205205
#include "core/MyGatewayTransportMQTTClient.cpp"
206206
#elif defined(MY_GATEWAY_FEATURE)

libraries/MySensors/core/MyGatewayTransportEthernet.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* The MySensors Arduino library handles the wireless radio link and protocol
33
* between your home built sensors/actuators and HA controller of choice.
44
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -47,8 +47,8 @@ typedef struct
4747
#define EthernetUDP WiFiUDP
4848

4949
#if defined(MY_IP_ADDRESS)
50-
IPAddress gateway(MY_IP_GATEWAY_ADDRESS);
51-
IPAddress subnet(MY_IP_SUBNET_ADDRESS);
50+
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
51+
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
5252
#endif
5353
static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS];
5454
#endif
@@ -108,7 +108,7 @@ bool gatewayTransportInit() {
108108
#endif
109109
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
110110
#ifdef MY_IP_ADDRESS
111-
WiFi.config(_ethernetGatewayIP, gateway, subnet);
111+
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
112112
#endif
113113
while (WiFi.status() != WL_CONNECTED)
114114
{
@@ -123,16 +123,17 @@ bool gatewayTransportInit() {
123123
#else
124124
#ifdef MY_IP_ADDRESS
125125
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
126-
MY_SERIALDEVICE.print(F("IP: "));
127-
MY_SERIALDEVICE.println(Ethernet.localIP());
128126
#else
129127
// Get IP address from DHCP
130-
Ethernet.begin(_ethernetGatewayMAC);
131-
MY_SERIALDEVICE.print(F("IP: "));
132-
MY_SERIALDEVICE.println(Ethernet.localIP());
133-
#endif /* IP_ADDRESS_DHCP */
128+
if (!Ethernet.begin(_ethernetGatewayMAC)) {
129+
MY_SERIALDEVICE.print("DHCP FAILURE...");
130+
_w5100_spi_en(false);
131+
return false;
132+
}
133+
#endif
134+
MY_SERIALDEVICE.print(F("IP: "));
135+
MY_SERIALDEVICE.println(Ethernet.localIP());
134136
// give the Ethernet interface a second to initialize
135-
// TODO: use HW delay
136137
delay(1000);
137138
#endif
138139

@@ -277,9 +278,9 @@ bool gatewayTransportAvailable()
277278
return protocolParse(_ethernetMsg, inputString[0].string);
278279
#else
279280
_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
280-
_w5100_spi_en(false);
281281
inputString.string[packet_size] = 0;
282282
debug(PSTR("UDP packet received: %s\n"), inputString.string);
283+
_w5100_spi_en(false);
283284
return protocolParse(_ethernetMsg, inputString.string);
284285
#endif
285286
}
@@ -299,9 +300,7 @@ bool gatewayTransportAvailable()
299300
clients[i] = _ethernetServer.available();
300301
inputString[i].idx = 0;
301302
debug(PSTR("Client %d connected\n"), i);
302-
_w5100_spi_en(false);
303303
gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
304-
_w5100_spi_en(true);
305304
if (presentation)
306305
presentation();
307306
}
@@ -335,6 +334,7 @@ bool gatewayTransportAvailable()
335334
debug(PSTR("Eth: connect\n"));
336335
_w5100_spi_en(false);
337336
gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
337+
_w5100_spi_en(true);
338338
if (presentation)
339339
presentation();
340340
}

0 commit comments

Comments
 (0)