mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Nina: Implement AP mode.
This commit is contained in:
parent
eb2f982779
commit
9dafa2447b
@ -39,6 +39,12 @@ typedef enum {
|
|||||||
NINA_ERROR_TIMEOUT = -2,
|
NINA_ERROR_TIMEOUT = -2,
|
||||||
} nina_error_t;
|
} nina_error_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NINA_WIFI_MODE_STA = 0,
|
||||||
|
NINA_WIFI_MODE_AP,
|
||||||
|
} nina_wifi_mode_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t ip_addr[NINA_IPV4_ADDR_LEN];
|
uint8_t ip_addr[NINA_IPV4_ADDR_LEN];
|
||||||
uint8_t subnet_addr[NINA_IPV4_ADDR_LEN];
|
uint8_t subnet_addr[NINA_IPV4_ADDR_LEN];
|
||||||
|
|||||||
@ -359,7 +359,7 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
|||||||
if (key == NULL && security != NINA_SEC_OPEN) {
|
if (key == NULL && security != NINA_SEC_OPEN) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (security) {
|
switch (security) {
|
||||||
case NINA_SEC_OPEN:
|
case NINA_SEC_OPEN:
|
||||||
if (nina_send_command_read_ack(SET_NET_CMD,
|
if (nina_send_command_read_ack(SET_NET_CMD,
|
||||||
@ -381,17 +381,17 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(100)) {
|
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(10)) {
|
||||||
status = nina_connection_status();
|
status = nina_connection_status();
|
||||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mp_hal_ticks_ms() - start) >= NINA_CONNECT_TIMEOUT) {
|
if ((mp_hal_ticks_ms() - start) >= NINA_CONNECT_TIMEOUT) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (status == WL_CONNECTED) ? 0 : -1;
|
return (status == WL_CONNECTED) ? 0 : -1;
|
||||||
@ -399,7 +399,42 @@ int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t c
|
|||||||
|
|
||||||
int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel)
|
int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel)
|
||||||
{
|
{
|
||||||
return -1;
|
uint8_t status = WL_AP_FAILED;
|
||||||
|
|
||||||
|
if ((key == NULL && security != NINA_SEC_OPEN) ||
|
||||||
|
(security != NINA_SEC_OPEN && security != NINA_SEC_WEP)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (security) {
|
||||||
|
case NINA_SEC_OPEN:
|
||||||
|
if (nina_send_command_read_ack(SET_AP_NET_CMD,
|
||||||
|
2, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_BYTE(channel))) != SPI_ACK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NINA_SEC_WEP:
|
||||||
|
if (nina_send_command_read_ack(SET_AP_PASSPHRASE_CMD,
|
||||||
|
3, ARG_8BITS, NINA_ARGS(ARG_STR(ssid), ARG_STR(key), ARG_BYTE(channel))) != SPI_ACK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(10)) {
|
||||||
|
status = nina_connection_status();
|
||||||
|
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((mp_hal_ticks_ms() - start) >= NINA_CONNECT_TIMEOUT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (status == WL_AP_LISTENING) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nina_disconnect()
|
int nina_disconnect()
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit ff9bd957f0475fcaf9dc5cec3c19f8e07506370f
|
Subproject commit 7ae9fc12e7f27c4b94784db13f80eac02ae83aa5
|
||||||
Loading…
Reference in New Issue
Block a user