Skip to content

Commit 7314929

Browse files
committed
send network data to cloud
1 parent 2cd7da7 commit 7314929

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/ArduinoIoTCloudDevice.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _state{State::Init},
2828
_attachAttempt(0, 0),
2929
_propertyContainer(),
3030
_propertyContainerIndex(0),
31+
_getNetConfigCallback(nullptr),
3132
_attached(false),
3233
_registered(false) {
3334
}
@@ -109,6 +110,13 @@ ArduinoCloudDevice::State ArduinoCloudDevice::handleSendCapabilities() {
109110
DeviceBeginCmd deviceBegin = { DeviceBeginCmdId, AIOT_CONFIG_LIB_VERSION };
110111
deliver(reinterpret_cast<Message*>(&deviceBegin));
111112

113+
/* Send Network Configuration */
114+
if(_getNetConfigCallback){
115+
DeviceNetConfigCmdUp deviceNetConfig = { DeviceNetConfigCmdUpId };
116+
_getNetConfigCallback(deviceNetConfig.params );
117+
deliver(reinterpret_cast<Message*>(&deviceNetConfig));
118+
}
119+
112120
/* Subscribe to device topic to request */
113121
ThingBeginCmd thingBegin = { ThingBeginCmdId };
114122
deliver(reinterpret_cast<Message*>(&thingBegin));

src/ArduinoIoTCloudDevice.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <Arduino_TimedAttempt.h>
1919
#include "interfaces/CloudProcess.h"
2020
#include "property/PropertyContainer.h"
21+
#include <Arduino_ConnectionHandler.h>
22+
#include <connectionHandlerModels/settings.h>
2123

2224
/******************************************************************************
2325
* CLASS DECLARATION
@@ -26,6 +28,8 @@
2628
class ArduinoCloudDevice : public CloudProcess {
2729
public:
2830

31+
typedef std::function<void(models::NetworkSetting&)> GetNetworkSettingCbk;
32+
2933
ArduinoCloudDevice(MessageStream* stream);
3034
virtual void update() override;
3135
virtual void handleMessage(Message* m) override;
@@ -43,6 +47,10 @@ class ArduinoCloudDevice : public CloudProcess {
4347
return _attached;
4448
};
4549

50+
void setGetNetworkSettingCbk(GetNetworkSettingCbk cbk) {
51+
_getNetConfigCallback = cbk;
52+
}
53+
4654

4755
private:
4856

@@ -57,6 +65,7 @@ class ArduinoCloudDevice : public CloudProcess {
5765
CommandId _command;
5866
TimedAttempt _attachAttempt;
5967
PropertyContainer _propertyContainer;
68+
GetNetworkSettingCbk _getNetConfigCallback;
6069
unsigned int _propertyContainerIndex;
6170
bool _attached;
6271
bool _registered;

src/ArduinoIoTCloudNotecard.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ int ArduinoIoTCloudNotecard::begin(ConnectionHandler &connection_, int interrupt
105105
// Configure the Device and Thing property containers
106106
_thing.begin();
107107
_device.begin();
108+
_device.setGetNetworkSettingCbk([connection = this->_connection](models::NetworkSetting &setting) {
109+
connection->getSetting(setting);
110+
});
108111

109112
return 1; // (true -> success)
110113
}

src/ArduinoIoTCloudTCP.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
168168
_thing.begin();
169169
_device.begin();
170170

171+
_device.setGetNetworkSettingCbk([connection = this->_connection](models::NetworkSetting &setting) {
172+
connection->getSetting(setting);
173+
});
174+
171175
#if OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)
172176
_ota.setClient(&_otaClient);
173177
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)

0 commit comments

Comments
 (0)