Skip to content

Commit 401a92a

Browse files
committed
chore: Update LoRa details
1 parent 0bfaa5d commit 401a92a

File tree

7 files changed

+59
-19
lines changed

7 files changed

+59
-19
lines changed

examples/ArduinoIoTCloud-Advanced/thingProperties.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
#if defined(USE_NOTECARD)
1519
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
1620
* or UART. An empty string (or the default value provided below) will not
@@ -31,6 +35,9 @@ void initProperties() {
3135
ArduinoCloud.setBoardId(BOARD_ID);
3236
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
3337
#endif
38+
#if defined(BOARD_HAS_LORA)
39+
ArduinoCloud.setThingId(THING_ID);
40+
#endif
3441
#if defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
3542
ArduinoCloud.addProperty(switchButton, Permission::Write).onUpdate(onSwitchButtonChange);
3643
ArduinoCloud.addProperty(location, Permission::Read).publishOnChange(0.0f);

examples/ArduinoIoTCloud-Basic/thingProperties.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
#if defined(USE_NOTECARD)
1519
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
1620
* or UART. An empty string (or the default value provided below) will not
@@ -30,6 +34,9 @@ void initProperties() {
3034
ArduinoCloud.setBoardId(BOARD_ID);
3135
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
3236
#endif
37+
#if defined(BOARD_HAS_LORA)
38+
ArduinoCloud.setThingId(THING_ID);
39+
#endif
3340
#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
3441
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
3542
ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10);

examples/ArduinoIoTCloud-Callbacks/thingProperties.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
#if defined(USE_NOTECARD)
1519
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
1620
* or UART. An empty string (or the default value provided below) will not
@@ -24,6 +28,9 @@ void initProperties() {
2428
ArduinoCloud.setBoardId(BOARD_ID);
2529
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
2630
#endif
31+
#if defined(BOARD_HAS_LORA)
32+
ArduinoCloud.setThingId(THING_ID);
33+
#endif
2734
}
2835

2936
#if defined(USE_NOTECARD)

examples/ArduinoIoTCloud-Notecard/ArduinoIoTCloud-Notecard.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void setup() {
4444
/* Initialize Arduino IoT Cloud library */
4545
#ifndef ATTN_PIN
4646
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
47-
ArduinoCloud.setNotecardPollInterval(3000); // default: 1000ms, min: 250ms
47+
ArduinoCloud.setNotecardPollingInterval(3000); // default: 1000ms, min: 250ms
4848
#else
4949
ArduinoCloud.begin(ArduinoIoTPreferredConnection, ATTN_PIN);
5050
#endif

examples/ArduinoIoTCloud-Schedule/thingProperties.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1212
#endif
1313

14+
#if defined(BOARD_HAS_LORA)
15+
#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
16+
#endif
17+
1418
#if defined(USE_NOTECARD)
1519
/* The Notecard can provide connectivity to almost any board via ESLOV (I2C)
1620
* or UART. An empty string (or the default value provided below) will not
@@ -35,6 +39,9 @@ void initProperties() {
3539
ArduinoCloud.setBoardId(BOARD_ID);
3640
ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY);
3741
#endif
42+
#if defined(BOARD_HAS_LORA)
43+
ArduinoCloud.setThingId(THING_ID);
44+
#endif
3845
#if defined(USE_NOTECARD) || defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) || defined(BOARD_HAS_ETHERNET) || defined(BOARD_HAS_CATM1_NBIOT)
3946
ArduinoCloud.addProperty(switchButton, Permission::Write);
4047
ArduinoCloud.addProperty(oneShot, Permission::ReadWrite);

src/ArduinoIoTCloudNotecard.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
* CONSTANTS
4444
******************************************************************************/
4545

46-
static size_t const CBOR_NOTE_MSG_MAX_SIZE = 255;
46+
static size_t const LORA_CBOR_MSG_MAX_SIZE = 242;
47+
static size_t const LORA_PAYLOAD_MAX_SIZE = 236;
4748
static size_t const DEFAULT_READ_INTERVAL_MS = 1000; // 1 second
4849
static size_t const FAILSAFE_READ_INTERVAL_MS = 15000; // 15 seconds
4950

@@ -73,7 +74,7 @@ ArduinoIoTCloudNotecard::ArduinoIoTCloudNotecard()
7374
,_thing(&_message_stream)
7475
,_device(&_message_stream)
7576
,_notecard_last_poll_ms{static_cast<uint32_t>(-DEFAULT_READ_INTERVAL_MS)}
76-
,_notecard_poll_interval_ms{DEFAULT_READ_INTERVAL_MS}
77+
,_notecard_polling_interval_ms{DEFAULT_READ_INTERVAL_MS}
7778
,_interrupt_pin{-1}
7879
,_data_available{false}
7980
#if OTA_ENABLED
@@ -278,7 +279,7 @@ bool ArduinoIoTCloudNotecard::available(void)
278279
const bool interrupts_enabled = (_interrupt_pin >= 0);
279280
const uint32_t now_ms = ::millis();
280281

281-
bool check_data = ((now_ms - _notecard_last_poll_ms) > _notecard_poll_interval_ms);
282+
bool check_data = ((now_ms - _notecard_last_poll_ms) > _notecard_polling_interval_ms);
282283
if (interrupts_enabled) {
283284
check_data = (_data_available || ((now_ms - _notecard_last_poll_ms) > FAILSAFE_READ_INTERVAL_MS));
284285
}
@@ -354,8 +355,8 @@ void ArduinoIoTCloudNotecard::pollNotecard(void)
354355
{
355356
/* Decode available data. */
356357
if (available()) {
357-
size_t note_len = CBOR_NOTE_MSG_MAX_SIZE;
358-
uint8_t note_buf[CBOR_NOTE_MSG_MAX_SIZE];
358+
size_t note_len = LORA_CBOR_MSG_MAX_SIZE;
359+
uint8_t note_buf[LORA_CBOR_MSG_MAX_SIZE];
359360
fetchIncomingBytes(note_buf, note_len);
360361
processMessage(note_buf, note_len);
361362
}
@@ -471,7 +472,7 @@ void ArduinoIoTCloudNotecard::sendMessage(Message * msg)
471472
{
472473
switch (msg->id) {
473474
case PropertiesUpdateCmdId:
474-
return sendThingPropertyContainerToCloud();
475+
sendThingPropertyContainerToCloud();
475476
break;
476477

477478
default:
@@ -482,17 +483,23 @@ void ArduinoIoTCloudNotecard::sendMessage(Message * msg)
482483

483484
void ArduinoIoTCloudNotecard::sendCommandMsgToCloud(Message * msg_)
484485
{
485-
size_t bytes_encoded = CBOR_NOTE_MSG_MAX_SIZE;
486-
uint8_t data[CBOR_NOTE_MSG_MAX_SIZE];
486+
size_t bytes_encoded = LORA_CBOR_MSG_MAX_SIZE;
487+
uint8_t data[LORA_CBOR_MSG_MAX_SIZE];
487488
CBORMessageEncoder encoder;
488489
NotecardConnectionHandler *notecard_connection = reinterpret_cast<NotecardConnectionHandler *>(_connection);
489490

490491
if (encoder.encode(msg_, data, bytes_encoded) == Encoder::Status::Complete) {
491-
if (bytes_encoded > 0) {
492+
if (LORA_PAYLOAD_MAX_SIZE < bytes_encoded) {
493+
DEBUG_WARNING("Encoded %d bytes for Command Message. Exceeds maximum payload size of %d bytes, and cannot be sent to cloud.", bytes_encoded, LORA_PAYLOAD_MAX_SIZE);
494+
} else if (bytes_encoded > 0) {
495+
DEBUG_DEBUG("Encoded %d bytes for Command Message", bytes_encoded);
492496
notecard_connection->setTopicType(NotecardConnectionHandler::TopicType::Command);
493-
notecard_connection->write(data, bytes_encoded);
497+
if (notecard_connection->write(data, bytes_encoded)) {
498+
DEBUG_ERROR("Failed to send Command Message to cloud");
499+
}
500+
} else {
501+
DEBUG_DEBUG("No bytes encoded for Command Message");
494502
}
495-
DEBUG_DEBUG("Encoded %d bytes for Command Message", bytes_encoded);
496503
} else {
497504
DEBUG_ERROR("Failed to encode Command Message");
498505
}
@@ -501,15 +508,19 @@ void ArduinoIoTCloudNotecard::sendCommandMsgToCloud(Message * msg_)
501508
void ArduinoIoTCloudNotecard::sendThingPropertyContainerToCloud()
502509
{
503510
int bytes_encoded = 0;
504-
uint8_t data[CBOR_NOTE_MSG_MAX_SIZE];
511+
uint8_t data[LORA_CBOR_MSG_MAX_SIZE];
505512
NotecardConnectionHandler *notecard_connection = reinterpret_cast<NotecardConnectionHandler *>(_connection);
506513

507514
// Check if any property needs encoding and send them to the cloud
508515
if (CBOREncoder::encode(_thing.getPropertyContainer(), data, sizeof(data), bytes_encoded, _thing.getPropertyContainerIndex(), USE_LIGHT_PAYLOADS) == CborNoError) {
509-
if (bytes_encoded > 0) {
510-
notecard_connection->setTopicType(NotecardConnectionHandler::TopicType::Thing);
511-
notecard_connection->write(data, bytes_encoded);
516+
if (LORA_PAYLOAD_MAX_SIZE < bytes_encoded) {
517+
DEBUG_ERROR("Encoded %d bytes for Thing properties. Exceeds maximum encoded payload size of %d bytes, and cannot sync with cloud.", bytes_encoded, LORA_PAYLOAD_MAX_SIZE);
518+
} else if (bytes_encoded > 0) {
512519
DEBUG_DEBUG("Encoded %d bytes for Thing properties", bytes_encoded);
520+
notecard_connection->setTopicType(NotecardConnectionHandler::TopicType::Thing);
521+
if (notecard_connection->write(data, bytes_encoded)) {
522+
DEBUG_ERROR("Failed to sync Thing properties with cloud");
523+
}
513524
}
514525
} else {
515526
DEBUG_ERROR("Failed to encode Thing properties");

src/ArduinoIoTCloudNotecard.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
8181
/**
8282
* @brief Set the Notecard polling interval.
8383
*
84-
* The interval at which the Notecard is polled for new data.
84+
* The interval at which the Notecard is polled (via I2C/UART) for new data.
85+
* This is not a network transaction, but a local polling of the Notecard.
8586
*
8687
* @param interval_ms The interval in milliseconds.
8788
* @par
@@ -91,7 +92,7 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
9192
* @note The Notecard poll interval is ignored if an interrupt pin is
9293
* provided to the `begin()` function.
9394
*/
94-
inline void setNotecardPollInterval(uint32_t interval_ms) { _notecard_poll_interval_ms = ((interval_ms < 250) ? 250 : interval_ms); }
95+
inline void setNotecardPollingInterval(uint32_t interval_ms) { _notecard_polling_interval_ms = ((interval_ms < 250) ? 250 : interval_ms); }
9596

9697
private:
9798

@@ -111,7 +112,7 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
111112

112113
// Notecard member variables
113114
uint32_t _notecard_last_poll_ms;
114-
uint32_t _notecard_poll_interval_ms;
115+
uint32_t _notecard_polling_interval_ms;
115116
int _interrupt_pin;
116117
volatile bool _data_available;
117118

0 commit comments

Comments
 (0)