Working WiFi operator.
This commit is contained in:
parent
6b3d7503bd
commit
db81c8ef1b
|
|
@ -0,0 +1 @@
|
||||||
|
Config.h
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef _PICOW_WIFI_OPERATOR_CONFIG_H
|
||||||
|
#define _PICOW_WIFI_OPERATOR_CONFIG_H
|
||||||
|
|
||||||
|
#define WIFI_OPERATOR_AUTH CYW43_AUTH_WPA2_AES_PSK
|
||||||
|
#define WIFI_OPERATOR_CHANNEL 3
|
||||||
|
#define WIFI_OPERATOR_POWERSAVE_MODE CYW43_NO_POWERSAVE_MODE
|
||||||
|
|
||||||
|
#define WIFI_OPERATOR_SSID "myssid2000+"
|
||||||
|
#define WIFI_OPERATOR_PASSWORD "*aw3s0meP4ssUwUord*"
|
||||||
|
|
||||||
|
#endif // _PICOW_WIFI_OPERATOR_CONFIG_H
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
#include "PicoW_WiFi_Operator.h"
|
||||||
|
|
||||||
|
#include <pico/cyw43_arch.h>
|
||||||
|
|
||||||
|
static enum wifi_operator_mode_t wifi_operator_mode = WIFI_OPERATOR_MODE_UNINITIALIZED;
|
||||||
|
|
||||||
|
int wifi_operator_init(enum wifi_operator_mode_t mode)
|
||||||
|
{
|
||||||
|
wifi_operator_mode = mode;
|
||||||
|
|
||||||
|
if(cyw43_wifi_pm(&cyw43_state, WIFI_OPERATOR_POWERSAVE_MODE))
|
||||||
|
{
|
||||||
|
puts("Failed to apply WiFi operator powersave mode.");
|
||||||
|
return PICO_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wifi_operator_mode == WIFI_OPERATOR_MODE_ACCESS_POINT)
|
||||||
|
{
|
||||||
|
// Setup as access point
|
||||||
|
cyw43_arch_enable_ap_mode(WIFI_OPERATOR_SSID, WIFI_OPERATOR_PASSWORD, WIFI_OPERATOR_AUTH);
|
||||||
|
cyw43_wifi_ap_set_channel(&cyw43_state, WIFI_OPERATOR_CHANNEL);
|
||||||
|
|
||||||
|
return PICO_OK;
|
||||||
|
}
|
||||||
|
else if(wifi_operator_mode == WIFI_OPERATOR_MODE_STATION)
|
||||||
|
{
|
||||||
|
// Setup as station
|
||||||
|
cyw43_arch_enable_sta_mode();
|
||||||
|
|
||||||
|
int ret = cyw43_arch_wifi_connect_blocking(WIFI_OPERATOR_SSID, WIFI_OPERATOR_PASSWORD, WIFI_OPERATOR_AUTH);
|
||||||
|
|
||||||
|
switch(ret)
|
||||||
|
{
|
||||||
|
case PICO_ERROR_BADAUTH:
|
||||||
|
puts("Failed to autentificate to WiFi network.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PICO_ERROR_CONNECT_FAILED:
|
||||||
|
puts("Failed to connect to WiFi network.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
wifi_operator_mode = WIFI_OPERATOR_MODE_UNINITIALIZED;
|
||||||
|
|
||||||
|
puts("WiFi operator mode not valid.");
|
||||||
|
|
||||||
|
return PICO_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wifi_operator_exit(void)
|
||||||
|
{
|
||||||
|
if(cyw43_wifi_pm(&cyw43_state, CYW43_DEFAULT_PM))
|
||||||
|
{
|
||||||
|
puts("Failed to reset WiFi operator powersave mode.");
|
||||||
|
return PICO_ERROR_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wifi_operator_mode == WIFI_OPERATOR_MODE_ACCESS_POINT)
|
||||||
|
{
|
||||||
|
// Exit as access point
|
||||||
|
cyw43_arch_disable_ap_mode();
|
||||||
|
|
||||||
|
return PICO_OK;
|
||||||
|
}
|
||||||
|
else if(wifi_operator_mode == WIFI_OPERATOR_MODE_STATION)
|
||||||
|
{
|
||||||
|
// Exit as station
|
||||||
|
cyw43_arch_disable_sta_mode();
|
||||||
|
|
||||||
|
return PICO_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("WiFi operator was not initialized correctly.");
|
||||||
|
|
||||||
|
return PICO_ERROR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef _PICOW_WIFI_OPERATOR_H
|
||||||
|
#define _PICOW_WIFI_OPERATOR_H
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief WiFi operator mode.
|
||||||
|
* Set in initialisation
|
||||||
|
*/
|
||||||
|
enum wifi_operator_mode_t {
|
||||||
|
WIFI_OPERATOR_MODE_UNINITIALIZED,
|
||||||
|
WIFI_OPERATOR_MODE_ACCESS_POINT,
|
||||||
|
WIFI_OPERATOR_MODE_STATION
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Init the WiFi operator with the given mode.
|
||||||
|
*
|
||||||
|
* @param mode Mode to initialise the wifi operator to.
|
||||||
|
*/
|
||||||
|
int wifi_operator_init(enum wifi_operator_mode_t mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Exit the WiFi operator and reset to default parameters.
|
||||||
|
*/
|
||||||
|
int wifi_operator_exit(void);
|
||||||
|
|
||||||
|
#endif // _PICOW_WIFI_OPERATOR_H
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H
|
#ifndef _LWIPOPTS_H
|
||||||
#define _LWIPOPTS_EXAMPLE_COMMONH_H
|
#define _LWIPOPTS_H
|
||||||
|
|
||||||
// Common settings used in most of the pico_w examples
|
// Common settings used in most of the pico_w examples
|
||||||
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
|
// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue