@@ -201,6 +201,8 @@ int CLAppConn::loadPrefs() {
201201        json_obj_get_bool (&jctx, (char *)" dhcp" 
202202    }
203203
204+     char  dbuf[192 ];
205+ 
204206    if  (ret == OS_SUCCESS && json_obj_get_array (&jctx, (char *)" stations" 
205207        Serial.print (" Known external SSIDs: " 
206208        if (stationCount>0 )
@@ -209,8 +211,9 @@ int CLAppConn::loadPrefs() {
209211                if (json_arr_get_object (&jctx, i) == OS_SUCCESS) {
210212                    Station *s = (Station*) malloc (sizeof (Station));
211213                    if (json_obj_get_string (&jctx, (char *)" ssid" ssid , sizeof (s->ssid )) == OS_SUCCESS &&
212-                        json_obj_get_string (&jctx, (char *)" pass" s-> password , sizeof (s-> password )) == OS_SUCCESS) {
214+                        json_obj_get_string (&jctx, (char *)" pass" dbuf , sizeof (dbuf )) == OS_SUCCESS) {
213215                        Serial.printf (" %s\r\n " ssid );
216+                         urlDecode (s->password , dbuf, sizeof (dbuf));
214217                        stationList[i] = s;
215218                    } 
216219                    else  {
@@ -236,7 +239,8 @@ int CLAppConn::loadPrefs() {
236239    }
237240
238241    json_obj_get_string (&jctx, (char *)" ap_ssid" sizeof (apName));
239-     json_obj_get_string (&jctx, (char *)" ap_pass" sizeof (apPass));
242+     json_obj_get_string (&jctx, (char *)" ap_pass" sizeof (dbuf));
243+     urlDecode (apPass, dbuf, sizeof (dbuf));
240244    if (json_obj_get_int (&jctx, (char *)" ap_channel" 
241245        ap_channel = 1 ;
242246    if (json_obj_get_bool (&jctx, (char *)" ap_dhcp" 
@@ -251,7 +255,8 @@ int CLAppConn::loadPrefs() {
251255
252256    //  OTA
253257    json_obj_get_bool (&jctx, (char *)" ota_enabled" 
254-     json_obj_get_string (&jctx, (char *)" ota_password" sizeof (otaPassword)); 
258+     json_obj_get_string (&jctx, (char *)" ota_password" sizeof (dbuf)); 
259+     urlDecode (otaPassword, dbuf, sizeof (dbuf));
255260
256261    //  NTP
257262    json_obj_get_string (&jctx, (char *)" ntp_server" sizeof (ntpServer)); 
@@ -305,23 +310,29 @@ int CLAppConn::savePrefs() {
305310    if (index < 0  && count == MAX_KNOWN_STATIONS) {
306311        count--;
307312    }
308-     
313+     char  ebuf[192 ]; 
314+ 
309315    if (index < 0  || count > 0 ) {
310316        json_gen_push_array (&jstr, " stations" 
311317        if (index < 0 ) {
312318            json_gen_start_object (&jstr);
313319            json_gen_obj_set_string (&jstr, " ssid" 
314-             json_gen_obj_set_string (&jstr, " pass" 
320+             urlEncode (ebuf, password, sizeof (password));
321+             json_gen_obj_set_string (&jstr, " pass" 
315322            json_gen_end_object (&jstr);
316323        }
317324
318325        for (int  i=0 ; i < count; i++) {
319326            json_gen_start_object (&jstr);
320327            json_gen_obj_set_string (&jstr, " ssid" ssid );
321-             if (index >= 0  && i == index)
322-                 json_gen_obj_set_string (&jstr, " pass" 
323-             else 
324-                 json_gen_obj_set_string (&jstr, " pass" password );
328+             if (index >= 0  && i == index) {
329+                 urlEncode (ebuf, password, sizeof (password));
330+                 json_gen_obj_set_string (&jstr, " pass" 
331+             }
332+             else  {
333+                 urlEncode (ebuf, stationList[i]->password , sizeof (stationList[i]->password ));
334+                 json_gen_obj_set_string (&jstr, " pass" 
335+             }
325336            json_gen_end_object (&jstr);
326337        }
327338        json_gen_pop_array (&jstr);
@@ -337,10 +348,13 @@ int CLAppConn::savePrefs() {
337348    json_gen_pop_object (&jstr);    
338349    json_gen_obj_set_int (&jstr, " http_port" 
339350    json_gen_obj_set_bool (&jstr, " ota_enabled" 
340-     json_gen_obj_set_string (&jstr, " ota_password" 
351+     urlEncode (ebuf, otaPassword, sizeof (otaPassword));
352+     Serial.println (ebuf);
353+     json_gen_obj_set_string (&jstr, " ota_password" 
341354
342355    json_gen_obj_set_string (&jstr, " ap_ssid" 
343-     json_gen_obj_set_string (&jstr, " ap_pass" 
356+     urlEncode (ebuf, apPass, sizeof (apPass));
357+     json_gen_obj_set_string (&jstr, " ap_pass" 
344358    json_gen_obj_set_bool (&jstr, " ap_dhcp" 
345359    json_gen_push_object (&jstr, " ap_ip" 
346360    if (apIP.ip ) json_gen_obj_set_string (&jstr, " ip" ip ->toString ().c_str ());
@@ -483,5 +497,4 @@ int CLAppConn::getSSIDIndex() {
483497    return  -1 ;
484498}
485499
486- 
487500CLAppConn AppConn;
0 commit comments