Need to convert ASCII Dec serial data stored as a string to ASCII characters stored as a string and push to network connection SSID & network password

If you are referring to this

Then I must disappoint you. the function name is only there as a string literal to make it clear with what parameters the function would be called if you had it there instead of the Serial.printlnf() statement.
However, if you had a function called like this

  Serial.printlnf("The fn returned %s", someFunctionReturningACString());

that would work.

Only when the respective network is available and visible to the device - then the Argon can "request" that information from the network directly. If the network is unreachable or invisible at the time of execution you need to provide that data (both encryption scheme and WLAN cipher) too.

after clearing credentials, if I go look at what is stored on the device I have seen network both locked and unlocked, but never empty unless I choose to delete it in the Particle app:

I have tried every combination of connection. Without enc, with enc, with enc & cypher, to no avail.
from another postings reference to this:

  • I disconnect from the network
  • cleared credentials
  • set credentials (all possible variations).
  • attempted to connect back to network; fails.

This is what I get in the log handler:

Credentials found (homenetwork). Clearing credentials, please wait...)
0000036500 [net.ifapi] INFO: Netif wl3 state DOWN
0000036501 [system.nm] INFO: State changed: IP_CONFIGURED -> IFACE_REQUEST_DOWN
0000036502 [system.nm] INFO: State changed: IFACE_REQUEST_DOWN -> IFACE_DOWN
0000036513 [net.ifapi] INFO: Netif wl3 link DOWN
0000036538 [comm] INFO: Forcing a cloud ping
0000036539 [system] ERROR: sock_send returned -1 118
0000036539 [comm.dtls] ERROR: mbedtls_ssl_write() failed: -0x4e
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 18. WEP
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 19. WPA
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 20. WPA, WLAN_CIPHER_AES_TKIP
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 21. WPA, WLAN_CIPHER_AES
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 22. WPA, WLAN_CIPHER_TKIP
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 23. WPA2
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 24. WPA2, WLAN_CIPHER_AES_TKIP
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 25. WPA2, WLAN_CIPHER_AES
Connecting to homenetwork, with 15FE63C8B44A6192, please wait...)
Device failed to connected to homenetwork using config 26. WPA2, WLAN_CIPHER_TKIP

It appears as though it goes into a listening mode as soon as I clear credentials (which, at least the network name, does not get cleared). Is there a working example of this disconnect,clear, set and reconnect?

Can you provide your entire code to see what might be causing your issues?
If you are using Web IDE you can just post a SHARE THIS REVISION link.

int found;
int i;
int postpone;
byte mac[6];
// EXAMPLE
String SSID = "homenetwork";
String SSIDPwd = "123456789ABCDEF";

void setup() {
    printWiFiCredentials();
    
    WiFiAccessPoint ap[5];
    found = WiFi.getCredentials(ap, 5);
    if(found > 0){
        Serial.printlnf("Credentials found (%s). Clearing credentials, please wait...)", ap[i].ssid);
        delay(5000);
        // delay buffer
        for(postpone = 20; postpone > 0; postpone--){
            Serial.printlnf("Postponing rewrite in %d seconds...", postpone);
            delay(1000);
        }
        WiFi.disconnect();
        WiFi.clearCredentials();
    }
    if(0){
        delay(10000);
        WiFi.setCredentials(SSID.c_str(), SSIDPwd.c_str(), WLAN_SEC_WPA, WLAN_CIPHER_AES_TKIP);
        WiFi.connect();
        bool tryingToConnect = WiFi.connecting();
        if(tryingToConnect==true){
            Serial.printlnf("Connecting to %s, with %s, please wait...)", SSID.c_str(), SSIDPwd.c_str());
        }
        bool deviceConnectedAndReady;
        for (int xxx=0; xxx < 10; xxx++){
            deviceConnectedAndReady = WiFi.ready();
            if(deviceConnectedAndReady==true){
                Serial.printlnf("Connected to %s.", SSID.c_str());
                break;
            }else{
                if(xxx==9){
                    Serial.printlnf("Device failed to connected to %s.", SSID.c_str());
                    break;
                }
            }
            delay(1000);
        }
    }
    
}

Hmm, I guess it's not

This code will also not set new credentials, since if(0) never executes its conditional block.

Also the Argon can store up to 10 sets of credentials for that reason I'd extend the array used of WiFi.getCredentials() to 10 elements.
Alternatively - since you don't seem to be interested in the retrieved data anyhow - use WiFi.hasCredentials() to determine whether there are any.

This would be one way that works for me on my mobile hotspot

SYSTEM_MODE(SEMI_AUTOMATIC)

SerialLogHandler logger( LOG_LEVEL_WARN, {{ "app", LOG_LEVEL_ALL }});

