Skip to content

Commit ebaa1ab

Browse files
committed
Library is now ArduinoCloudThing
1 parent e388049 commit ebaa1ab

File tree

29 files changed

+4
-3840
lines changed

29 files changed

+4
-3840
lines changed

ArduinoCloudNew.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

ArduinoCloudThing.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ static void utox8(uint32_t val, char* s) {
2121
}
2222
#endif
2323

24-
#ifdef USE_ARDUINO_CLOUD
25-
char MQTT_SERVER[] = "10.130.22.94";
26-
int MQTT_PORT = 1883;
27-
char GENERAL_TOPIC[] = "/main";
28-
char MQTT_USER[] = "";
29-
char MQTT_PASSWORD[] = "";
30-
char LWT_TOPIC[] = "";
31-
char LWT_MESSAGE[] = "";
32-
#endif
33-
3424
#ifdef ARDUINO_ARCH_MRAA
3525
#define Serial DebugSerial
3626
#endif
@@ -50,74 +40,34 @@ ArduinoCloudThing::ArduinoCloudThing() {
5040
#endif
5141
}
5242

53-
/*
54-
* begin() should prepare the environment
55-
* connect
56-
*/
57-
58-
void ArduinoCloudThing::begin(Client &client) {
59-
this->client = new MQTTClient();
60-
this->client->onMessageAdvanced(ArduinoCloudThing::callback);
61-
this->client->begin(MQTT_SERVER, MQTT_PORT, client);
62-
this->client->setParent((void*)this);
63-
64-
// using WiFi client and ECC508 connect to server
65-
while (!connect()) {
66-
Serial.println("Not connected");
67-
delay(500);
68-
}
69-
}
7043

71-
bool ArduinoCloudThing::connect() {
44+
bool ArduinoCloudThing::begin() {
7245

7346
#ifdef TESTING_PROTOCOL
7447
return true;
7548
#endif
7649

77-
if (client->connect(uuid, MQTT_USER, MQTT_PASSWORD) != 0) {
78-
// set status to ON
79-
status = ON;
80-
addProperty(status, READ);
81-
// subscribe to "general" topic
82-
client->subscribe(GENERAL_TOPIC);
83-
return true;
84-
}
85-
86-
return false;
50+
status = ON;
51+
addProperty(status, READ);
8752
}
8853

8954
void ArduinoCloudThing::publish(CborArray& object) {
9055

91-
bool retained = false;
92-
9356
uint8_t data[1024];
9457
size_t size = object.encode(data, sizeof(data));
9558

9659
#ifdef TESTING_PROTOCOL
9760
decode(data, size);
9861
#endif
9962

100-
#ifndef TESTING_PROTOCOL
101-
client->publish(GENERAL_TOPIC, (const char*)data, size);
102-
#endif
103-
10463
for (int i = 0; i < list.size(); i++) {
10564
ArduinoCloudPropertyGeneric *p = list.get(i);
10665
p->updateShadow();
10766
}
10867
}
10968

110-
// Reconnect to the mqtt broker
11169
int ArduinoCloudThing::poll() {
11270

113-
#ifndef TESTING_PROTOCOL
114-
if (!client->connected()){
115-
if (!connect()){
116-
return 0;
117-
}
118-
}
119-
#endif
120-
12171
// check if backing storage and cloud has diverged
12272
int diff = 0;
12373

@@ -197,10 +147,6 @@ ArduinoCloudPropertyGeneric& ArduinoCloudThing::addPropertyReal(float& property,
197147
return *(reinterpret_cast<ArduinoCloudPropertyGeneric*>(thing));
198148
}
199149

200-
void ArduinoCloudThing::callback(MQTTClient *client, char topic[], char bytes[], int length) {
201-
reinterpret_cast<ArduinoCloudThing*>(client->getParent())->decode((uint8_t *)bytes, length);
202-
}
203-
204150
void ArduinoCloudThing::decode(uint8_t * payload, size_t length) {
205151
CborBuffer buffer(200);
206152
CborVariant total = buffer.decode(payload, length);

ArduinoCloudThing.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@
33

44
#include <Client.h>
55
#include <Stream.h>
6-
#include "lib/MQTT/src/MQTTClient.h"
76
#include "lib/LinkedList/LinkedList.h"
87
#include "lib/ArduinoCbor/src/ArduinoCbor.h"
98

10-
#ifndef MQTT_BUFFER_SIZE
11-
#define MQTT_BUFFER_SIZE 256
12-
#endif
13-
149
//#define TESTING_PROTOCOL
1510
#define DEBUG_MEMORY
1611
#define USE_ARDUINO_CLOUD
1712

18-
//#define MQTTCLIENT_QOS1 0
19-
//#define MQTTCLIENT_QOS2 0
20-
2113
enum permissionType {
2214
READ = 0b01,
2315
WRITE = 0b10,
@@ -186,7 +178,7 @@ inline void ArduinoCloudProperty<char*>::appendValue(CborObject &cbor) {
186178
class ArduinoCloudThing {
187179
public:
188180
ArduinoCloudThing();
189-
void begin(Client &client);
181+
void begin();
190182
ArduinoCloudPropertyGeneric& addPropertyReal(int& property, String name, permissionType permission);
191183
ArduinoCloudPropertyGeneric& addPropertyReal(bool& property, String name, permissionType permission);
192184
ArduinoCloudPropertyGeneric& addPropertyReal(float& property, String name, permissionType permission);
@@ -196,8 +188,6 @@ class ArduinoCloudThing {
196188
int poll();
197189

198190
private:
199-
static void callback(MQTTClient *client, char topic[], char bytes[], int length);
200-
bool connect();
201191
void publish(CborArray& object);
202192

203193
void update();
@@ -212,8 +202,6 @@ class ArduinoCloudThing {
212202

213203
LinkedList<ArduinoCloudPropertyGeneric*> list;
214204
int currentListIndex = -1;
215-
216-
MQTTClient* client;
217205
};
218206

219207
#endif

lib/MQTT/CMakeLists.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/MQTT/DEVELOPING.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/MQTT/LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/MQTT/Makefile

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)