Nina driver updates, bug fixes.

This commit is contained in:
iabdalkader 2021-11-17 18:29:23 +02:00
parent 9c15742eb2
commit 5c127078ca
5 changed files with 349 additions and 358 deletions

View File

@ -11,6 +11,7 @@ print("Scanning...")
while (True): while (True):
scan_result = wlan.scan() scan_result = wlan.scan()
for ap in scan_result: for ap in scan_result:
print("Channel:%d RSSI:%d Auth:%d BSSID:%s SSID:%s"%(ap)) print("SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d"
%(ap[0], ":".join(["%X"%i for i in ap[1]]), ap[2], ap[3], ap[4]))
print() print()
time.sleep_ms(1000) time.sleep_ms(1000)

View File

@ -8,9 +8,11 @@ wlan = network.WLAN(network.STA_IF)
wlan.deinit() wlan.deinit()
wlan.active(True) wlan.active(True)
print("Scanning...")
while (True): while (True):
scan_result = wlan.scan() scan_result = wlan.scan()
for ap in scan_result: for ap in scan_result:
print(ap) print("SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d"
%(ap[0], ":".join(["%X"%i for i in ap[1]]), ap[2], ap[3], ap[4]))
print() print()
time.sleep_ms(1000) time.sleep_ms(1000)

View File

@ -6,10 +6,11 @@
* *
* This work is licensed under the MIT license, see the file LICENSE for details. * This work is licensed under the MIT license, see the file LICENSE for details.
* *
* NINA-W10 driver. * NINA-W10 WiFi driver.
*/ */
#ifndef __NINA_H__ #ifndef __NINA_H__
#define __NINA_H__ #define __NINA_H__
#define NINA_FW_VER_LEN (6) #define NINA_FW_VER_LEN (6)
#define NINA_IPV4_ADDR_LEN (4) #define NINA_IPV4_ADDR_LEN (4)
#define NINA_MAC_ADDR_LEN (6) #define NINA_MAC_ADDR_LEN (6)
@ -17,7 +18,7 @@
#define NINA_MAX_WEP_LEN (13) #define NINA_MAX_WEP_LEN (13)
#define NINA_MAX_WPA_LEN (63) #define NINA_MAX_WPA_LEN (63)
#define NINA_MAX_NETWORK_LIST (10) #define NINA_MAX_NETWORK_LIST (10)
#define NINA_MAX_SOCKET (10) #define NINA_MAX_SOCKET (10)
#define NINA_FW_VER_MAJOR (1) #define NINA_FW_VER_MAJOR (1)
#define NINA_FW_VER_MINOR (4) #define NINA_FW_VER_MINOR (4)
@ -47,7 +48,6 @@ typedef enum {
NINA_ERROR_TIMEOUT = -2, NINA_ERROR_TIMEOUT = -2,
} nina_error_t; } nina_error_t;
typedef enum { typedef enum {
NINA_WIFI_MODE_STA = 0, NINA_WIFI_MODE_STA = 0,
NINA_WIFI_MODE_AP, NINA_WIFI_MODE_AP,
@ -61,34 +61,34 @@ typedef struct {
} nina_ifconfig_t; } nina_ifconfig_t;
typedef struct { typedef struct {
int8_t rssi; int32_t rssi;
uint8_t security; uint8_t security;
uint8_t channel; uint8_t channel;
uint8_t bssid[NINA_MAC_ADDR_LEN]; uint8_t bssid[NINA_MAC_ADDR_LEN];
char ssid[NINA_MAX_SSID_LEN]; char ssid[NINA_MAX_SSID_LEN];
} nina_scan_result_t; } nina_scan_result_t;
typedef struct { typedef struct {
int8_t rssi; int32_t rssi;
uint8_t security; uint8_t security;
char ssid[NINA_MAX_SSID_LEN]; char ssid[NINA_MAX_SSID_LEN];
uint8_t bssid[NINA_MAC_ADDR_LEN]; uint8_t bssid[NINA_MAC_ADDR_LEN];
} nina_netinfo_t; } nina_netinfo_t;
typedef int (*nina_scan_callback_t) (nina_scan_result_t *, void *); typedef int (*nina_scan_callback_t)(nina_scan_result_t *, void *);
int nina_init(); int nina_init(void);
int nina_deinit(); int nina_deinit(void);
int nina_connect(const char *ssid, uint8_t security, const char *key, uint16_t channel); int nina_connect(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); int nina_start_ap(const char *ssid, uint8_t security, const char *key, uint16_t channel);
int nina_disconnect(); int nina_disconnect(void);
int nina_isconnected(); int nina_isconnected(void);
int nina_connected_sta(uint32_t *sta_ip); int nina_connected_sta(uint32_t *sta_ip);
int nina_wait_for_sta(uint32_t *sta_ip, uint32_t timeout); int nina_wait_for_sta(uint32_t *sta_ip, uint32_t timeout);
int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set); int nina_ifconfig(nina_ifconfig_t *ifconfig, bool set);
int nina_netinfo(nina_netinfo_t *netinfo); int nina_netinfo(nina_netinfo_t *netinfo);
int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout); int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout);
int nina_get_rssi(); int nina_get_rssi(void);
int nina_fw_version(uint8_t *fw_ver); int nina_fw_version(uint8_t *fw_ver);
int nina_set_hostname(const char *name); int nina_set_hostname(const char *name);
int nina_gethostbyname(const char *name, uint8_t *out_ip); int nina_gethostbyname(const char *name, uint8_t *out_ip);

File diff suppressed because it is too large Load Diff

View File

@ -258,24 +258,16 @@ static mp_obj_t py_nina_netinfo(mp_obj_t self_in)
static int nina_scan_callback(nina_scan_result_t *scan_result, void *arg) static int nina_scan_callback(nina_scan_result_t *scan_result, void *arg)
{ {
mp_obj_t scan_list = (mp_obj_t) arg; mp_obj_t scan_list = (mp_obj_t)arg;
mp_obj_t ap[6] = {
// Format MAC address mp_obj_new_bytes((uint8_t *)scan_result->ssid, strlen(scan_result->ssid)),
VSTR_FIXED(bssid_vstr, 18); mp_obj_new_bytes(scan_result->bssid, sizeof(scan_result->bssid)),
vstr_printf(&bssid_vstr, "%02X:%02X:%02X:%02X:%02X:%02X",
scan_result->bssid[0], scan_result->bssid[1], scan_result->bssid[2],
scan_result->bssid[3], scan_result->bssid[4], scan_result->bssid[5]);
mp_obj_t ap[5] = {
mp_obj_new_int(scan_result->channel), mp_obj_new_int(scan_result->channel),
mp_obj_new_int(scan_result->rssi), mp_obj_new_int(scan_result->rssi),
mp_obj_new_int(scan_result->security), mp_obj_new_int(scan_result->security),
mp_obj_new_str(bssid_vstr.buf, bssid_vstr.len), MP_OBJ_NEW_SMALL_INT(1), // N
mp_obj_new_str(scan_result->ssid, strlen(scan_result->ssid)),
}; };
mp_obj_list_append(scan_list, mp_obj_new_tuple(MP_ARRAY_SIZE(ap), ap)); mp_obj_list_append(scan_list, mp_obj_new_tuple(MP_ARRAY_SIZE(ap), ap));
return 0; return 0;
} }