Skip to content

Commit d142460

Browse files
committed
feat: Wi-Fi Credentials not supported
1 parent 79532b1 commit d142460

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Arduino_NotecardConnectionHandler.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,42 @@ NotecardConnectionHandler::NotecardConnectionHandler(
161161
PUBLIC MEMBER FUNCTIONS
162162
******************************************************************************/
163163

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 to 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+
164200
const String & NotecardConnectionHandler::syncArduinoDeviceId (const String & device_id_)
165201
{
166202
// Validate the connection state is not in an initialization state
@@ -193,6 +229,7 @@ const String & NotecardConnectionHandler::syncArduinoDeviceId (const String & de
193229
if (NoteResponseError(rsp)) {
194230
const char *err = JGetString(rsp, "err");
195231
Debug.print(DBG_ERROR, F("%s"), err);
232+
Debug.print(DBG_ERROR, F("Failed to update cache."));
196233
} else {
197234
Debug.print(DBG_VERBOSE, F("Cache updated successfully."));
198235
}
@@ -234,6 +271,7 @@ int NotecardConnectionHandler::syncSecretDeviceKey (const String & secret_device
234271
if (NoteResponseError(rsp)) {
235272
const char *err = JGetString(rsp, "err");
236273
Debug.print(DBG_ERROR, F("%s"), err);
274+
Debug.print(DBG_ERROR, F("Failed to sync Secret Device Key."));
237275
result = NotecardCommunicationError::NOTECARD_ERROR_GENERIC;
238276
} else {
239277
Debug.print(DBG_VERBOSE, F("Secret key updated successfully."));

src/Arduino_NotecardConnectionHandler.h

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class NotecardConnectionHandler final : public ConnectionHandler
9898
_topic_type = topic;
9999
}
100100

101+
int setWiFiCredentials (const String & ssid, const String & pass);
101102
const String & syncArduinoDeviceId (const String & device_id);
102103
int syncSecretDeviceKey (const String & secret_device_key);
103104

0 commit comments

Comments
 (0)