char ssid[32] = "homenetwork";
char pwd[32] = "homenetwork_pwd";

void setup() {
  WiFi.on();
  if (WiFi.hasCredentials()) {
    Log.info("Clearing credentials");    
    WiFi.clearCredentials();  
    // some stuff to be extra save
    delay(1000);
    WiFi.off();
    delay(1000);
    WiFi.on();
  }
  
  Log.info("setting new credentials %s / %s", ssid, pwd);
  WiFi.setCredentials(ssid, pwd);
  delay(1000);
  Log.info("connecting");
  WiFi.connect();   
  
  if(waitFor(WiFi.ready, 30000)) {
    Log.info("WiFi connected");
  }
  else {
    Log.warn("WiFi %s not found", ssid);
  }
}
1 Like

I had marked that loop false(0) only to bypass this part of the temporarily or I would not have gotten the
"Connecting to homenetwork, with 15FE63C8B44A6192, please wait…)
Device failed to connected to homenetwork using config 18. WEP..." mentioned above.

I did not include this additional code as it was unnecessary for diagnostics and when I add unnecessary code it seem to distract people from focusing on the actual problem at hand. I should have broke this down to the essentials to isolate my issue, sorry about that:

void loop() {
}

void printWiFiCredentials(){
    WiFiAccessPoint ap[5];
    found = WiFi.getCredentials(ap, 5);
    
    for (i = 0; i < found; i++) {
        Serial.printf("ssid: %s \n", ap[i].ssid);
        // security is one of WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA, WLAN_SEC_WPA2, WLAN_SEC_WPA_ENTERPRISE, WLAN_SEC_WPA2_ENTERPRISE
        Serial.printf("security: %d \n", (int) ap[i].security);
        // cipher is one of WLAN_CIPHER_AES, WLAN_CIPHER_TKIP or WLAN_CIPHER_AES_TKIP
        Serial.printf("cipher: %d \n", (int) ap[i].cipher);
        
        Serial.printlnf("ip address: %s", WiFi.localIP().toString().c_str());
        
        Serial.printlnf("gateway: %s", WiFi.gatewayIP().toString().c_str());
        
        WiFi.macAddress(mac);
        Serial.printlnf("mac: %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    }   
}

I have tried your code and I get:
0000033471 [app] WARN: WiFi skynet not found

...mind you. this is the same network that this device was connected to, just a moment earlier. When I go into the particle app under settings=>WiFi=>manage WiFi for this device, it shows that the skynet is there, but it has a lock on it:
particle1
I clear it and reset WiFi parameters. Since your code has no delay (buffer zone) in clearing credentials (my fault, I should have added it), even after I use the Particle App to reset to WiFi credentials, upon reboot (device reboot), this code immediately wipes the credentials I just set, and now I am unable to flash anything to it.
First and most important issue as the device is unusable at present:

  • How do I tell the web IDE or console to clear the code upon reboot (reboot after setting WiFi credentials with Particle App)?

  • The code above does not work on this device. I can look at my router and see what enc and cyph it is using. I tried connecting using those additional parameters, and it still does not connect. I then tried every possible combination, no go.

You can either use Safe Mode to bypass the application firmware or you can reflash the device via CLI (particle flash --usb tinker) or via this tool: Device Restore USB | Tools | Particle

When your network is present and visible you won't need to provide the encryption or cipher.

BTW, which device OS version are you using - I tested with 2.3.0 and 3.3.0

Device OS: 2.3.0

Device OS: 2.3.0

This worked great, thanks.

... as for the network connection, I tried to connect to a different router and network, get the same results:
0000063317 [app] WARN: WiFi europa not found
I have no idea where to go from here.

I can’t quite see what’s going on on your side.
I’ll try to cobble together an application where you could send your desired credentials via USB Serial. This way I can test multiple networks on my side.

When this works for me I wouldn’t see what could be the reason for it to not work on your side.

I also do not know why. Assuming the device my have had an error, I have ran that same code on another Argon device and I encounter the same issue: WiFi not found. I have tried this with two devices (both Argon) and two different networks, which have to different routers, on each device and get the same error:

Serial monitor opened successfully:
0000030386 [app] INFO: Clearing credentials
0000032416 [app] INFO: setting new credentials skynet / 123456789ABCD
0000033473 [app] INFO: connecting
0000063484 [app] WARN: WiFi skynet not found

...and this is when I have to reset the WiFi through the Particle app. While using the Particle app, it states "Particle device is looking for networks"... and I see the blue light on the Argon blink for a moment, and then the same network that it couldn't find, is in the list of available networks.
Tried 2.4 Ghz, 5 Ghz on routers, no difference. Dead on the water.

Is there a command that lists the available networks? I know I can get them using the particle app. I wanted to get a list without using the app. TIA

WiFi.scan()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.