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 all commits
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
73 changes: 73 additions & 0 deletions examples/ArduinoIoTCloud-WiFiClient/ArduinoIoTCloud-WiFiClient.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
This sketch demonstrates how to use Arduino IoT Cloud without ArduinoConnectionHandler

* Connect a potentiometer (or other analog sensor) to A0.
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.

IMPORTANT:
This sketch works with only with WiFi.

The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/

#include <WiFi.h>
#include "thingProperties.h"

#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif

WiFiClient brokerClient;
WiFiClient otaClient;
WiFiUDP ntpClient;

void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }

int status = WL_IDLE_STATUS;
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_WIFI_SSID);
status = WiFi.begin(SECRET_WIFI_SSID, SECRET_WIFI_PASS);
delay(1000);
}

/* Set the debug message level:
* - DBG_ERROR: Only show error messages
* - DBG_WARNING: Show warning and error messages
* - DBG_INFO: Show info, warning, and error messages
* - DBG_DEBUG: Show debug, info, warning, and error messages
* - DBG_VERBOSE: Show all messages
*/
setDebugMessageLevel(DBG_INFO);

/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);

/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();

/* Initialize Arduino IoT Cloud library */
ArduinoCloud.begin(brokerClient, otaClient, ntpClient);

ArduinoCloud.printDebugInfo();
}

void loop() {
ArduinoCloud.update();
potentiometer = analogRead(A0);
seconds = millis() / 1000;
}

/*
* 'onLedChange' is called when the "led" property of your Thing changes
*/
void onLedChange() {
Serial.print("LED set to ");
Serial.println(led);
digitalWrite(LED_BUILTIN, led);
}
9 changes: 9 additions & 0 deletions examples/ArduinoIoTCloud-WiFiClient/arduino_secrets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* A complete list of supported boards with WiFi is available here:
* https://github.com/arduino-libraries/ArduinoIoTCloud/#what
*/

#define SECRET_WIFI_SSID "YOUR_WIFI_NETWORK_NAME"
#define SECRET_WIFI_PASS "YOUR_WIFI_PASSWORD"

/* Configure this if you want to use username/password broker authentication */
#define SECRET_DEVICE_KEY "my-device-password"
28 changes: 28 additions & 0 deletions examples/ArduinoIoTCloud-WiFiClient/thingProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <ArduinoIoTCloud.h>
#include "arduino_secrets.h"

#if !defined(HAS_TCP)
#error "Please check Arduino IoT Cloud supported boards list: https://github.com/arduino-libraries/ArduinoIoTCloud/#what"
#endif

#if !defined(BOARD_HAS_SECURE_ELEMENT)
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
#endif

void onLedChange();

bool led;
int potentiometer;
int seconds;

void initProperties() {
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);
ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1);

#if !defined(BOARD_HAS_SECURE_ELEMENT)
ArduinoCloud.setBoardId(BOARD_ID);
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
#endif
}

2 changes: 1 addition & 1 deletion examples/utility/Provisioning_2.0/CSRHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool CSRHandlerClass::begin(ConnectionHandler &connectionHandler, SecureElement
_fw_version = WiFi.firmwareVersion();
#endif
if(!_tlsClient){
_tlsClient = new TLSClientMqtt();
_tlsClient = new TLSClientBroker();
}
_tlsClient->begin(*_connectionHandler);
_tlsClient->setTimeout(RESPONSE_TIMEOUT);
Expand Down
4 changes: 2 additions & 2 deletions examples/utility/Provisioning_2.0/CSRHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <Arduino.h>
#include <Arduino_ConnectionHandler.h>
#include <Arduino_SecureElement.h>
#include <tls/utility/TLSClientMqtt.h>
#include <tls/utility/TLSClientBroker.h>
#include <ArduinoHttpClient.h>
#include "utility/LEDFeedback.h"
#define JITTER_BASE 0
Expand Down Expand Up @@ -55,7 +55,7 @@ class CSRHandlerClass {
ECP256Certificate *_certForCSR;
ConnectionHandler *_connectionHandler;
SecureElement *_secureElement;
TLSClientMqtt *_tlsClient;
TLSClientBroker *_tlsClient;
HttpClient *_client;
LEDFeedbackClass &_ledFeedback;
void updateNextRequestAt();
Expand Down
3 changes: 3 additions & 0 deletions extras/test/include/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
******************************************************************************/

typedef std::string String;
typedef struct {
void * udp;
} UDP;

/******************************************************************************
FUNCTION PROTOTYPES
Expand Down
12 changes: 10 additions & 2 deletions src/AIoTC_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
* AUTOMATICALLY CONFIGURED DEFINES
******************************************************************************/

#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
#define DEBUG_ENABLED (1)
#else
#define DEBUG_ENABLED (0)
#endif

#if !defined(HAS_NOTECARD)

#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT)
Expand Down Expand Up @@ -148,8 +154,10 @@
#define BOARD_STM32H7
#endif

#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA) \
|| defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)
#define CONNECTION_HANDLER_ENABLED (1)

#if ((defined(BOARD_STM32H7) || defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_PORTENTA_C33)) &&\
(defined(CONNECTION_HANDLER_ENABLED) && (CONNECTION_HANDLER_ENABLED == 1)))
#define NETWORK_CONFIGURATOR_ENABLED (1)
#else
#define NETWORK_CONFIGURATOR_ENABLED (0)
Expand Down
6 changes: 4 additions & 2 deletions src/ArduinoIoTCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
******************************************************************************/

