Skip to content

Commit 2dd49c0

Browse files
committed
Lora working
1 parent 0cab7a7 commit 2dd49c0

8 files changed

+58
-48
lines changed

src/ArduinoIoTCloud.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,17 @@ class ArduinoIoTCloudClass {
177177
ArduinoIoTSynchronizationStatus _syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED;
178178

179179

180-
String _device_id, _thing_id;
180+
String _device_id = "";
181+
String _thing_id = "";
181182

182183

183184
ArduinoCloudThing Thing;
184185

185-
int _lastSyncRequestTickTime;
186+
int _lastSyncRequestTickTime = 0;
186187

187-
OnCloudEventCallback _on_sync_event_callback,
188-
_on_connect_event_callback,
189-
_on_disconnect_event_callback;
188+
OnCloudEventCallback _on_sync_event_callback = NULL;
189+
OnCloudEventCallback _on_connect_event_callback = NULL;
190+
OnCloudEventCallback _on_disconnect_event_callback = NULL;
190191

191192
static void execCloudEventCallback(OnCloudEventCallback & callback, void * callback_arg) {
192193
if (callback) {
@@ -204,13 +205,15 @@ class ArduinoIoTCloudClass {
204205
}
205206
}
206207
};
207-
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || \
208-
defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT)
209-
#include "ArduinoIoTCloudTCP.h"
210-
extern ArduinoIoTCloudTCP ArduinoCloud;
211-
#elif defined(ARDUINO_SAMD_MKR1300) || defined(ARDUINO_SAMD_MKR1310)
212-
//#include "ArduinoIoTCloudLPWAN.h"
213-
//extern ArduinoIoTCloudLPWAN ArduinoCloud;
208+
209+
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT)
210+
//#error HAS_TCP
211+
#include "ArduinoIoTCloudTCP.h"
212+
extern ArduinoIoTCloudTCP ArduinoCloud;
213+
#elif defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
214+
//#error HAS_LORA
215+
#include "ArduinoIoTCloudLPWAN.h"
216+
//extern ArduinoIoTCloudLPWAN ArduinoCloud;
214217
#endif
215218

216219
#endif

src/ArduinoIoTCloudLPWAN.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
a commercial license, send an email to [email protected].
1616
*/
1717

18+
#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
19+
1820
#include<ArduinoIoTCloudLPWAN.h>
1921

2022
ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN() :
2123
_connection(NULL)
2224
{
23-
_thing_id = "";
25+
/*_thing_id = "";
2426
_lastSyncRequestTickTime = 0;
2527
_on_sync_event_callback(NULL);
2628
_on_connect_event_callback(NULL);
2729
_on_disconnect_event_callback(NULL);
28-
_device_id = "";
30+
_device_id = "";*/
2931
}
3032

