-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Pico W: implement more things #6960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our te 8000 rms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
this works with some simple tcp & udp echo service code
Now, `led.value = not led.value` works as a way to toggle the LED state. Closes: adafruit#6959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks OK by me! Did not test the network code.
51ab560
to
4de9487
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested most of the new features briefly:
• adafruit_httpserver
runs:
% curl -iL http://192.168.6.199
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 492
Connection: close
• Didn't fully test control-C across features, but generally seemed more responsive to control-C (except during connect, which I think is expected). Added handling ETIMEOUT
to test code, I think this may be related.
• Confirm get and set tx_power
and hostname
(couldn't verify actual tx_power
level). New hostname
shows up in the router when set prior to connection, as expected.
• I'll test Power-Save more in CP. uP testing shows that generally anything but no power-save won't reliably maintain network operation over long idle intervals (for station-only). Cyw43 driver power save modes documented and implemented here. CP in current form (this PR) has the same quirk that uP has regarding IP address: it sticks around across reloads, so usual logic to check for a connection doesn't always work. Reset sometimes needed. I finally evolved uP to disconnecting and deiniting when trouble arises, then reiniting and reconnecting next time network is needed (best power savings too), but that's awkward especially for APs and servers. I don't believe CP can deinit wifi in the current API. This will probably get addressed to some extent as the other properties get added: wifi.radio.stop_station()
, wifi.radio.enabled = False
, etc. But the cyw43 driver and micropython behave different from current native wifi (espressif
), so there's probably some discussion needed about reconciling / normalizing the APIs and behavior.
This is strange relative to espressif
, where the device has an IP address if and only if it is connected to an AP:
Adafruit CircuitPython 8.0.0-beta.0-82-g8d0554e43 on 2022-09-30; Raspberry Pi Pico W with rp2040
>>> import wifi
>>>
>>> wifi.radio.ipv4_address
192.168.6.199
We need a way to test for connection. To me, it's a uP bug to have an IP address when there is no AP connection (and device is not an AP). uP uses wlan.status()
(and sometimes (wlan.isconnected()
) to test for connection (p.16). We're used to using IP address for stations. It would be ideal if espressif
network code ran unmodified on raspberrypi
.
• Confirmed digitalio.DigitalInOut
output values can now be read (and of course still written). Known quirks with these pins:
>>> digitalio.DigitalInOut(board.VBUS_SENSE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: VBUS_SENSE in use
>>> digitalio.DigitalInOut(board.VOLTAGE_MONITOR)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: A3 in use
I'm not sure what to do with this: >>> import cyw43
>>>
>>> cyw43.set_power_management
'set_power_management'
>>>
>>> cyw43.set_power_management = 0xa11140
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'set_power_management'
>>>
>>> cyw43.set_power_management(0xa11140)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable I don't think power management needs to be a priority, especially given the challenges of operating the network in the power-save modes (edit: if we default to no power save). It's been really great to see this evolve so quickly. It's quite usable for typical stuff. Thanks, jepler! 🎉 |
Huge thanks jepler! This is the most appreciated feature! ❤️ |
@@ -81,7 +92,10 @@ mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) { | |||
} | |||
|
|||
void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname) { | |||
ro_attribute(MP_QSTR_hostname); | |||
self->hostname = mp_obj_new_str(hostname, strlen(hostname)); | |||
hostname = mp_obj_str_get_str(self->hostname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be changed, as the storage for self->hostname
will be freed when the VM exits. The storage needs to be statically allocated or otherwise allocated in a way that will survive a VM reset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Espressif, the underlying ESP-IDF code keeps the hostname. Does the CYW43 allow it to be set and retrieved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, lwip just takes a copy of the pointer value.
#define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about why we would want a (custom) hostname to survive a VM reset. Don't we want a clean slate?
edit: n/m, refreshed and saw Dan's reply... if that maintains compatibility, then yea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static hostname storage looks good
We could set |
Does powersave mode "fix" something (vs just postponing it to longer polling intervals)? |
Putting it in no power-save mode (0) makes it conform more to the expectations from espressif, i.e., the network won't usually become unavailable unless something bad external happens. If the network goes away, user code (and many examples) will need to be re-written to be more defensive - not a bad thing, but harder I think for beginners to get going. I'm not a beginner (but not advanced either), and I really struggled with uP's paradigm. |
Sounds good. I don't want to hold anything up, this should get out into the world :-) |
bind
,listen
andaccept
.tx_power
and settinghostname
Note that I could not discover how to set a CywPin back to input mode, micropython does not seem capable of doing it either:
Closes: #6959