@@ -49,8 +49,7 @@ ArduinoIoTCloudLPWAN::ArduinoIoTCloudLPWAN()
49
49
50
50
int ArduinoIoTCloudLPWAN::connect () {
51
51
_connection->connect ();
52
- const int state = _connection->getStatus () == NetworkConnectionState::INIT ? 1 : 0 ;
53
- return state;
52
+ return 1 ;
54
53
}
55
54
56
55
bool ArduinoIoTCloudLPWAN::disconnect () {
@@ -74,8 +73,24 @@ void ArduinoIoTCloudLPWAN::update() {
74
73
// Check if a primitive property wrapper is locally changed
75
74
_thing.updateTimestampOnLocallyChangedProperties ();
76
75
77
- if (checkPhyConnection () != NetworkConnectionState::CONNECTED) return ;
78
- if (checkCloudConnection () != ArduinoIoTConnectionStatus::CONNECTED) return ;
76
+ ArduinoIoTConnectionStatus next_iot_status = _iotStatus;
77
+
78
+ /* Since we do not have a direct connection to the Arduino IoT Cloud servers
79
+ * there is no such thing is a 'cloud connection state' since the LoRa
80
+ * board connection state to the gateway is all the information we have.
81
+ */
82
+ NetworkConnectionState const net_con_state = checkPhyConnection ();
83
+ if (net_con_state == NetworkConnectionState::CONNECTED) { next_iot_status = ArduinoIoTConnectionStatus::CONNECTED; execCloudEventCallback (ArduinoIoTCloudEvent::CONNECT); }
84
+ else if (net_con_state == NetworkConnectionState::CONNECTING) { next_iot_status = ArduinoIoTConnectionStatus::CONNECTING; }
85
+ else if (net_con_state == NetworkConnectionState::DISCONNECTED) { next_iot_status = ArduinoIoTConnectionStatus::DISCONNECTED; execCloudEventCallback (ArduinoIoTCloudEvent::DISCONNECT); }
86
+
87
+ if (next_iot_status != _iotStatus)
88
+ {
89
+ printConnectionStatus (next_iot_status);
90
+ _iotStatus = next_iot_status;
91
+ }
92
+
93
+ if (net_con_state != NetworkConnectionState::CONNECTED) return ;
79
94
80
95
if (_connection->available ()) {
81
96
uint8_t msgBuf[CBOR_LORA_MSG_MAX_SIZE];
@@ -120,54 +135,6 @@ int ArduinoIoTCloudLPWAN::writeProperties(const byte data[], int length) {
120
135
return 1 ;
121
136
}
122
137
123
- ArduinoIoTConnectionStatus ArduinoIoTCloudLPWAN::checkCloudConnection ()
124
- {
125
- ArduinoIoTConnectionStatus next_iot_status = _iotStatus;
126
-
127
- switch (_iotStatus)
128
- {
129
- case ArduinoIoTConnectionStatus::IDLE: next_iot_status = ArduinoIoTConnectionStatus::CONNECTING; break ;
130
- case ArduinoIoTConnectionStatus::ERROR: next_iot_status = ArduinoIoTConnectionStatus::RECONNECTING; break ;
131
- case ArduinoIoTConnectionStatus::DISCONNECTED: next_iot_status = ArduinoIoTConnectionStatus::RECONNECTING; break ;
132
- case ArduinoIoTConnectionStatus::CONNECTING:
133
- {
134
- Debug.print (DBG_INFO, " Arduino IoT Cloud connecting ..." );
135
- if (connected ())
136
- {
137
- next_iot_status = ArduinoIoTConnectionStatus::CONNECTED;
138
- }
139
- }
140
- break ;
141
-
142
- case ArduinoIoTConnectionStatus::RECONNECTING:
143
- {
144
- Debug.print (DBG_INFO, " Arduino IoT Cloud reconnecting ..." );
145
- if (connect ()) next_iot_status = ArduinoIoTConnectionStatus::IDLE;
146
- else next_iot_status = ArduinoIoTConnectionStatus::ERROR;
147
- }
148
- break ;
149
-
150
- case ArduinoIoTConnectionStatus::CONNECTED:
151
- {
152
- if (_connection->getStatus () != NetworkConnectionState::CONNECTED)
153
- {
154
- next_iot_status = ArduinoIoTConnectionStatus::DISCONNECTED;
155
- }
156
- }
157
- break ;
158
- }
159
-
160
- if (next_iot_status != _iotStatus)
161
- {
162
- printConnectionStatus (next_iot_status);
163
- if (next_iot_status == ArduinoIoTConnectionStatus::DISCONNECTED) execCloudEventCallback (ArduinoIoTCloudEvent::DISCONNECT);
164
- else if (next_iot_status == ArduinoIoTConnectionStatus::CONNECTED) execCloudEventCallback (ArduinoIoTCloudEvent::CONNECT);
165
- _iotStatus = next_iot_status;
166
- }
167
-
168
- return _iotStatus;
169
- }
170
-
171
138
/* *****************************************************************************
172
139
* EXTERN DEFINITION
173
140
******************************************************************************/
0 commit comments