How can I get Wifi/Internet status from captive-portal-wifi-stack

Hi ,

Now am used captive-portal-wifi-stack for connect wifi. now I would like to know how can I get network or internet connection status from this lib.

I saw some code in demo-c example. They have MGOS_HAVE_WIFI but I don’t know where of this are declare to used. but only the function is running in background for Log network status.


Try not to broadcast everywhere.

What function, what background ? You either call a C function from C/C++ code or you need to FFI from mJS. There is no point in calling an RPC from a web page to get WiFi status since your device needs to be connected to have WiFi to be able to answer… do you need other status ? Specifically ?
There is no notion of “Internet” connection, whoever tells you that “is connected to the Internet” is pinging some host or polling some service that he assumes must be accesible and knows how to access that. AFAIK mOS does not do that; but if you connect to a cloud you can check its status.

From the WiFi API docs:


enum mgos_wifi_status mgos_wifi_get_status(void);
Get wifi status, see enum mgos_wifi_status.

and they belong in the header

enum mgos_wifi_status {

Or you may subscribe to an event

Everything is documented, RTM.

#ifdef MGOS_HAVE_WIFI only checks wether the wifi library is included in the build.

I didn’t test, but if you add the captive-portal-wifi-stack library in your mos.yml, I’d expect MGOS_HAVE_CAPTIVE_PORTAL_WIFI_STACK to be defined.

What are you trying to do?

I’m just doubt. MGOS_HAVE_WIFI where is come from now I know. @scaprile has tell me on the Chat group.

I just want to handle network event. But not sure it will work with wifistock lib or not. I don’t know why it need to define MGOS_HAVE_WIFI

So know it just remove that define.