Skip to content

Instantly share code, notes, and snippets.

@andyjjones1
Created August 16, 2018 23:58
Show Gist options
  • Save andyjjones1/11ffc788a5dbaa180523c23688b60492 to your computer and use it in GitHub Desktop.
Save andyjjones1/11ffc788a5dbaa180523c23688b60492 to your computer and use it in GitHub Desktop.
#include "common/cs_dbg.h"
#include "wifi_setup.h"
#include "mgos_system.h"
#include "mgos_timers.h"
#include "mgos_wifi.h"
#include "mgos_wifi_hal.h"
bool g_wifi_setup_ap_setup_ret = false;
bool g_wifi_setup_sta_setup_ret = false;
/* Disable STA */
static bool wifi_setup_sta_disable(void)
{
/* Local variables */
struct mgos_config_wifi_sta sta_setup;
bool result = false;
/* Disable mgos STA */
memcpy(&sta_setup, mgos_sys_config_get_wifi_sta(), sizeof(sta_setup));
sta_setup.enable = false;
/* Check success/failure of disable */
g_wifi_setup_sta_setup_ret = mgos_wifi_dev_sta_setup(&sta_setup);
if(g_wifi_setup_sta_setup_ret == true)
{
LOG(LL_ERROR, ("Andrew: STA disable success."));//debug
result = true;
} else
{
LOG(LL_ERROR, ("Andrew: STA disable fail."));//debug
result = false;
}
/* Return SOFTAP disable result */
return result;
}
/* Call back to complete AP set up (needed only by this module) */
static void wifi_setup_softap_setup(void)
{
/* Local variables */
struct mgos_config_wifi_ap ap_setup;
char *ssid = (char *)mgos_sys_config_get_wifi_setup_ssid();
char *pass = (char *)mgos_sys_config_get_wifi_setup_pass();
/* Disable Wifi STA */
wifi_setup_sta_disable();
/* SOFTAP set up */
memcpy(&ap_setup, mgos_sys_config_get_wifi_ap(), sizeof(ap_setup));
ap_setup.enable = true;
ap_setup.ssid = ssid;
ap_setup.pass = pass;
ap_setup.hidden = false;
ap_setup.channel = 6;
ap_setup.max_connections = 1;
ap_setup.ip = "192.168.4.1";
ap_setup.netmask = "255.255.255.0";
ap_setup.gw = "192.168.4.1";
ap_setup.dhcp_start = "192.168.4.2";
ap_setup.dhcp_end = "192.168.4.100";
ap_setup.trigger_on_gpio = -1;
ap_setup.keep_enabled=false;
/* Set global success/err flag */
g_wifi_setup_ap_setup_ret = mgos_wifi_dev_ap_setup(&ap_setup);
if(g_wifi_setup_ap_setup_ret == true)
{
LOG(LL_ERROR, ("Andrew: SOFTAP setup success."));//debug
g_wifi_setup_result = WIFI_SETUP_SUCCESS;
} else
{
LOG(LL_ERROR, ("Andrew: SOFTAP setup fail."));//debug
g_wifi_setup_result = WIFI_SETUP_ERR_SETUP;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment