Argon Cloud session reconnect

I am developing with OS 1.3.0-rc.1 and have the argon in SEMI_AUTOMATIC mode. To test the BLE UART communications I’ve setup some functions to be called when certain commands are received. The problem I am currently having is within the Particle.connect() or originates from here.

The order of events that works then fails are:

  1. Flash with CLI tinker
  2. Send wifi credentials over serial. Unit connects to the cloud.
  3. Flash my code on from the workbench.
  4. Send command to Particle.connect() with wifi credentials. Unit connects to the cloud
  5. Push the reset button on the Argon. Then send the connect command again. Unit connects to the cloud.
  6. Unplug the argon from the power supply (usb).
  7. Plug back in Argon and send the same connect command. This time the unit gets stuck. The last message I see print out on my serial is:
0000015402 [app] WARN: Network on
0000016410 [app] WARN: Setup started
0000017418 [app] WARN: Setup ended after 99 ms
0000017605 [net.ifapi] INFO: Netif wl3 link UP
0000017605 [system.nm] INFO: State changed: IFACE_UP -> IFACE_LINK_UP
0000017756 [hal] INFO: DNS server list changed
0000017757 [hal] INFO: DNS server list changed
0000017759 [system.nm] INFO: State changed: IFACE_LINK_UP -> IP_CONFIGURED
0000017818 [system.nm] INFO: Checking gateway status with the device cloud
0000017820 [system] INFO: Cloud: connecting
0000017823 [system] INFO: Read Server Address = type:1,domain:$id.udp-mesh.particle.io
0000017824 [system] ERROR: Failed to load session data from persistent storage
0000017825 [system] INFO: Discarding session data
0000018161 [system] INFO: Cloud socket=0, connecting to 3.81.24.94#5684
0000018162 [system] INFO: Cloud socket connected
0000018163 [system] INFO: Starting handshake: presense_announce=0
0000018164 [comm.protocol.handshake] INFO: Establish secure connection
0000018428 [app] WARN: Network connecting
Local Time - 946663218
0000018462 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2

When it connects successfully the restoreStatus=0

I’m not sure what the tinker app does each time it connects to either reset the session or…?

Here is my code that is called from the ble command:

        Particle.publish("spark/device/session/end", "", PRIVATE);
        Particle.disconnect();
        delay(100);
        //Connect to the network and then to the Particle cloud
        WiFi.on();
        WiFi.setCredentials("wifiNetowrkname", "BigPassword");
        delay(100);
        WiFi.connect(WIFI_CONNECT_SKIP_LISTEN);
        delay(100);
        WiFi.listen(false);
        Serial.println(" ---------- **** no listen");
        delay(100);
        if(WiFi.ready()){
            Particle.process();
            Serial.println(" ---------- **** wifi.ready()");
        }
        Particle.connect();
        Serial.println(" ---------- **** Particle connect()");
        delay(1000);
        if(Particle.connected()){
            bleSerial.println("connected");
            Particle.process();
        }

Are you using SYSTEM_THREAD(ENABLED); ?

You do not need Particle.process(); calls if so.

Also, I am not clear from the snippet where you are actually calling the WiFi setup etc. from. If from a callback handler it might be that there is insufficient memory available. It might be better to set a flag in the BLE handler that is then serviced by the loop when this flag is set.

It might help if you posted all your code.

1 Like

Yes, but we are running in semi-automatic mode to allow the code to run if there is not a wifi network available. So I added it to this function to test if it helped with the connection process.

This block of code is called from a received Bluetooth command received over wireless UART connection. I'm not sure what you are referring to in regards to wifi setup? I setup this command to check the functionality of connecting to the wifi network on demand. In the reference material it seems as easy as calling Particle.connect() in order to establish the connection, but I seem to have an issue if I power down the Argon.

Our code is doing a lot of other things with Canbus communications, so posting it all wouldn't be helpful, it pretty big.

Memory for what? I'm thinking that something is either not getting stored or retrieved correctly but I'm not sure exactly what.

The WIFI connection process uses memory- if you are already using a lot for your application and BLE then there may point where the level is too low.

Ok, I’ll keep that in mind. Thanks