diff --git a/examples/ConnectionHandlerDemo/arduino_secrets.h b/examples/ConnectionHandlerDemo/arduino_secrets.h index 5836270..4d9fb7c 100644 --- a/examples/ConnectionHandlerDemo/arduino_secrets.h +++ b/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -1,14 +1,18 @@ +// Required for WiFiConnectionHandler const char SECRET_SSID[] = "NETWORK NAME"; const char SECRET_PASS[] = "NETWORK PASSWORD"; +// Required for GSMConnectionHandler const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; -const char SECRET_PIN[] = "0000"; +const char SECRET_PIN[] = "0000"; // Required for NBConnectionHandler const char SECRET_GSM_USER[] = "GSM USERNAME"; const char SECRET_GSM_PASS[] = "GSM PASSWORD"; +// Required for LoRaConnectionHandler const char SECRET_APP_EUI[] = "APP_EUI"; const char SECRET_APP_KEY[] = "APP_KEY"; +// Required for EthernetConnectionHandler (without DHCP mode) const char SECRET_IP[] = "IP ADDRESS"; const char SECRET_DNS[] = "DNS ADDRESS"; const char SECRET_GATEWAY[] = "GATEWAY ADDRESS"; diff --git a/library.properties b/library.properties index 7739c63..1bb985e 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name=Arduino_ConnectionHandler version=0.8.1 author=Ubi de Feo, Cristian Maglie, Andrea Catozzi, Alexander Entinger et al. -maintainer=Arduino.cc +maintainer=Arduino sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet]) paragraph=Originally part of ArduinoIoTCloud category=Communication diff --git a/src/Arduino_EthernetConnectionHandler.cpp b/src/Arduino_EthernetConnectionHandler.cpp index 693def4..5225450 100644 --- a/src/Arduino_EthernetConnectionHandler.cpp +++ b/src/Arduino_EthernetConnectionHandler.cpp @@ -25,32 +25,38 @@ CTOR/DTOR ******************************************************************************/ -EthernetConnectionHandler::EthernetConnectionHandler(bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{INADDR_NONE} ,_dns{INADDR_NONE} ,_gateway{INADDR_NONE} ,_netmask{INADDR_NONE} +,_timeout{timeout} +,_response_timeout{responseTimeout} { } -EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{ip} ,_dns{dns} ,_gateway{gateway} ,_netmask{netmask} +,_timeout{timeout} +,_response_timeout{responseTimeout} { } -EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive) +EthernetConnectionHandler::EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout, unsigned long const responseTimeout, bool const keep_alive) : ConnectionHandler{keep_alive, NetworkAdapter::ETHERNET} ,_ip{INADDR_NONE} ,_dns{INADDR_NONE} ,_gateway{INADDR_NONE} ,_netmask{INADDR_NONE} +,_timeout{timeout} +,_response_timeout{responseTimeout} { if(!_ip.fromString(ip)) { _ip = INADDR_NONE; @@ -82,13 +88,15 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit() NetworkConnectionState EthernetConnectionHandler::update_handleConnecting() { if (_ip != INADDR_NONE) { - if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, 15000, 4000) == 0) { + if (Ethernet.begin(nullptr, _ip, _dns, _gateway, _netmask, _timeout, _response_timeout) == 0) { Debug.print(DBG_ERROR, F("Failed to configure Ethernet, check cable connection")); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); return NetworkConnectionState::CONNECTING; } } else { - if (Ethernet.begin(nullptr, 15000, 4000) == 0) { + if (Ethernet.begin(nullptr, _timeout, _response_timeout) == 0) { Debug.print(DBG_ERROR, F("Waiting Ethernet configuration from DHCP server, check cable connection")); + Debug.print(DBG_VERBOSE, "timeout: %d, response timeout: %d", _timeout, _response_timeout); return NetworkConnectionState::CONNECTING; } } diff --git a/src/Arduino_EthernetConnectionHandler.h b/src/Arduino_EthernetConnectionHandler.h index e53abba..29dde2f 100644 --- a/src/Arduino_EthernetConnectionHandler.h +++ b/src/Arduino_EthernetConnectionHandler.h @@ -40,9 +40,9 @@ class EthernetConnectionHandler : public ConnectionHandler { public: - EthernetConnectionHandler(bool const keep_alive = true); - EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, bool const keep_alive = true); - EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, bool const keep_alive = true); + EthernetConnectionHandler(unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); + EthernetConnectionHandler(const IPAddress ip, const IPAddress dns, const IPAddress gateway, const IPAddress netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); + EthernetConnectionHandler(const char * ip, const char * dns, const char * gateway, const char * netmask, unsigned long const timeout = 15000, unsigned long const responseTimeout = 4000, bool const keep_alive = true); virtual unsigned long getTime() override { return 0; } @@ -65,6 +65,9 @@ class EthernetConnectionHandler : public ConnectionHandler IPAddress _gateway; IPAddress _netmask; + unsigned long _timeout; + unsigned long _response_timeout; + EthernetUDP _eth_udp; EthernetClient _eth_client; diff --git a/src/Arduino_LoRaConnectionHandler.cpp b/src/Arduino_LoRaConnectionHandler.cpp index c0073e8..2f94910 100644 --- a/src/Arduino_LoRaConnectionHandler.cpp +++ b/src/Arduino_LoRaConnectionHandler.cpp @@ -107,7 +107,7 @@ NetworkConnectionState LoRaConnectionHandler::update_handleInit() { Debug.print(DBG_ERROR, F("Something went wrong; are you indoor? Move near a window, then reset and retry.")); return NetworkConnectionState::ERROR; - } + } // Set channelmask based on configuration if (_channelMask) { _modem.sendMask(_channelMask); diff --git a/src/Arduino_LoRaConnectionHandler.h b/src/Arduino_LoRaConnectionHandler.h index fce2cb5..fb0f560 100644 --- a/src/Arduino_LoRaConnectionHandler.h +++ b/src/Arduino_LoRaConnectionHandler.h @@ -28,6 +28,8 @@ #include #endif +#ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */ + /****************************************************************************** CLASS DECLARATION ******************************************************************************/ @@ -76,4 +78,6 @@ class LoRaConnectionHandler : public ConnectionHandler LoRaModem _modem; }; +#endif /* #ifdef BOARD_HAS_LORA */ + #endif /* ARDUINO_LORA_CONNECTION_HANDLER_H_ */