Skip to content

Commit f245a02

Browse files
committed
chore: Strip BOARD_HAS_SECRET_KEY
1 parent 6505195 commit f245a02

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

src/AIoTC_Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#if defined __has_include
2222
#if __has_include (<Notecard.h>)
2323
#define USE_NOTECARD
24-
#define BOARD_HAS_SECRET_KEY
2524
#endif
2625
#endif
2726

src/ArduinoIoTCloudNotecard.cpp

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <algorithm>
2929
#include <functional>
3030

31+
#include <Arduino.h>
3132
#include <Arduino_NotecardConnectionHandler.h>
3233

3334
#include "cbor/CBOREncoder.h"
@@ -79,9 +80,6 @@ ArduinoIoTCloudNotecard::ArduinoIoTCloudNotecard()
7980
,_notecard_read_interval_ms{DEFAULT_READ_INTERVAL_MS}
8081
,_interrupt_pin{-1}
8182
,_data_available{false}
82-
#if defined(BOARD_HAS_SECRET_KEY)
83-
,_secret_device_key{""}
84-
#endif /* BOARD_HAS_SECRET_KEY */
8583
#if OTA_ENABLED
8684
,_ota_cap{false}
8785
,_ota_error{static_cast<int>(OTAError::None)}
@@ -99,33 +97,36 @@ ArduinoIoTCloudNotecard::ArduinoIoTCloudNotecard()
9997
* PUBLIC MEMBER FUNCTIONS
10098
******************************************************************************/
10199

