@@ -161,6 +161,42 @@ NotecardConnectionHandler::NotecardConnectionHandler(
161
161
PUBLIC MEMBER FUNCTIONS
162
162
******************************************************************************/
163
163
164
+ int NotecardConnectionHandler::setWiFiCredentials (const String & ssid_, const String & password_)
165
+ {
166
+ int result;
167
+
168
+ // Validate the connection state is not in an initialization state
169
+ if (check () == NetworkConnectionState::INIT)
170
+ {
171
+ Debug.print (DBG_ERROR, F (" Failed to set WiFi credentials. Connection has not been initialized." ));
172
+ result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC;
173
+ } else if (J *req = _notecard.newRequest (" card.wifi" )) {
174
+ JAddStringToObject (req, " ssid" , ssid_.c_str ());
175
+ JAddStringToObject (req, " password" , password_.c_str ());
176
+ if (J *rsp = _notecard.requestAndResponse (req)) {
177
+ // Check the response for errors
178
+ if (NoteResponseError (rsp)) {
179
+ const char *err = JGetString (rsp, " err" );
180
+ Debug.print (DBG_ERROR, F (" %s" ), err);
181
+ Debug.print (DBG_ERROR, F (" Failed to set WiFi credentials." ));
182
+ result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC;
183
+ } else {
184
+ Debug.print (DBG_INFO, F (" WiFi credentials updated. ssid: \" %s\" password: \" %s\" ." ), ssid_.c_str (), password_.length () ? " **********" : " " );
185
+ result = NotecardCommunicationError::NOTECARD_ERROR_NONE;
186
+ }
187
+ JDelete (rsp);
188
+ } else {
189
+ Debug.print (DBG_ERROR, F (" Failed to receive response from Notecard." ));
190
+ result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC;
191
+ }
192
+ } else {
193
+ Debug.print (DBG_ERROR, F (" Failed to allocate request: wifi.set" ));
194
+ result = NotecardCommunicationError::HOST_ERROR_OUT_OF_MEMORY;
195
+ }
196
+
197
+ return result;
198
+ }
199
+
164
200
const String & NotecardConnectionHandler::syncArduinoDeviceId (const String & device_id_)
165
201
{
166
202
// Validate the connection state is not in an initialization state
@@ -193,6 +229,7 @@ const String & NotecardConnectionHandler::syncArduinoDeviceId (const String & de
193
229
if (NoteResponseError (rsp)) {
194
230
const char *err = JGetString (rsp, " err" );
195
231
Debug.print (DBG_ERROR, F (" %s" ), err);
232
+ Debug.print (DBG_ERROR, F (" Failed to update cache." ));
196
233
} else {
197
234
Debug.print (DBG_VERBOSE, F (" Cache updated successfully." ));
198
235
}
@@ -234,6 +271,7 @@ int NotecardConnectionHandler::syncSecretDeviceKey (const String & secret_device
234
271
if (NoteResponseError (rsp)) {
235
272
const char *err = JGetString (rsp, " err" );
236
273
Debug.print (DBG_ERROR, F (" %s" ), err);
274
+ Debug.print (DBG_ERROR, F (" Failed to sync Secret Device Key." ));
237
275
result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC;
238
276
} else {
239
277
Debug.print (DBG_VERBOSE, F (" Secret key updated successfully." ));
0 commit comments