Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Read wifi sta IP address

pjapja Cambridge

Hi,

I am attempting to read the wifi sta IP address as follows in a timer callback function.

...

int wifiStatus = mgos_wifi_get_status();

if( wifiStatus == MGOS_WIFI_IP_ACQUIRED ) {
    fprintf(stdout, "PJA: 1 mgos_sys_config.wifi.ap.enable  = %d\n", mgos_sys_config.wifi.ap.enable);
    fprintf(stdout, "PJA: 2 mgos_sys_config.wifi.ap.ip      = %p\n", mgos_sys_config.wifi.ap.ip);
    fprintf(stdout, "PJA: 3 mgos_sys_config.wifi.sta.ip     = %s\n", mgos_sys_config.wifi.ap.ip);

    fprintf(stdout, "PJA: 4 mgos_sys_config.wifi.sta.enable = %d\n", mgos_sys_config.wifi.sta.enable);
    fprintf(stdout, "PJA: 5 mgos_sys_config.wifi.sta.ip     = %p\n", mgos_sys_config.wifi.sta.ip);
}

[Apr 5 09:10:28.215] I (4240) event: sta ip: 192.168.0.51, mask: 255.255.255.0, gw: 192.168.0.1
[Apr 5 09:10:28.225] mgos_net_on_change_c WiFi STA: ready, IP 192.168.0.51, GW 192.168.0.1, DNS 194.168.4.100
[Apr 5 09:10:28.258] PJA: 1 mgos_sys_config.wifi.ap.enable = 0
[Apr 5 09:10:28.262] PJA: 2 mgos_sys_config.wifi.ap.ip = 0x3ffc141c
[Apr 5 09:10:28.266] PJA: 3 mgos_sys_config.wifi.sta.ip = 192.168.4.1
[Apr 5 09:10:28.270] PJA: 4 mgos_sys_config.wifi.sta.enable = 1
[Apr 5 09:10:28.274] PJA: 5 mgos_sys_config.wifi.sta.ip = 0x0

pja@e6410:/media/scratch/git_repos/mgos_wifi_dev_template$ mos --version
The Mongoose OS command line tool
Version: 2.0
Build ID: 2.0+4ed5853~xenial0
Update channel: release

I expected to get the IP address string that the device (ESP32) has been served as detailed in the above console output but
I see a null pointer in mgos_sys_config.wifi.sta.ip. I've probably incorrectly assumed that the DHCP (from my router) served
IP address will be loaded into mgos_sys_config.wifi.sta.ip. Therefore where should I read the local DHCP server wifi sta IP address from ?

Thanks

Paul

Comments

Sign In or Register to comment.