Skip to content

Allow build without ArduinoConnectionHandler #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TCP: make begin(bool, String uint16_t, bool) private
  • Loading branch information
pennam committed Jun 5, 2025
commit 3b6713ede97f7e4bfac449552d3b9e464080c0d2
118 changes: 59 additions & 59 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,65 +139,6 @@ int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_
return begin(enable_watchdog, _brokerAddress, _brokerPort, auto_reconnect);
}

int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress, uint16_t brokerPort, bool auto_reconnect)
{
_enable_watchdog = enable_watchdog;
_brokerAddress = brokerAddress;
_brokerPort = brokerPort;
_auto_reconnect = auto_reconnect;

_state = State::ConfigPhy;

_mqttClient.setClient(_brokerClient);

#ifdef BOARD_HAS_SECRET_KEY
if(_password.length())
{
_mqttClient.setUsernamePassword(getDeviceId(), _password);
}
#endif

_mqttClient.onMessage(ArduinoIoTCloudTCP::onMessage);
_mqttClient.setKeepAliveInterval(30 * 1000);
_mqttClient.setConnectionTimeout(1500);
_mqttClient.setId(getDeviceId().c_str());

_messageTopicOut = getTopic_messageout();
_messageTopicIn = getTopic_messagein();

_thing.begin();
_device.begin();

#if OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)
_ota.setClient(&_otaClient);
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)

#if OTA_ENABLED && defined(OTA_BASIC_AUTH)
_ota.setAuthentication(getDeviceId().c_str(), _password.c_str());
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD) && defined(OTA_BASIC_AUTH)

#ifdef BOARD_HAS_OFFLOADED_ECCX08
if (String(WiFi.firmwareVersion()) < String("1.6.0")) {
DEBUG_ERROR("ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, NINA firmware needs to be >= 1.6.0, current %s", __FUNCTION__, WiFi.firmwareVersion());
return 0;
}
#endif /* BOARD_HAS_OFFLOADED_ECCX08 */

#if defined (ARDUINO_UNOWIFIR4)
if (String(WiFi.firmwareVersion()) < String("0.2.0")) {
DEBUG_ERROR("ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, WiFi firmware needs to be >= 0.2.0, current %s", __FUNCTION__, WiFi.firmwareVersion());
}
#endif

#if NETWORK_CONFIGURATOR_ENABLED
if(_configurator != nullptr){
_configurator->enableAgent(ConfiguratorAgent::AgentTypes::BLE,false);
_configurator->begin();
}
#endif
return 1;
}

void ArduinoIoTCloudTCP::update()
{
/* Feed the watchdog. If any of the functions called below
Expand Down Expand Up @@ -295,6 +236,65 @@ void ArduinoIoTCloudTCP::disconnect() {
* PRIVATE MEMBER FUNCTIONS
******************************************************************************/

int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress, uint16_t brokerPort, bool auto_reconnect)
{
_enable_watchdog = enable_watchdog;
_brokerAddress = brokerAddress;
_brokerPort = brokerPort;
_auto_reconnect = auto_reconnect;

_state = State::ConfigPhy;

_mqttClient.setClient(_brokerClient);

#ifdef BOARD_HAS_SECRET_KEY
if(_password.length())
{
_mqttClient.setUsernamePassword(getDeviceId(), _password);
}
#endif

_mqttClient.onMessage(ArduinoIoTCloudTCP::onMessage);
_mqttClient.setKeepAliveInterval(30 * 1000);
_mqttClient.setConnectionTimeout(1500);
_mqttClient.setId(getDeviceId().c_str());

_messageTopicOut = getTopic_messageout();
_messageTopicIn = getTopic_messagein();

_thing.begin();
_device.begin();

#if OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)
_ota.setClient(&_otaClient);
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)

#if OTA_ENABLED && defined(OTA_BASIC_AUTH)
_ota.setAuthentication(getDeviceId().c_str(), _password.c_str());
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD) && defined(OTA_BASIC_AUTH)

#ifdef BOARD_HAS_OFFLOADED_ECCX08
if (String(WiFi.firmwareVersion()) < String("1.6.0")) {
DEBUG_ERROR("ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, NINA firmware needs to be >= 1.6.0, current %s", __FUNCTION__, WiFi.firmwareVersion());
return 0;
}
#endif /* BOARD_HAS_OFFLOADED_ECCX08 */

#if defined (ARDUINO_UNOWIFIR4)
if (String(WiFi.firmwareVersion()) < String("0.2.0")) {
DEBUG_ERROR("ArduinoIoTCloudTCP::%s In order to connect to Arduino IoT Cloud, WiFi firmware needs to be >= 0.2.0, current %s", __FUNCTION__, WiFi.firmwareVersion());
}
#endif

#if NETWORK_CONFIGURATOR_ENABLED
if(_configurator != nullptr){
_configurator->enableAgent(ConfiguratorAgent::AgentTypes::BLE,false);
_configurator->begin();
}
#endif
return 1;
}

ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConfigPhy()
{
#if NETWORK_CONFIGURATOR_ENABLED
Expand Down
4 changes: 3 additions & 1 deletion src/ArduinoIoTCloudTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
virtual void disconnect () override;

int begin(ConnectionHandler & connection, bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool auto_reconnect = true);
int begin(bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool auto_reconnect = true);

#if defined(BOARD_HAS_SECURE_ELEMENT)
int updateCertificate(String authorityKeyIdentifier, String serialNumber, String notBefore, String notAfter, String signature);
Expand Down Expand Up @@ -117,6 +116,9 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
#endif

private:

int begin(bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS, uint16_t brokerPort = DEFAULT_BROKER_PORT_AUTO, bool auto_reconnect = true);

static const int MQTT_TRANSMIT_BUFFER_SIZE = 256;

enum class State
Expand Down