8000 Pico W: implement more things by jepler · Pull Request #6960 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 14 commits into from
Sep 30, 2022
Merged

Pico W: implement more things #6960

merged 14 commits into from
Sep 30, 2022

Conversation

jepler
Copy link
@jepler jepler commented Sep 29, 2022
  • In socketl, implement bind, listen and accept.
  • In socket, most long running operations can be interrupted by ctrl-c now
  • In wifi.radio, implement tx_power and setting hostname
  • In cyw43, implement set_power_management. One documented value, 0xa111440, can be used to disable aggressive power saving. Other values are not documented by Raspberry Pi, and document CywPin
  • in digitalio, implement reading back the value of a CywPin
  • Switch SMPS_PIN and GPIO23 to use CywPin 1

Note that I could not discover how to set a CywPin back to input mode, micropython does not seem capable of doing it either:

    if (args[ARG_mode].u_obj != mp_const_none) {
        mp_int_t mode = mp_obj_get_int(args[ARG_mode].u_obj);
        if (mode == GPIO_MODE_IN) {
            if (self->is_output) {
                // todo need to disable output
            }
        ...

Closes: #6959

dhalbert
dhalbert previously approved these changes Sep 30, 2022
Copy link
Collaborator
@dhalbert dhalbert left a 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.

dhalbert
dhalbert previously approved these changes Sep 30, 2022
dhalbert
dhalbert previously approved these changes Sep 30, 2022
Copy link
Member
@anecdata anecdata left a 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

@anecdata
Copy link
Member
anecdata commented Sep 30, 2022

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! 🎉

@DeadSix27
Copy link

Huge thanks jepler! This is the most appreciated feature! ❤️

dhalbert
dhalbert previously approved these changes Sep 30, 2022
@@ -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);
Copy link
Author

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.

Copy link
Collaborator

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?

Copy link
Author

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)

Copy link
Member
@anecdata anecdata Sep 30, 2022

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

Copy link
Collaborator
@dhalbert dhalbert left a 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

@anecdata
Copy link
Member
anecdata commented Sep 30, 2022

We could set #define CYW43_NO_POWERSAVE_MODE (0) ///< No Powersave mode as default, then the network is much more robust (and compatible with espressif). My trusty PPK, er, Charge Doctor indicates ~20 mA idling in power-save modes 1 and 2, ~30mA or so idling in no-power-save mode 0, and ~10mA or less idling when de-inited (those seem low, but that's what it reads steadily).

@jepler
Copy link
Author
jepler commented Sep 30, 2022

Does powersave mode "fix" something (vs just postponing it to longer polling intervals)?

@anecdata
Copy link
Member
anecdata commented Sep 30, 2022

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.

@jepler
Copy link
Author
jepler commented Sep 30, 2022

Let's discuss options around powersave mode on the issue: #6958

But short story, if your testing shows that changing that compile time flag means we can resolve #6958 let's do it.

@anecdata
Copy link
Member

Sounds good. I don't want to hold anything up, this should get out into the world :-)

@jepler jepler merged commit fcf7cfe into adafruit:main Sep 30, 2022
@jepler jepler deleted the picow 7713 -server branch October 11, 2022 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raspberry Pi Pico W - reading digital output is always False
4 participants
0