Skip to content

Commit 6c3cdce

Browse files
committed
Implement scan, connect, ping
My pings go out, and then they come back ```py import os import wifi import ipaddress wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD')) ipv4 = ipaddress.ip_address("8.8.4.4") print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000)) ```
1 parent 346fff2 commit 6c3cdce

File tree

29 files changed

+1472
-26
lines changed

29 files changed

+1472
-26
lines changed

locale/circuitpython.pot

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ msgstr ""
303303
msgid "'%s' object doesn't support item deletion"
304304
msgstr ""
305305

306-
#: py/runtime.c
306+
#: ports/raspberrypi/common-hal/wifi/Radio.c py/runtime.c
307307
msgid "'%s' object has no attribute '%q'"
308308
msgstr ""
309309

@@ -489,6 +489,7 @@ msgid "Already running"
489489
msgstr ""
490490

491491
#: ports/espressif/common-hal/wifi/Radio.c
492+
#: ports/raspberrypi/common-hal/wifi/Radio.c
492493
msgid "Already scanning for wifi networks"
493494
msgstr ""
494495

@@ -2208,6 +2209,11 @@ msgstr ""
22082209
msgid "Unknown system firmware error: %d"
22092210
msgstr ""
22102211

2212+
#: ports/raspberrypi/common-hal/wifi/__init__.c
2213+
#, c-format
2214+
msgid "Unkown error code %d"
2215+
msgstr ""
2216+
22112217
#: shared-bindings/adafruit_pixelbuf/PixelBuf.c
22122218
#, c-format
22132219
msgid "Unmatched number of items on RHS (expected %d, got %d)."
@@ -4137,14 +4143,10 @@ msgstr ""
41374143
msgid "type is not an acceptable base type"
41384144
msgstr ""
41394145

4140-
#: py/runtime.c
4146+
#: py/objgenerator.c py/runtime.c
41414147
msgid "type object '%q' has no attribute '%q'"
41424148
msgstr ""
41434149

4144-
#: py/objgenerator.c
4145-
msgid "type object 'generator' has no attribute '__await__'"
4146-
msgstr ""
4147-
41484150
#: py/objtype.c
41494151
msgid "type takes 1 or 3 arguments"
41504152
msgstr ""
@@ -4276,9 +4278,14 @@ msgid "width must be greater than zero"
42764278
msgstr ""
42774279

42784280
#: ports/espressif/common-hal/wifi/Radio.c
4281+
#: ports/raspberrypi/common-hal/wifi/Radio.c
42794282
msgid "wifi is not enabled"
42804283
msgstr ""
42814284

4285+
#: ports/raspberrypi/common-hal/wifi/Monitor.c
4286+
msgid "wifi.Monitor not available"
4287+
msgstr ""
4288+
42824289
#: shared-bindings/_bleio/Adapter.c
42834290
msgid "window must be <= interval"
42844291
msgstr ""

mpy-cross/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ override undefine PROG
2020
endif
2121

2222
include mpy-cross.mk
23+
CFLAGS += -g
24+
STRIP = :

ports/espressif/esp32-camera

ports/raspberrypi/Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,30 @@ HAL_DIR=hal/$(MCU_SERIES)
5959

6060
ifeq ($(CIRCUITPY_CYW43),1)
6161
INC_CYW43 := \
62-
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
63-
-isystem sdk/lib/cyw43-driver/src \
6462
-isystem sdk/lib/cyw43-driver/firmware \
63+
-isystem sdk/lib/cyw43-driver/src \
64+
-isystem sdk/lib/lwip/src/include \
65+
-isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \
66+
-isystem sdk/src/rp2_common/pico_lwip/include/ \
6567

