@@ -132,10 +132,9 @@ bool gatewayTransportInit(void)
132
132
(void )WiFi.begin (MY_ESP8266_SSID, MY_ESP8266_PASSWORD, 0 , MY_ESP8266_BSSID);
133
133
while (WiFi.status () != WL_CONNECTED) {
134
134
wait (500 );
135
- MY_SERIALDEVICE. print ( F (" ." ));
135
+ GATEWAY_DEBUG ( PSTR (" ." ));
136
136
}
137
- MY_SERIALDEVICE.print (F (" IP: " ));
138
- MY_SERIALDEVICE.println (WiFi.localIP ());
137
+ GATEWAY_DEBUG (PSTR (" IP: %s\n " ), WiFi.localIP ().toString ().c_str ());
139
138
#endif /* End of MY_ESP8266_SSID */
140
139
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
141
140
// Nothing to do here
@@ -148,13 +147,13 @@ bool gatewayTransportInit(void)
148
147
#else /* Else part of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
149
148
// Get IP address from DHCP
150
149
if (!Ethernet.begin (_ethernetGatewayMAC)) {
151
- MY_SERIALDEVICE. print ( F (" DHCP FAILURE..." ));
150
+ GATEWAY_DEBUG ( PSTR (" DHCP FAILURE..." ));
152
151
_w5100_spi_en (false );
153
152
return false ;
154
153
}
155
154
#endif /* End of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
156
- MY_SERIALDEVICE. print ( F (" IP: " ));
157
- MY_SERIALDEVICE. println ( Ethernet.localIP ());
155
+ GATEWAY_DEBUG ( PSTR (" IP: % " PRIu8 " .% " PRIu8 " .% " PRIu8 " .% " PRIu8 " \n " ), Ethernet. localIP ()[ 0 ],
156
+ Ethernet. localIP ()[ 1 ], Ethernet.localIP ()[ 2 ], Ethernet. localIP ()[ 3 ] );
158
157
// give the Ethernet interface a second to initialize
159
158
delay (1000 );
160
159
#endif /* End of MY_GATEWAY_ESP8266 */
@@ -171,14 +170,14 @@ bool gatewayTransportInit(void)
171
170
#else
172
171
if (client.connect (_ethernetControllerIP, MY_PORT)) {
173
172
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
174
- debug (PSTR (" Eth: connect\n " ));
173
+ GATEWAY_DEBUG (PSTR (" Eth: connect\n " ));
175
174
_w5100_spi_en (false );
176
175
gatewayTransportSend (buildGw (_msgTmp, I_GATEWAY_READY).set (MSG_GW_STARTUP_COMPLETE));
177
176
_w5100_spi_en (true );
178
177
presentNode ();
179
178
} else {
180
179
client.stop ();
181
- debug (PSTR (" Eth: Failed to connect\n " ));
180
+ GATEWAY_DEBUG (PSTR (" Eth: Failed to connect\n " ));
182
181
}
183
182
#endif /* End of MY_USE_UDP */
184
183
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
@@ -220,14 +219,14 @@ bool gatewayTransportSend(MyMessage &message)
220
219
#else
221
220
if (client.connect (_ethernetControllerIP, MY_PORT)) {
222
221
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
223
- debug (PSTR (" Eth: connect\n " ));
222
+ GATEWAY_DEBUG (PSTR (" Eth: connect\n " ));
224
223
_w5100_spi_en (false );
225
224
gatewayTransportSend (buildGw (_msgTmp, I_GATEWAY_READY).set (MSG_GW_STARTUP_COMPLETE));
226
225
_w5100_spi_en (true );
227
226
presentNode ();
228
227
} else {
229
228
// connecting to the server failed!
230
- debug (PSTR (" Eth: Failed to connect\n " ));
229
+ GATEWAY_DEBUG (PSTR (" Eth: Failed to connect\n " ));
231
230
_w5100_spi_en (false );
232
231
return false ;
233
232
}
@@ -263,7 +262,7 @@ bool _readFromClient(uint8_t i)
263
262
if (inChar == ' \n ' || inChar == ' \r ' ) {
264
263
// Add string terminator and prepare for the next message
265
264
inputString[i].string [inputString[i].idx ] = 0 ;
266
- debug (PSTR (" Client %" PRIu8 " : %s\n " ), i, inputString[i].string );
265
+ GATEWAY_DEBUG (PSTR (" Client %" PRIu8 " : %s\n " ), i, inputString[i].string );
267
266
inputString[i].idx = 0 ;
268
267
if (protocolParse (_ethernetMsg, inputString[i].string )) {
269
268
return true ;
@@ -275,7 +274,7 @@ bool _readFromClient(uint8_t i)
275
274
}
276
275
} else {
277
276
// Incoming message too long. Throw away
278
- debug (PSTR (" Client %" PRIu8 " : Message too long\n " ), i);
277
+ GATEWAY_DEBUG (PSTR (" Client %" PRIu8 " : Message too long\n " ), i);
279
278
inputString[i].idx = 0 ;
280
279
// Finished with this client's message. Next loop() we'll see if there's more to read.
281
280
break ;
@@ -293,7 +292,7 @@ bool _readFromClient(void)
293
292
if (inChar == ' \n ' || inChar == ' \r ' ) {
294
293
// Add string terminator and prepare for the next message
295
294
inputString.string [inputString.idx ] = 0 ;
296
- debug (PSTR (" Eth: %s\n " ), inputString.string );
295
+ GATEWAY_DEBUG (PSTR (" Eth: %s\n " ), inputString.string );
297
296
inputString.idx = 0 ;
298
297
if (protocolParse (_ethernetMsg, inputString.string )) {
299
298
return true ;
@@ -305,7 +304,7 @@ bool _readFromClient(void)
305
304
}
306
305
} else {
307
306
// Incoming message too long. Throw away
308
- debug (PSTR (" Eth: Message too long\n " ));
307
+ GATEWAY_DEBUG (PSTR (" Eth: Message too long\n " ));
309
308
inputString.idx = 0 ;
310
309
// Finished with this client's message. Next loop() we'll see if there's more to read.
311
310
break ;
@@ -329,10 +328,10 @@ bool gatewayTransportAvailable(void)
329
328
int packet_size = _ethernetServer.parsePacket ();
330
329
331
330
if (packet_size) {
332
- // debug (PSTR("UDP packet available. Size:%" PRIu8 "\n"), packet_size);
331
+ // GATEWAY_DEBUG (PSTR("UDP packet available. Size:%" PRIu8 "\n"), packet_size);
333
332
_ethernetServer.read (inputString.string , MY_GATEWAY_MAX_RECEIVE_LENGTH);
334
333
inputString.string [packet_size] = 0 ;
335
- debug (PSTR (" UDP packet received: %s\n " ), inputString.string );
334
+ GATEWAY_DEBUG (PSTR (" UDP packet received: %s\n " ), inputString.string );
336
335
_w5100_spi_en (false );
337
336
const bool ok = protocolParse (_ethernetMsg, inputString.string );
338
337
if (ok) {
@@ -348,13 +347,13 @@ bool gatewayTransportAvailable(void)
348
347
#else
349
348
if (client.connect (_ethernetControllerIP, MY_PORT)) {
350
349
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
351
- debug (PSTR (" Eth: connect\n " ));
350
+ GATEWAY_DEBUG (PSTR (" Eth: connect\n " ));
352
351
_w5100_spi_en (false );
353
352
gatewayTransportSend (buildGw (_msgTmp, I_GATEWAY_READY).set (MSG_GW_STARTUP_COMPLETE));
354
353
_w5100_spi_en (true );
355
354
presentNode ();
356
355
} else {
357
- debug (PSTR (" Eth: Failed to connect\n " ));
356
+ GATEWAY_DEBUG (PSTR (" Eth: Failed to connect\n " ));
358
357
_w5100_spi_en (false );
359
358
return false ;
360
359
}
@@ -373,14 +372,14 @@ bool gatewayTransportAvailable(void)
373
372
for (uint8_t i = 0 ; i < ARRAY_SIZE (clients); i++) {
374
373
if (!clients[i].connected ()) {
375
374
if (clientsConnected[i]) {
376
- debug (PSTR (" Client %" PRIu8 " disconnected\n " ), i);
375
+ GATEWAY_DEBUG (PSTR (" Client %" PRIu8 " disconnected\n " ), i);
377
376
clients[i].stop ();
378
377
}
379
378
// check if there are any new clients
380
379
if (_ethernetServer.hasClient ()) {
381
380
clients[i] = _ethernetServer.available ();
382
381
inputString[i].idx = 0 ;
383
- debug (PSTR (" Client %" PRIu8 " connected\n " ), i);
382
+ GATEWAY_DEBUG (PSTR (" Client %" PRIu8 " connected\n " ), i);
384
383
gatewayTransportSend (buildGw (_msgTmp, I_GATEWAY_READY).set (MSG_GW_STARTUP_COMPLETE));
385
384
// Send presentation of locally attached sensors (and node if applicable)
386
385
presentNode ();
@@ -392,7 +391,7 @@ bool gatewayTransportAvailable(void)
392
391
}
393
392
if (allSlotsOccupied && _ethernetServer.hasClient ()) {
394
393
// no free/disconnected spot so reject
395
- debug (PSTR (" No free slot available\n " ));
394
+ GATEWAY_DEBUG (PSTR (" No free slot available\n " ));
396
395
EthernetClient c = _ethernetServer.available ();
397
396
c.stop ();
398
397
}
@@ -412,7 +411,7 @@ bool gatewayTransportAvailable(void)
412
411
if (client != newclient) {
413
412
client.stop ();
414
413
client = newclient;
415
- debug (PSTR (" Eth: connect\n " ));
414
+ GATEWAY_DEBUG (PSTR (" Eth: connect\n " ));
416
415
_w5100_spi_en (false );
417
416
gatewayTransportSend (buildGw (_msgTmp, I_GATEWAY_READY).set (MSG_GW_STARTUP_COMPLETE));
418
417
_w5100_spi_en (true );
@@ -421,7 +420,7 @@ bool gatewayTransportAvailable(void)
421
420
}
422
421
if (client) {
423
422
if (!client.connected ()) {
424
- debug (PSTR (" Eth: disconnect\n " ));
423
+ GATEWAY_DEBUG (PSTR (" Eth: disconnect\n " ));
425
424
client.stop ();
426
425
} else {
427
426
if (_readFromClient ()) {
@@ -461,7 +460,7 @@ void gatewayTransportRenewIP(void)
461
460
return ;
462
461
}
463
462
if (Ethernet.maintain () & ~(0x06 )) {
464
- debug (PSTR (" IP was not renewed correctly\n " ));
463
+ GATEWAY_DEBUG (PSTR (" IP was not renewed correctly\n " ));
465
464
/* Error occured -> IP was not renewed */
466
465
return ;
467
466
}
0 commit comments