wifi/web_setup/main.c
/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/* Documentation for this app is available online.
* See https://docs.silabs.com/gecko-os/4/standard/latest/sdk/examples/wifi/web-setup
*/
#include "gos.h"
#define APPLICATION_START_LINE "\r\nWeb Setup example starting..."
/*************************************************************************************************/
{
GOS_LOG(APPLICATION_START_LINE);
// First let's check if we have joined a wlan network, or currently in the process of.
// If so - lets not start setup web. Note this is required as when `setup_stop` is called
// Gecko OS silently reboots the device, and then attempts to join the most recently
// provisioned network.
switch(join_result)
{
{
GOS_LOG("Joined wlan network");
return;
}
{
GOS_LOG("Joining network");
gos_network_register_event_handler(GOS_INTERFACE_WLAN, (gos_network_handler_t)wlan_network_event_handler);
return;
}
default:
break; // Fall through and start web setup
}
start_setup();
}
/*************************************************************************************************/
static void start_setup(void)
{
gos_result_t result;
char buffer[96];
{
GOS_LOG("Failed to load app settings, err:%d", result);
}
gos_setup_register_client_event_handler(setup_client_event_handler);
gos_setup_register_finished_event_handler(setup_finished_event_handler);
{
GOS_LOG("Failed to start web setup, err:%d", result);
return;
}
GOS_LOG("Web Setup running ...");
}
/*************************************************************************************************/
{
char buffer[32];
{
// If the OS is 'invalid' then that means the client has connected to the SoftAP but NOT
// the HTTP server yet
{
GOS_LOG("Client connected: %s - %s", mac_to_str(&client->mac, NULL), ipv4_to_str(client->ipv4_address, buffer));
}
else
{
GOS_LOG("Client connected to server: %s - %s", ipv4_to_str(client->ipv4_address, buffer), gos_setup_get_client_os_str(client));
}
}
else
{
GOS_LOG("Client disconnected: %s - %s", mac_to_str(&client->mac, NULL), ipv4_to_str(client->ipv4_address, buffer));
}
}
/*************************************************************************************************/
static void setup_finished_event_handler(void *unused)
{
GOS_LOG("Web Setup finished");
}
/*************************************************************************************************/
static void wlan_network_event_handler(bool is_up)
{
if(is_up)
{
// The device successfully joined the wlan network
}
else
{
// Failed to join - lets start the setup web server for device configuration
GOS_LOG("Failed to join wlan network");
start_setup();
}
}