ArduinoIoTCloudClass::ArduinoIoTCloudClass()
: _connection{nullptr}
: _time_service(TimeService)
#if CONNECTION_HANDLER_ENABLED
,_connection{nullptr}
#endif
#if NETWORK_CONFIGURATOR_ENABLED
, _configurator{nullptr}
#endif
, _time_service(TimeService)
, _thing_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
, _lib_version{AIOT_CONFIG_LIB_VERSION}
, _device_id{"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
Expand Down
21 changes: 14 additions & 7 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

#include <AIoTC_Config.h>

#include <Arduino_ConnectionHandler.h>
#if CONNECTION_HANDLER_ENABLED
#include <Arduino_ConnectionHandler.h>
#endif

#if NETWORK_CONFIGURATOR_ENABLED
#include <Arduino_NetworkConfigurator.h>
#endif

#if defined(DEBUG_ERROR) || defined(DEBUG_WARNING) || defined(DEBUG_INFO) || defined(DEBUG_DEBUG) || defined(DEBUG_VERBOSE)
#if DEBUG_ENABLED
#include <Arduino_DebugUtils.h>
#endif

Expand Down Expand Up @@ -99,14 +102,16 @@ class ArduinoIoTCloudClass
inline void setDeviceId(String const device_id) { _device_id = device_id; };
inline String & getDeviceId() { return _device_id; };

#if CONNECTION_HANDLER_ENABLED
inline ConnectionHandler * getConnection() { return _connection; }
#endif

inline unsigned long getInternalTime() { return _time_service.getTime(); }
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }

#if NETWORK_CONFIGURATOR_ENABLED
#if NETWORK_CONFIGURATOR_ENABLED
inline void setConfigurator(NetworkConfiguratorClass & configurator) { _configurator = &configurator; }
#endif
#endif
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);

#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
Expand Down Expand Up @@ -151,11 +156,13 @@ class ArduinoIoTCloudClass

protected:

TimeServiceClass & _time_service;
#if CONNECTION_HANDLER_ENABLED
ConnectionHandler * _connection;
#if NETWORK_CONFIGURATOR_ENABLED
#endif
#if NETWORK_CONFIGURATOR_ENABLED
NetworkConfiguratorClass * _configurator;
#endif
TimeServiceClass & _time_service;
#endif
String _thing_id;
String _lib_version;

Expand Down
4 changes: 4 additions & 0 deletions src/ArduinoIoTCloudDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "ArduinoIoTCloudDevice.h"
#include "interfaces/CloudProcess.h"

#if DEBUG_ENABLED
#include <Arduino_DebugUtils.h>
#endif

/******************************************************************************
CTOR/DTOR
******************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudLPWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int ArduinoIoTCloudLPWAN::begin(ConnectionHandler& connection, bool retry)
{
_connection = &connection;
_retryEnable = retry;
_time_service.begin(nullptr);
_time_service.begin();
return 1;
}

Expand Down
Loading
Loading