Skip to content

Commit 75f0495

Browse files
committed
Fix multiple board support by adding boardId
1 parent 8c9ecbe commit 75f0495

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

EmberIot.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class EmberIot : WithSecureClient
2222
public:
2323
EmberIot(const char* dbUrl,
2424
const char* deviceId,
25+
const unsigned int &boardId = 0,
2526
const char* username = nullptr,
2627
const char* password = nullptr,
2728
const char* webApiKey = nullptr) : dbUrl(dbUrl)
@@ -32,6 +33,7 @@ class EmberIot : WithSecureClient
3233
auth = nullptr;
3334
lastUpdatedChannels = 0;
3435
lastHeartbeat = -UPDATE_LAST_SEEN_INTERVAL;
36+
snprintf(EmberIotChannels::boardId, sizeof(EmberIotChannels::boardId), "%d", boardId);
3537

3638
if (username != nullptr && password != nullptr && webApiKey != nullptr)
3739
{
@@ -104,7 +106,7 @@ class EmberIot : WithSecureClient
104106
char buf[5];
105107
sprintf(buf, "CH%d", i);
106108
doc[buf]["d"] = updateDataByChannel[i];
107-
doc[buf]["w"] = EMBER_DEVICE_TYPE;
109+
doc[buf]["w"] = EmberIotChannels::boardId;
108110
}
109111

110112
unsigned int bodySize = measureJson(doc)+2;

EmberIotHttp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
#include <ArduinoJson.h>
99
#include <WiFiClientSecure.h>
1010

11+
#ifdef EMBER_ENABLE_LOGGING
1112
#define HTTP_LOGN(str) Serial.println(str)
1213
#define HTTP_LOGF(str, p...) Serial.printf(str, p)
14+
#else
15+
#define HTTP_LOGN(str)
16+
#define HTTP_LOGF(str, p...)
17+
#endif
1318

1419
namespace HTTP_UTIL
1520
{

EmberIotShared.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
#include <EmberIotHttp.h>
2525

26-
const char *EMBER_DEVICE_TYPE PROGMEM = "board";
27-
2826
class EmberIotProp
2927
{
3028
public:
@@ -68,6 +66,7 @@ namespace EmberIotChannels
6866
bool started = false;
6967
EmberIotUpdateCallback callbacks[EMBER_CHANNEL_COUNT]{};
7068
bool firstCallbackDone = false;
69+
char boardId[8] = "0";
7170

7271
inline void streamCallback(const char* data)
7372
{
@@ -107,7 +106,7 @@ namespace EmberIotChannels
107106
if (dataDoc[name]["w"].is<JsonVariant>() && firstCallbackDone)
108107
{
109108
const char *who = dataDoc[name]["w"].as<const char*>();
110-
if (strcmp(who, EMBER_DEVICE_TYPE) == 0)
109+
if (strcmp(who, boardId) == 0)
111110
{
112111
HTTP_LOGN("Event was self-made, ignoring.");
113112
continue;

0 commit comments

Comments
 (0)