Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for WiFi.connecting() returning false during DHCP configuration #1254

Merged
merged 2 commits into from Mar 21, 2017

Conversation

@sergeuz
Copy link
Member

commented Feb 19, 2017

This PR fixes #1241 by making WLAN_CONNECTING and WLAN_CONNECTED flags span over the entire network connection process, including DHCP configuration phase.

I'm not sure how I can write a good test for this fix, so below is my usual test application which I play with to debug network/cloud connectivity problems. Make sure you build the system firmware with debugging enabled and DEBUG_NETWORK_STATE macro defined to get internal state of the ManagedNetworkInterface class logged.

Tested on Photon and Electron with static and dynamic IP configurations.

#include "application.h"

SYSTEM_MODE(MANUAL)
// SYSTEM_THREAD(ENABLED)

#if PLATFORM_ID == 10
#define Network Cellular
#else
#define Network WiFi
#endif

namespace {

Serial1LogHandler logHandler(115200, LOG_LEVEL_WARN, {
    { "system.network.state", LOG_LEVEL_ALL },
    { "app", LOG_LEVEL_ALL }
});

void connectionStatusChanged(system_event_t event, int data) {
    switch (event) {
    case network_status: {
        switch (data) {
        case network_status_powering_off: Log.info("network_status_powering_off"); break;
        case network_status_off: Log.info("network_status_off"); break;
        case network_status_powering_on: Log.info("network_status_powering_on"); break;
        case network_status_on: Log.info("network_status_on"); break;
        case network_status_connecting: Log.info("network_status_connecting"); break;
        case network_status_connected: Log.info("network_status_connected"); break;
        case network_status_disconnecting: Log.info("network_status_disconnecting"); break;
        case network_status_disconnected: Log.info("network_status_disconnected"); break;
        }
        Log.info(PP_STR(Network) ".connecting() == %d", (int)Network.connecting());
        Log.info(PP_STR(Network) ".ready() == %d", (int)Network.ready());
        break;
    }
    case cloud_status: {
        switch (data) {
        case cloud_status_disconnected: Log.info("cloud_status_disconnected"); break;
        case cloud_status_connecting: Log.info("cloud_status_connecting"); break;
        case cloud_status_connected: Log.info("cloud_status_connected"); break;
        case cloud_status_disconnecting: Log.info("cloud_status_disconnecting"); break;
        }
        Log.info("Particle.connected() == %d", (int)Particle.connected());
        break;
    }
    default:
        break;
    }
}

uint32_t t = 0;
int step = 0;

} // namespace

STARTUP(System.on(network_status | cloud_status, connectionStatusChanged))

void setup() {
/*
    WiFi.on();

    // Use static IP configuration
    IPAddress addr(192,168,1,177);
    IPAddress mask(255,255,255,0);
    IPAddress gateway(192,168,1,1);
    IPAddress dns(192,168,1,1);
    WiFi.setStaticIP(addr, mask, gateway, dns);
    WiFi.useStaticIP();

    // Use dynamic IP configuration
    WiFi.useDynamicIP();
*/
}

void loop() {
    if (step && millis() - t < 6000) {
        // Particle.process();
        return;
    }
    switch (++step) {
    case 1: {
        Log.info("-> " PP_STR(Network) ".on()");
        Network.on();
        break;
    }
    case 2: {
        Log.info("-> " PP_STR(Network) ".connect()");
        Network.connect();
        break;
    }
    case 3: {
        Log.info("-> Particle.connect()");
        Particle.connect();
        break;
    }
    case 4: {
        Log.info("-> Particle.disconnect()");
        Particle.disconnect();
        break;
    }
    case 5: {
        Log.info("-> " PP_STR(Network) ".disconnect()");
        Network.disconnect();
        break;
    }
    case 6: {
        Log.info("-> " PP_STR(Network) ".off()");
        Network.off();
        break;
    }
    default:
        break;
    }
    t = millis();
}

Doneness:

  • Contributor has signed CLA
  • Problem and Solution clearly stated
  • Code peer reviewed
  • API tests compiled
  • Run unit/integration/application tests on device
  • Add documentation (N/A)
  • Add to CHANGELOG.md after merging (add links to docs and issues)

Bugfixes

sergeuz added 2 commits Feb 11, 2017
Make WLAN_CONNECTING and WLAN_CONNECTED flags span over whole connect…
…ion process (network connection and DHCP); helper macros for connection state debugging

@sergeuz sergeuz added this to the 0.7.0 milestone Feb 19, 2017

@sergeuz sergeuz changed the title Fix for `WiFi.connecting()` returning `false` during DHCP configuration Fix for WiFi.connecting() returning false during DHCP configuration Feb 19, 2017

@technobly technobly added the bug label Mar 21, 2017

@technobly technobly merged commit 9d7c715 into develop Mar 21, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@technobly technobly deleted the fix/dhcp_connecting branch Mar 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.