Skip to content

Commit

Permalink
Merge branch 'master' into include-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andreagilardoni authored Jun 5, 2024
2 parents 6569c17 + 5022993 commit e8b1fb7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
6 changes: 5 additions & 1 deletion examples/ConnectionHandlerDemo/arduino_secrets.h
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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 <info@arduino.cc>
sentence=Arduino Library for network connection management (WiFi, GSM, NB, [Ethernet])
paragraph=Originally part of ArduinoIoTCloud
category=Communication
Expand Down
18 changes: 13 additions & 5 deletions src/Arduino_EthernetConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/Arduino_EthernetConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Arduino_LoRaConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Arduino_LoRaConnectionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <MKRWAN.h>
#endif

#ifdef BOARD_HAS_LORA /* Only compile if the board has LoRa */

/******************************************************************************
CLASS DECLARATION
******************************************************************************/
Expand Down Expand Up @@ -76,4 +78,6 @@ class LoRaConnectionHandler : public ConnectionHandler
LoRaModem _modem;
};

#endif /* #ifdef BOARD_HAS_LORA */

#endif /* ARDUINO_LORA_CONNECTION_HANDLER_H_ */

0 comments on commit e8b1fb7

Please sign in to comment.