3133
ArduinoIoTCloudLPWAN::~ArduinoIoTCloudLPWAN() {
@@ -34,7 +36,8 @@ ArduinoIoTCloudLPWAN::~ArduinoIoTCloudLPWAN() {
3436
int ArduinoIoTCloudLPWAN::connect()
3537
{
3638
_connection->connect();
37-
return _connection->getStatus();
39+
int state = _connection->getStatus() == NetworkConnectionState::INIT ? 1 : 0;
40+
return state;
3841
}
3942

4043
bool ArduinoIoTCloudLPWAN::disconnect()
@@ -45,7 +48,8 @@ bool ArduinoIoTCloudLPWAN::disconnect()
4548

4649
int ArduinoIoTCloudLPWAN::connected()
4750
{
48-
return _connection->getStatus();
51+
int state = _connection->getStatus() == NetworkConnectionState::INIT ? 1 : 0;
52+
return state;
4953
}
5054

5155
int ArduinoIoTCloudLPWAN::begin(LPWANConnectionHandler& connection)
@@ -73,8 +77,6 @@ void ArduinoIoTCloudLPWAN::update(CallbackFunc onSyncCompleteCallback) {
7377
msgBuf[i++] = _connection->read();
7478
}
7579

76-
CloudSerial.appendStdin(msgBuf, sizeof(msgBuf));
77-
7880
Thing.decode(msgBuf, sizeof(msgBuf));
7981
}
8082

@@ -132,33 +134,22 @@ void ArduinoIoTCloudLPWAN::connectionCheck() {
132134
case ArduinoIoTConnectionStatus::RECONNECTING: {
133135
int const ret_code = connect();
134136
Debug.print(DBG_INFO, "ArduinoCloud.reconnect()");
135-
if (ret_code == NetworkConnectionState::INIT) {
137+
if (ret_code == 1) {
136138
_iotStatus = ArduinoIoTConnectionStatus::IDLE;
137139
}
138140
else {
139141
_iotStatus = ArduinoIoTConnectionStatus::ERROR;
140142
}
141143

142-
/*int const ret_code_reconnect = reconnect(*_net);
143-
Debug.print(DBG_INFO, "ArduinoCloud.reconnect(): %d", ret_code_reconnect);
144-
if (ret_code_reconnect == CONNECT_SUCCESS) {
145-
_iotStatus = ArduinoIoTConnectionStatus::CONNECTED;
146-
printConnectionStatus(_iotStatus);
147-
execCloudEventCallback(_on_connect_event_callback, 0 callback_arg );
148-
CloudSerial.begin(9600);
149-
CloudSerial.println("Hello from Cloud Serial!");
150-
}*/
151144
}
152145
break;
153146
case ArduinoIoTConnectionStatus::CONNECTING: {
154-
int const net_status = _connection->getStatus();
147+
NetworkConnectionState net_status = _connection->getStatus();
155148
Debug.print(DBG_VERBOSE, "ArduinoCloud.connect(): %d", net_status);
156149
if (net_status == NetworkConnectionState::CONNECTED) {
157150
_iotStatus = ArduinoIoTConnectionStatus::CONNECTED;
158151
printConnectionStatus(_iotStatus);
159152
execCloudEventCallback(_on_connect_event_callback, 0 /* callback_arg */);
160-
CloudSerial.begin(9600);
161-
CloudSerial.println("Hello from Cloud Serial!");
162153
}
163154

164155
}
@@ -197,4 +188,7 @@ void ArduinoIoTCloudLPWAN::sendPropertiesToCloud() {
197188
writeProperties(data, length);
198189
}
199190
}
191+
//#error MULTIPLE_DEFINITION
200192
ArduinoIoTCloudLPWAN ArduinoCloud;
193+
194+
#endif

src/ArduinoIoTCloudLPWAN.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef ARDUINO_IOT_CLOUD_LPWAN_H
1919
#define ARDUINO_IOT_CLOUD_LPWAN_H
2020

21+
//#ifdef defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
22+
2123
#include <ArduinoIoTCloud.h>
2224
#include <Arduino_ConnectionHandler.h>
2325

@@ -46,16 +48,18 @@ class ArduinoIoTCloudLPWAN : public ArduinoIoTCloudClass {
4648

4749

4850
protected:
49-
friend class CloudSerialClass;
5051
int writeStdout(const byte data[], int length);
5152
int writeProperties(const byte data[], int length);
5253
int writeShadowOut(const byte data[], int length);
5354

5455
private:
5556
LPWANConnectionHandler* _connection;
57+
void sendPropertiesToCloud();
5658

5759
};
5860

5961
extern ArduinoIoTCloudLPWAN ArduinoCloud;
6062

63+
//#endif
64+
6165
#endif

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
software without disclosing the source code of your own applications. To purchase
1515
a commercial license, send an email to [email protected].
1616
*/
17+
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT)
18+
1719
#include <ArduinoIoTCloudTCP.h>
1820
#ifdef BOARD_HAS_ECCX08
1921
#include "utility/ECCX08Cert.h"
@@ -71,12 +73,12 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP():
7173
_dataTopicIn(""),
7274
_otaTopic("")
7375
{
74-
_thing_id="";
76+
/*_thing_id="";
7577
_lastSyncRequestTickTime=0;
7678
_on_sync_event_callback(NULL);
7779
_on_connect_event_callback(NULL);
7880
_on_disconnect_event_callback(NULL);
79-
_device_id="";
81+
_device_id="";*/
8082
}
8183

8284

@@ -443,4 +445,8 @@ void ArduinoIoTCloudTCP::printDebugInfo() {
443445
Debug.print(DBG_INFO, "Thing ID: %s", getThingId().c_str());
444446
Debug.print(DBG_INFO, "MQTT Broker: %s:%d", _brokerAddress.c_str(), _brokerPort);
445447
}
446-
ArduinoIoTCloudTCP ArduinoCloud;
448+
449+
//#error DEFINING_ARDUINOCLOUD2
450+
ArduinoIoTCloudTCP ArduinoCloud;
451+
452+
#endif

src/ArduinoIoTCloudTCP.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#ifndef ARDUINO_IOT_CLOUD_TCP_H
1919
#define ARDUINO_IOT_CLOUD_TCP_H
2020

21+
//#ifdef defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT)
22+
23+
2124
#include <ArduinoIoTCloud.h>
2225
#include <Arduino_ConnectionHandler.h>
2326

@@ -140,4 +143,6 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
140143

141144
extern ArduinoIoTCloudTCP ArduinoCloud;
142145

146+
//#endif
147+
143148
#endif

src/ArduinoIoTCloud_Defines.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
defined(ARDUINO_SAMD_MKRNB1500)
2424
#define BOARD_HAS_ECCX08
2525
#define HAS_TCP
26+
//#error HAS_TCP_SET
2627
#endif
2728

28-
29-
30-
#if defined(ARDUINO_SAMD_MKR1300) || defined(ARDUINO_SAMD_MKR1310)
31-
// TODO set BOARD_HAS_LORA
29+
#if defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
30+
#define HAS_LORA
3231
#endif
3332

3433
#if defined(ARDUINO_ESP8266_ESP12) || defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)

src/CloudSerial.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
software without disclosing the source code of your own applications. To purchase
1515
a commercial license, send an email to [email protected].
1616
*/
17+
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ESP8266_ESP12) || defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
1718

1819
#include "ArduinoIoTCloud.h"
1920
#include "CloudSerial.h"
@@ -86,3 +87,5 @@ void CloudSerialClass::appendStdin(const uint8_t *buffer, size_t size) {
8687
}
8788

8889
CloudSerialClass CloudSerial;
90+
91+
#endif

src/CloudSerial.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
#define CLOUD_SERIAL_TX_BUFFER_SIZE 64
2929
#define CLOUD_SERIAL_RX_BUFFER_SIZE 512
3030

31-
#ifdef HAS_TCP
31+
3232
class ArduinoIoTCloudTCP;
33-
#else
34-
class ArduinoIoTCloudLPWAN;
35-
#endif
33+
3634

3735
class CloudSerialClass : public Stream {
3836
public:
@@ -52,11 +50,9 @@ class CloudSerialClass : public Stream {
5250
operator bool();
5351

5452
protected:
55-
#ifdef HAS_TCP
56-
friend class ArduinoIoTCloudTCP;
57-
#else
58-
friend class ArduinoIoTCloudLPWAN;
59-
#endif
53+
54+
friend class ArduinoIoTCloudTCP;
55+
6056

6157

6258
void appendStdin(const uint8_t *buffer, size_t size);

0 commit comments

Comments
 (0)