wifi/web_setup/main.c

/*
* EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
* CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
* IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
* PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
* (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
*/
/* 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..."
/*************************************************************************************************/
void gos_app_init(void)
{
gos_result_t result;
char buffer[96];
GOS_LOG(APPLICATION_START_LINE);
if (GOS_FAILED(result, gos_load_app_settings("settings.ini")))
{
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);
if (GOS_FAILED(result, gos_setup_start()))
{
GOS_LOG("Failed to start web setup, err:%d", result);
return;
}
GOS_LOG("Web Setup running ...");
GOS_LOG("Wi-Fi network: %s", GOS_GET_SETTING_STR("setup.web.ssid", buffer));
GOS_LOG("Password: %s", GOS_GET_SETTING_STR("setup.web.passkey", buffer));
GOS_LOG("HTTP URL(s): %s", GOS_GET_SETTING_STR("setup.web.url", buffer));
}
/*************************************************************************************************/
static void setup_client_event_handler(const gos_softap_client_t *client)
{
char buffer[32];
if (client->valid == true)
{
// 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");
}