Hello friends, successful connection to Wi-Fi.
It happened surprisingly.
When preparing a minimal code to test and share here, I found a method that I created in the first attempt to use Wi-Fi by interrupting the cellular network by setting it to EXTERNAL_SIM ( . oops) It was still being called inadvertently.
type or paste code here
Interestingly, the Wi-Fi negotiation apparently only ends fully with the SIM accessed. Does that make sense?
Below is the code & log
#include "ble_wifi_setup_manager.h"
#include "dct.h"
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
bool settingWifi = false;
int W_PIN;
typedef enum
{
STATE_IDLE = 0,
STATE_PROVISIONED
} ProvisionStates_t;
ProvisionStates_t provision_state, next_provision_state;
void provisionCb()
{
provision_state = STATE_PROVISIONED;
}
void setSIM(SimType qual)
{
Cellular.setActiveSim(qual);
const uint8_t val = 0x01;
dct_write_app_data(&val, DCT_SETUP_DONE_OFFSET, 1);
}
void setup()
{
delay(5000);
Log.info("setup");
W_PIN = D3; // WDT PIN
// SWITCHES
pinMode(W_PIN, OUTPUT);
//DIP Switches pins
pinMode(D6, INPUT_PULLDOWN);
pinMode(D7, INPUT_PULLDOWN);
pinMode(D5, INPUT_PULLDOWN);
pinMode(D4, INPUT_PULLDOWN);
pinMode(D23, INPUT_PULLDOWN);
//all switches on > config wifi password
if (digitalRead(D6) && digitalRead(D7) && digitalRead(D5) && digitalRead(D4) && digitalRead(D23))
{
bool clearedWifi = WiFi.clearCredentials();
WiFi.prefer(false);
settingWifi = true;
if (clearedWifi)
{
Log.info("ok clear wifi Credentials");
}
Log.info("config wifi");
provision_state = STATE_IDLE;
next_provision_state = STATE_IDLE;
BLEWiFiSetupManager::instance().setup();
BLEWiFiSetupManager::instance().setProvisionCallback(provisionCb);
// misuse found from first attempt to disable cell!!!
//setSIM(EXTERNAL_SIM);
}
}
void loop()
{
if (settingWifi)
{
BLEWiFiSetupManager::instance().loop();
// State machine to handle WiFi provisioning states
switch (provision_state)
{
case STATE_IDLE:
{
next_provision_state = STATE_IDLE;
break;
}
case STATE_PROVISIONED:
{
if (WiFi.ready() || WiFi.connecting())
{
WiFi.disconnect();
}
// WiFi.prefer();
// STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
Particle.connect();
next_provision_state = STATE_IDLE;
settingWifi = false;
break;
}
}
if (provision_state != next_provision_state)
{
Log.info("Provision State Transition: %u -> %u", provision_state, next_provision_state);
provision_state = next_provision_state;
}
// iWdt(); hardwarw watchdog
}
}
0000031526 [app.BLEWiFiSetupManager] INFO: WiFi credentials set
0000031542 [app] INFO: Provision State Transition: 1 -> 0
0000031555 [system.nm] INFO: State changed: IFACE_DOWN -> IFACE_REQUEST_UP
0000031600 [net.ifapi] INFO: Netif wl4 state UP
0000031622 [system.nm] INFO: State changed: IFACE_REQUEST_UP -> IFACE_UP
0000031628 [ncp.rltk.client] INFO: Try to connect to ssid: Cello 2-2.4G
0000031635 [net.ifapi] INFO: Netif pp3 state UP
0000036318 [net.ifapi] INFO: Netif wl4 link UP, profile=Cello 2-2.4G
0000036328 [system.nm] INFO: State changed: IFACE_UP -> IFACE_LINK_UP
0000036461 [hal] INFO: DNS server list changed
0000036467 [system.nm] INFO: State changed: IFACE_LINK_UP -> IP_CONFIGURED
0000036573 [system] INFO: Cloud: connecting
0000036596 [system] INFO: Read Server Address = type:1,domain:$id.udp.particle.io
0000036632 [system] WARN: Failed to load session data from persistent storage
0000036668 [system] INFO: Discarding session data
0000037104 [system] INFO: Cloud socket=0, connecting to 52.45.184.198#5684 using if 5
0000037140 [system] INFO: Bound cloud socket to lwip if 5 ("wl4")
0000037171 [system] INFO: Cloud socket connected
0000037193 [system] INFO: Starting handshake: presense_announce=0
0000037223 [comm.protocol.handshake] INFO: Establish secure connection
0000037256 [comm.dtls] INFO: (CMPL,RENEG,NO_SESS,ERR) restoreStatus=2
0000040171 [comm.protocol.handshake] INFO: Sending HELLO message
0000040354 [comm.protocol.handshake] INFO: Handshake completed
0000040384 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000040412 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000042845 [mux] INFO: Starting GSM07.10 muxer
0000042847 [mux] INFO: Opening mux channel 0
0000042847 [mux] INFO: GSM07.10 muxer thread started
0000042950 [mux] INFO: Opening mux channel 1
0000043046 [comm] INFO: Sending TIME request
0000043068 [system] INFO: Send spark/device/last_reset event
0000043105 [system] INFO: Sending application DESCRIBE
0000043134 [system] INFO: Sending subscriptions
0000043157 [comm.protocol] INFO: Sending subscriptions
0000043191 [comm.protocol] INFO: Received DESCRIBE request; flags: 0x04
0000043270 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000044286 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000044315 [comm.protocol] INFO: Received TIME response: 1731505751
0000044352 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000044383 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000044415 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 4
0000044443 [comm.dtls] INFO: session cmd (CLS,DIS,MOV,LOD,SAV): 3
0000044474 [system] INFO: All handshake messages have been processed
0000044509 [system] INFO: Cloud connected
0000044530 [comm] INFO: Forcing a cloud ping