102-
int ArduinoIoTCloudNotecard::begin(ConnectionHandler &connection, int interrupt_pin)
100+
int ArduinoIoTCloudNotecard::begin(ConnectionHandler &connection_, int interrupt_pin_)
103101
{
104-
_connection = &connection;
102+
_connection = &connection_;
103+
NotecardConnectionHandler *notecard_connection = reinterpret_cast<NotecardConnectionHandler *>(_connection);
104+
105+
// Configure the interrupt pin
106+
if (interrupt_pin_ >= 0) {
107+
_interrupt_pin = interrupt_pin_;
108+
::pinMode(_interrupt_pin, INPUT);
109+
::attachInterrupt(digitalPinToInterrupt(_interrupt_pin), ISR_dataAvailable, RISING);
110+
notecard_connection->enableHardwareInterrupts();
111+
}
112+
113+
// Initialize the connection to the Notecard
105114
if (NetworkConnectionState::ERROR == _connection->check()) {
106115
DEBUG_ERROR("ArduinoIoTCloudNotecard::%s encountered fatal connection error!", __FUNCTION__);
107116
return 0; // (false -> failure)
108117
}
109118

110-
#ifdef BOARD_HAS_SECRET_KEY
111-
// Update Device ID using connection cache
112-
setBoardId(getDeviceId());
113-
#endif
114-
115-
// Configure the interrupt pin
116-
if (interrupt_pin >= 0) {
117-
::pinMode(interrupt_pin, INPUT);
118-
::attachInterrupt(digitalPinToInterrupt(interrupt_pin), ISR_dataAvailable, RISING);
119-
_interrupt_pin = interrupt_pin;
120-
}
119+
//TODO: Remove if not needed
120+
// Pull the Arduino IoT Cloud Device ID from the Notecard
121+
setDeviceId(notecard_connection->getDeviceId());
121122

122123
#if OTA_ENABLED
123124
/* Setup OTA TLS client */
124125
_otaClient.begin(connection);
125126
#endif
126127

127128
// Begin the Notecard time service
128-
_time_service.begin(&connection);
129+
_time_service.begin(&connection_);
129130

130131
/* Setup retry timers */
131132
_connection_attempt.begin(AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms, AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms);
@@ -148,6 +149,7 @@ void ArduinoIoTCloudNotecard::printDebugInfo()
148149
NetworkConnectionState conn_state = _connection->check();
149150
DEBUG_INFO("***** Arduino IoT Cloud Notecard - configuration info *****");
150151
DEBUG_INFO("Notecard UID: %s", reinterpret_cast<NotecardConnectionHandler *>(_connection)->getNotecardUid().c_str());
152+
//TODO: Remove if not needed
151153
DEBUG_INFO("Arduino Device ID: %s", getDeviceId().c_str());
152154
if (NetworkConnectionState::CONNECTED == conn_state)
153155
{
@@ -167,7 +169,6 @@ void ArduinoIoTCloudNotecard::update()
167169
{
168170
case State::ConnectPhy: next_state = handle_ConnectPhy(); break;
169171
case State::SyncTime: next_state = handle_SyncTime(); break;
170-
case State::ConfigureNotehub: next_state = handle_ConfigureNotehub(); break;
171172
case State::Connected: next_state = handle_Connected(); break;
172173
case State::Disconnect: next_state = handle_Disconnect(); break;
173174
}
@@ -199,39 +200,20 @@ ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_SyncTime()
199200
if (TimeServiceClass::isTimeValid(current_time))
200201
{
201202
DEBUG_VERBOSE("ArduinoIoTCloudNotecard::%s internal clock configured to posix timestamp %d", __FUNCTION__, current_time);
202-
return State::ConfigureNotehub;
203+
return State::Connected;
203204
}
204205

205206
DEBUG_ERROR("ArduinoIoTCloudNotecard::%s could not get valid time. Retrying now.", __FUNCTION__);
206207
return State::ConnectPhy;
207208
}
208209

209-
ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_ConfigureNotehub()
210-
{
211-
if (!connected())
212-
{
213-
DEBUG_ERROR("ArduinoIoTCloudNotecard::%s connection to Notehub lost", __FUNCTION__);
214-
return State::ConnectPhy;
215-
}
216-
217-
#if defined(BOARD_HAS_SECRET_KEY)
218-
if (reinterpret_cast<NotecardConnectionHandler *>(_connection)->syncSecretDeviceKey(_secret_device_key)) {
219-
DEBUG_WARNING("ArduinoIoTCloudNotecard::%s failed to set secret device key", __FUNCTION__);
220-
DEBUG_WARNING("You may manually enter the secret key on Notehub as a device level environment variable named `arduino_iot_cloud_secret_device_key`");
221-
}
222-
#endif
223-
224-
return State::Connected;
225-
}
226-
227210
ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_Connected()
228211
{
229212
if (!connected() || !_thing.connected() || !_device.connected())
230213
{
231214
return State::Disconnect;
232215
}
233216

234-
//TODO: Understand how available applies to the _device.update() and _thing.update()
235217
/* Poll Notecard for new messages */
236218
pollNotecard();
237219

src/ArduinoIoTCloudNotecard.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ typedef bool (*onOTARequestCallbackFunc)(void);
4848
* CLASS DECLARATION
4949
******************************************************************************/
5050

51+
/**
52+
* @brief The ArduinoIoTCloudNotecard class
53+
*
54+
* This class is used to connect to the Arduino IoT Cloud using a Notecard.
55+
*/
5156
class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
5257
{
5358
public:
@@ -59,13 +64,30 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
5964
virtual void printDebugInfo() override;
6065
inline virtual PropertyContainer &getThingPropertyContainer() override { return _thing.getPropertyContainer(); }
6166

67+
/**
68+
* @brief Begin the connection to the Arduino IoT Cloud.
69+
*
70+
* @param connection The connection handler to use.
71+
* @param interrupt_pin The interrupt pin to use for the Notecard.
72+
*
73+
* @note The interrupt pin is optional and only required if you want to
74+
* eliminate the need to poll the Notecard for new data.
75+
*
76+
* @return 1 on success, 0 on failure.
77+
*/
6278
int begin(ConnectionHandler &connection, int interrupt_pin = -1);
6379

64-
#ifdef BOARD_HAS_SECRET_KEY
65-
inline void setBoardId (String const & device_id) { (_connection && (NetworkConnectionState::INIT != _connection->check())) ? setDeviceId(reinterpret_cast<NotecardConnectionHandler *>(_connection)->syncArduinoDeviceId(device_id)) : setDeviceId(device_id); }
66-
inline void setSecretDeviceKey(String const & secret_device_key) { _secret_device_key = secret_device_key; }
67-
#endif
68-
80+
/**
81+
* @brief Set the Notecard read interval.
82+
*
83+
* The interval at which the Notecard is polled for new data. The default
84+
* interval is 1000ms, and the minimum interval is 250ms.
85+
*
86+
* @param interval_ms The interval in milliseconds.
87+
*
88+
* @note The Notecard read interval is ignored if an interrupt pin is
89+
* provided to the `begin()` function.
90+
*/
6991
inline void setNotecardReadInterval(uint32_t interval_ms) { _notecard_read_interval_ms = ((interval_ms < 250) ? 250 : interval_ms); }
7092

7193
private:
@@ -74,7 +96,6 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
7496
{
7597
ConnectPhy,
7698
SyncTime,
77-
ConfigureNotehub,
7899
Connected,
79100
Disconnect,
80101
};
@@ -93,10 +114,6 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
93114
int _interrupt_pin;
94115
volatile bool _data_available;
95116

96-
#ifdef BOARD_HAS_SECRET_KEY
97-
String _secret_device_key;
98-
#endif
99-
100117
#if OTA_ENABLED
101118
// OTA member variables
102119
bool _ota_cap;
@@ -110,7 +127,6 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
110127

111128
State handle_ConnectPhy();
112129
State handle_SyncTime();
113-
State handle_ConfigureNotehub();
114130
State handle_Connected();
115131
State handle_Disconnect();
116132

@@ -137,4 +153,4 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
137153

138154
extern ArduinoIoTCloudNotecard ArduinoCloud;
139155

140-
#endif
156+
#endif // ARDUINO_IOT_CLOUD_NOTECARD_H

0 commit comments

Comments
 (0)