66-
CFLAGS_CYW43 := -DCYW43_LWIP=0 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25
68+
CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25
6769
SRC_SDK_CYW43 := \
6870
lib/cyw43-driver/src/cyw43_ctrl.c \
6971
lib/cyw43-driver/src/cyw43_ll.c \
7072
lib/cyw43-driver/src/cyw43_lwip.c \
7173
lib/cyw43-driver/src/cyw43_stats.c \
7274
src/common/pico_sync/sem.c \
75+
src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \
7376
src/rp2_common/pico_cyw43_arch/cyw43_arch.c \
7477
src/rp2_common/pico_cyw43_arch/cyw43_arch_threadsafe_background.c \
75-
src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \
78+
src/rp2_common/pico_lwip/nosys.c \
79+
src/rp2_common/pico_lwip/random.c \
80+
81+
SRC_LWIP := \
82+
$(wildcard sdk/lib/lwip/src/core/*.c) \
83+
$(wildcard sdk/lib/lwip/src/core/ipv4/*.c) \
84+
sdk/lib/lwip/src/netif/ethernet.c \
85+
$(wildcard lwip_src/*.c) \
7686

7787
SRC_CYW43 := $(wildcard bindings/cyw43/*.c)
7888

@@ -114,16 +124,17 @@ OBJ_CYW43 := $(BUILD)/cyw43_resource.o
114124
### )
115125
###
116126
else
117-
$(error y u no y fi)
118127
INC_CYW43 :=
119128
CFLAGS_CYW43 :=
120129
SRC_SDK_CYW43 :=
121130
SRC_CYW43 :=
122131
OBJ_CYW43 :=
132+
SRC_LWIP :=
123133
endif
124134

125135
INC += \
126136
-I. \
137+
-Ilwip_inc \
127138
-I../.. \
128139
-I../lib/mp-readline \
129140
-I../shared/timeutils \
@@ -276,6 +287,7 @@ SRC_C += \
276287
lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \
277288
mphalport.c \
278289
$(SRC_CYW43) \
290+
$(SRC_LWIP) \
279291

280292
SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
281293
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \

ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ CIRCUITPY_HASHLIB = 0
1616
CIRCUITPY_WEB_WORKFLOW = 0
1717
CIRCUITPY_MDNS = 0
1818
CIRCUITPY_SOCKETPOOL = 0
19+
CIRCUITPY_WIFI = 1
1920

2021
CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <string.h>
28+
29+
#include "py/mpstate.h"
30+
#include "py/runtime.h"
31+
32+
#include "shared-bindings/wifi/Monitor.h"
33+
#include "shared-bindings/wifi/Packet.h"
34+
35+
36+
#define MONITOR_PAYLOAD_FCS_LEN (4)
37+
#define MONITOR_QUEUE_TIMEOUT_TICK (0)
38+
39+
typedef struct {
40+
} monitor_packet_t;
41+
42+
void common_hal_wifi_monitor_construct(wifi_monitor_obj_t *self, uint8_t channel, size_t queue) {
43+
mp_raise_NotImplementedError(translate("wifi.Monitor not available"));
44+
}
45+
46+
bool common_hal_wifi_monitor_deinited(void) {
47+
return true;
48+
}
49+
50+
void common_hal_wifi_monitor_deinit(wifi_monitor_obj_t *self) {
51+
}
52+
53+
void common_hal_wifi_monitor_set_channel(wifi_monitor_obj_t *self, uint8_t channel) {
54+
}
55+
56+
mp_obj_t common_hal_wifi_monitor_get_channel(wifi_monitor_obj_t *self) {
57+
return MP_OBJ_NEW_SMALL_INT(0);
58+
}
59+
60+
mp_obj_t common_hal_wifi_monitor_get_queue(wifi_monitor_obj_t *self) {
61+
return mp_obj_new_int_from_uint(0);
62+
}
63+
64+
mp_obj_t common_hal_wifi_monitor_get_lost(wifi_monitor_obj_t *self) {
65+
return mp_obj_new_int_from_uint(0);
66+
}
67+
68+
mp_obj_t common_hal_wifi_monitor_get_queued(wifi_monitor_obj_t *self) {
69+
return mp_obj_new_int_from_uint(0);
70+
}
71+
72+
mp_obj_t common_hal_wifi_monitor_get_packet(wifi_monitor_obj_t *self) {
73+
return mp_const_none;
74+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 microDev
7+
* Copyright (c) 2022 Jeff Epler for Adafruit Industries
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H
29+
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H
30+
31+
#include "py/obj.h"
32+
33+
typedef struct {
34+
mp_obj_base_t base;
35+
uint8_t channel;
36+
size_t lost;
37+
size_t queue_length;
38+
} wifi_monitor_obj_t;
39+
40+
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WIFI_MONITOR_H
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <string.h>
28+
29+
#include "shared-bindings/wifi/Network.h"
30+
#include "shared-bindings/wifi/AuthMode.h"
31+
32+
mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) {
33+
const char *cstr = (const char *)self->record.ssid;
34+
return mp_obj_new_str(cstr, self->record.ssid_len);
35+
}
36+
37+
#define MAC_ADDRESS_LENGTH 6
38+
39+
mp_obj_t common_hal_wifi_network_get_bssid(wifi_network_obj_t *self) {
40+
return mp_obj_new_bytes(self->record.bssid, MAC_ADDRESS_LENGTH);
41+
}
42+
43+
mp_obj_t common_hal_wifi_network_get_rssi(wifi_network_obj_t *self) {
44+
return mp_obj_new_int(self->record.rssi);
45+
}
46+
47+
mp_obj_t common_hal_wifi_network_get_channel(wifi_network_obj_t *self) {
48+
return mp_obj_new_int(self->record.channel);
49+
}
50+
51+
mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
52+
return (mp_obj_t)MP_QSTR_;
53+
}
54+
55+
mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) {
56+
uint8_t authmode_mask = 0;
57+
if (self->record.auth_mode == 0) {
58+
authmode_mask = (1 << AUTHMODE_OPEN);
59+
}
60+
if (self->record.auth_mode & 1) {
61+
authmode_mask |= (1 << AUTHMODE_PSK);
62+
}
63+
;
64+
if (self->record.auth_mode & 2) {
65+
authmode_mask |= (1 << AUTHMODE_WPA);
66+
}
67+
;
68+
if (self->record.auth_mode & 4) {
69+
authmode_mask |= (1 << AUTHMODE_WPA2);
70+
}
71+
;
72+
mp_obj_t authmode_list = mp_obj_new_list(0, NULL);
73+
if (authmode_mask != 0) {
74+
for (uint8_t i = 0; i < 8; i++) {
75+
if ((authmode_mask >> i) & 1) {
76+
mp_obj_list_append(authmode_list, cp_enum_find(&wifi_authmode_type, i));
77+
}
78+
}
79+
}
80+
return authmode_list;
81+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#pragma once
28+
29+
#include "py/obj.h"
30+
31+
#include "pico/cyw43_arch.h"
32+
33+
typedef struct {
34+
mp_obj_base_t base;
35+
cyw43_ev_scan_result_t record;
36+
} wifi_network_obj_t;

0 commit comments

Comments
 (0)