1
- /* *
1
+ /*
2
2
* The MySensors Arduino library handles the wireless radio link and protocol
3
3
* between your home built sensors/actuators and HA controller of choice.
4
4
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -47,8 +47,8 @@ typedef struct
47
47
#define EthernetUDP WiFiUDP
48
48
49
49
#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);
52
52
#endif
53
53
static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS];
54
54
#endif
@@ -108,7 +108,7 @@ bool gatewayTransportInit() {
108
108
#endif
109
109
(void )WiFi.begin (MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
110
110
#ifdef MY_IP_ADDRESS
111
- WiFi.config (_ethernetGatewayIP, gateway, subnet );
111
+ WiFi.config (_ethernetGatewayIP, _gatewayIp, _subnetIp );
112
112
#endif
113
113
while (WiFi.status () != WL_CONNECTED)
114
114
{
@@ -123,16 +123,17 @@ bool gatewayTransportInit() {
123
123
#else
124
124
#ifdef MY_IP_ADDRESS
125
125
Ethernet.begin (_ethernetGatewayMAC, _ethernetGatewayIP);
126
- MY_SERIALDEVICE.print (F (" IP: " ));
127
- MY_SERIALDEVICE.println (Ethernet.localIP ());
128
126
#else
129
127
// 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 ());
134
136
// give the Ethernet interface a second to initialize
135
- // TODO: use HW delay
136
137
delay (1000 );
137
138
#endif
138
139
@@ -277,9 +278,9 @@ bool gatewayTransportAvailable()
277
278
return protocolParse (_ethernetMsg, inputString[0 ].string );
278
279
#else
279
280
_ethernetServer.read (inputString.string , MY_GATEWAY_MAX_RECEIVE_LENGTH);
280
- _w5100_spi_en (false );
281
281
inputString.string [packet_size] = 0 ;
282
282
debug (PSTR (" UDP packet received: %s\n " ), inputString.string );
283
+ _w5100_spi_en (false );
283
284
return protocolParse (_ethernetMsg, inputString.string );
284
285
#endif
285
286
}
@@ -299,9 +300,7 @@ bool gatewayTransportAvailable()
299
300
clients[i] = _ethernetServer.available ();
300
301
inputString[i].idx = 0 ;
301
302
debug (PSTR (" Client %d connected\n " ), i);
302
- _w5100_spi_en (false );
303
303
gatewayTransportSend (buildGw (_msg, I_GATEWAY_READY).set (" Gateway startup complete." ));
304
- _w5100_spi_en (true );
305
304
if (presentation)
306
305
presentation ();
307
306
}
@@ -335,6 +334,7 @@ bool gatewayTransportAvailable()
335
334
debug (PSTR (" Eth: connect\n " ));
336
335
_w5100_spi_en (false );
337
336
gatewayTransportSend (buildGw (_msg, I_GATEWAY_READY).set (" Gateway startup complete." ));
337
+ _w5100_spi_en (true );
338
338
if (presentation)
339
339
presentation ();
340
340
}
0 commit comments