@@ -22,15 +22,17 @@ static void utox8(uint32_t val, char* s) {
22
22
#endif
23
23
24
24
#ifdef USE_ARDUINO_CLOUD
25
-
26
25
char MQTT_SERVER[] = " 10.130.22.94" ;
27
26
int MQTT_PORT = 1883 ;
28
27
char GENERAL_TOPIC[] = " /main" ;
29
28
char MQTT_USER[] = " " ;
30
29
char MQTT_PASSWORD[] = " " ;
31
30
char LWT_TOPIC[] = " " ;
32
31
char LWT_MESSAGE[] = " " ;
32
+ #endif
33
33
34
+ #ifdef ARDUINO_ARCH_MRAA
35
+ #define Serial DebugSerial
34
36
#endif
35
37
36
38
ArduinoCloudThing::ArduinoCloudThing () {
@@ -84,7 +86,7 @@ bool ArduinoCloudThing::connect() {
84
86
return false ;
85
87
}
86
88
87
- void ArduinoCloudThing::publish (CborObject & object) {
89
+ void ArduinoCloudThing::publish (CborArray & object) {
88
90
89
91
bool retained = false ;
90
92
@@ -122,7 +124,7 @@ int ArduinoCloudThing::poll() {
122
124
diff = checkNewData ();
123
125
if (diff > 0 ) {
124
126
CborBuffer buffer (1024 );
125
- CborObject object = CborObject (buffer);
127
+ CborArray object = CborArray (buffer);
126
128
compress (object, buffer);
127
129
publish (object);
128
130
}
@@ -134,20 +136,17 @@ int ArduinoCloudThing::poll() {
134
136
return diff;
135
137
}
136
138
137
- void ArduinoCloudThing::compress (CborObject& object, CborBuffer& buffer) {
138
-
139
- CborArray array = CborArray (buffer);
139
+ void ArduinoCloudThing::compress (CborArray& object, CborBuffer& buffer) {
140
140
141
141
for (int i = 0 ; i < list.size (); i++) {
142
142
ArduinoCloudPropertyGeneric *p = list.get (i);
143
143
if (p->shouldBeUpdated ()) {
144
144
CborObject child = CborObject (buffer);
145
145
p->append (child);
146
146
CborVariant variant = CborVariant (buffer, child);
147
- array .add (variant);
147
+ object .add (variant);
148
148
}
149
149
}
150
- object.set (" a" , array);
151
150
}
152
151
153
152
int ArduinoCloudThing::checkNewData () {
@@ -205,6 +204,7 @@ void ArduinoCloudThing::callback(MQTTClient *client, char topic[], char bytes[],
205
204
void ArduinoCloudThing::decode (uint8_t * payload, size_t length) {
206
205
CborBuffer buffer (200 );
207
206
CborVariant total = buffer.decode (payload, length);
207
+
208
208
CborArray array = total.asArray ();
209
209
210
210
for (int i=0 ; ;i++) {
@@ -214,6 +214,7 @@ void ArduinoCloudThing::decode(uint8_t * payload, size_t length) {
214
214
break ;
215
215
}
216
216
217
+
217
218
CborObject object = variant.asObject ();
218
219
219
220
String name = " " ;
@@ -227,15 +228,13 @@ void ArduinoCloudThing::decode(uint8_t * payload, size_t length) {
227
228
break ;
228
229
}
229
230
if (idx == list.size ()) {
230
- Serial.println (" Property not found, skipping" );
231
231
currentListIndex = -1 ;
232
232
}
233
233
}
234
234
}
235
235
236
236
if (object.get (" t" ).isValid ()) {
237
237
int tag = object.get (" t" ).asInteger ();
238
-
239
238
if (name != " " ) {
240
239
list.get (currentListIndex)->setTag (tag);
241
240
} else {
@@ -281,79 +280,9 @@ void ArduinoCloudThing::decode(uint8_t * payload, size_t length) {
281
280
282
281
if (list.get (currentListIndex)->newData ()) {
283
282
// call onUpdate()
284
- list.get (currentListIndex)->callback ();
285
- }
286
- }
287
- }
288
-
289
- /*
290
-
291
- void CborPropertyListener::OnInteger(int32_t value) {
292
- if (currentListIndex < 0) {
293
- return;
294
- }
295
- reinterpret_cast<ArduinoCloudProperty<int>*>(list->get(currentListIndex))->write(value);
296
- }
297
-
298
- void CborPropertyListener::OnBytes(unsigned char *data, unsigned int size) {
299
- printf("bytes with size: %d", size);
300
- }
301
-
302
- void CborPropertyListener::OnString(String &str) {
303
- // if tag arrived, search a string with the same name in the list
304
- if (newElement == true) {
305
- newElement = false;
306
- for (int i = 0; i < list->size(); i++) {
307
- ArduinoCloudPropertyGeneric *p = list->get(i);
308
- if (p->getName() == str) {
309
- currentListIndex = i;
310
- break;
311
- }
312
- if (i == list->size()) {
313
- Serial.println("Property not found, skipping");
314
- currentListIndex = -1;
283
+ if (list.get (currentListIndex)->callback != NULL ) {
284
+ list.get (currentListIndex)->callback ();
315
285
}
316
286
}
317
- } else {
318
- if (currentListIndex < 0) {
319
- return;
320
- }
321
- reinterpret_cast<ArduinoCloudProperty<String>*>(list->get(currentListIndex))->write(str);
322
- }
323
- }
324
-
325
- void CborPropertyListener::OnArray(unsigned int size) {
326
-
327
- // prepare for new properties to arrive
328
- if (justStarted == true) {
329
- list_size = size;
330
- justStarted = false;
331
- }
332
- }
333
-
334
- void CborPropertyListener::OnMap(unsigned int size) {
335
- }
336
-
337
- void CborPropertyListener::OnTag(uint32_t tag) {
338
- newElement = true;
339
- list_size--;
340
- if (list_size < 0) {
341
- Serial.println("problem, we got more properties than advertised");
342
- }
343
- }
344
-
345
- void CborPropertyListener::OnSpecial(uint32_t code) {
346
-
347
- if (currentListIndex < 0) {
348
- return;
349
- }
350
- if (list->get(currentListIndex)->getPermission() != code) {
351
- Serial.println("permission changed, updating");
352
- list->get(currentListIndex)->setPermission((permissionType)code);
353
287
}
354
- }
355
-
356
- void CborPropertyListener::OnError(const char *error) {
357
- }
358
-
359
- */
288
+ }
0 commit comments