0

I don't understand where the access point's IP comes from. Sketch uses WiFi.beginAP( ssid ) ..to start the AP. Then, printWifiStatus() gets the access point's IP with:

IPAddress ip = WiFi.localIP();

How does .beginAP() create the IP? What does it use for a mask?

I'm creating network service on a MKR1000, and want to use .beginAP() to make it an access point, so I don't need a "middle man" (router). Going to have mobile device (iPhone) connect directly to Arduino MKR1000.

1 Answer 1

2

If you look into that github source code, you can see startAP function and mainly rows with strM2MAPConfig.au8DHCPServerIP:

uint8_t WiFiClass::startAP(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo, uint8_t channel)
{
    tstrM2MAPConfig strM2MAPConfig;

    if (!_init) {
        init();
    }

    if (channel == 0) {
        channel = 1; // channel 1 is the minium channel
    }

    // Enter Access Point mode:
    memset(&strM2MAPConfig, 0x00, sizeof(tstrM2MAPConfig));
    strcpy((char *)&strM2MAPConfig.au8SSID, ssid);
    strM2MAPConfig.u8ListenChannel = channel - 1;
    strM2MAPConfig.u8SecType = u8SecType;
    strM2MAPConfig.au8DHCPServerIP[0] = 0xC0; /* 192 */
    strM2MAPConfig.au8DHCPServerIP[1] = 0xA8; /* 168 */
    strM2MAPConfig.au8DHCPServerIP[2] = 0x01; /* 1 */
    strM2MAPConfig.au8DHCPServerIP[3] = 0x01; /* 1 */

    if (u8SecType == M2M_WIFI_SEC_WEP) {
        tstrM2mWifiWepParams* wep_params = (tstrM2mWifiWepParams*)pvAuthInfo;

        strM2MAPConfig.u8KeyIndx = wep_params->u8KeyIndx;
        strM2MAPConfig.u8KeySz = wep_params->u8KeySz;
        strcpy((char*)strM2MAPConfig.au8WepKey, (char *)wep_params->au8WepKey);
    }

    if (m2m_wifi_enable_ap(&strM2MAPConfig) < 0) {
        _status = WL_CONNECT_FAILED;
        return _status;
    }
    _status = WL_AP_LISTENING;
    _mode = WL_AP_MODE;

    memset(_ssid, 0, M2M_MAX_SSID_LEN);
    memcpy(_ssid, ssid, strlen(ssid));
    m2m_memcpy((uint8 *)&_localip, (uint8 *)&strM2MAPConfig.au8DHCPServerIP[0], 4);
    _submask = 0x00FFFFFF;
    _gateway = _localip;

    // WiFi led ON (rev A then rev B).
    m2m_periph_gpio_set_val(M2M_PERIPH_GPIO15, 0);
    m2m_periph_gpio_set_val(M2M_PERIPH_GPIO4, 0);

    return _status;
}
1
  • Ah, hah! 192.168.1.1 Look at the code: I feel sheepish. I'm still getting used to EVERYTHING being available with open source, I guess. Thanks!
    – Doug Null
    Commented Sep 6, 2016 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.