Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

esp32/modnetwork.c: Report SSID values as strings. #50

Closed
wants to merge 3 commits into from

Conversation

StopHacking
Copy link

From WLAN, I would like to get reported SSID names as strings rather than byte arrays.
In the configuration, SSID names are passed via strings into the driver, and so reading SSID names
from the driver should return them as strings too.

@dpgeorge
Copy link
Member

Sorry for the late response.

There are 2 independent changes here:

  • Changing scan results to return str instead of bytes for the ssid. esp8266 returns bytes so that's how it should stay. It's really a bytes entity because it could contain non-ascii chars, and so converting to a str would be wrong.
  • Allowing config('essid') to return the ssid of the AP that the device is connected to. As far as I see, this change is ok.

@nickzoic
Copy link
Collaborator

nickzoic commented May 19, 2017 via email

@nickzoic
Copy link
Collaborator

nickzoic commented Oct 3, 2017

Re: config('essid') returning the APs SSID when in STA mode: I think this should be returned by status (along with RSSI etc). 'config' suits read/write parameters, I think.

Perhaps at the same time as we define AP status for #186 we can define a structure for STA status (and perhaps also for the Ethernet PHY #187)

@nickzoic
Copy link
Collaborator

nickzoic commented Oct 3, 2017

Thanks for your PR and please do keep contributing but I'm going to close this particular PR because of the problems above.

A couple of thoughts on this work though:

  1. The SSID can be set from a bytes() array, allowing it to be set from a string is a shorthand.

2 In 802.11-2012 6.3.11.2.2 there's an additional "SSID-Encoding" flag which indicates if the SSID encoding is "UNSPECIFED" or "UTF8", but there's no particular guarantee that it'll be valid or printable UTF-8 even if this flag is set so I don't know to what extent it is actually useful.

  1. In practice, devices seem to have a stab at decoding the bytes as UTF-8 and just ignore anything which goes wrong: for example u'\U0001f4a9' displays as the pile-of-poo emoji and b'abc\0def'displays just as abcdef. Broken UTF-8 (eg: bytes([0xf0,0xf0])) displays as some other (chinese?) encoding on Android, and other characters on other systems

  2. Perhaps it'd make sense to provide a Python helper function to "do the obvious thing" when displaying SSIDs but displaying arbitrary byte arrays as strings is a problem beyond just SSIDs

@nickzoic nickzoic closed this Oct 3, 2017
@dpgeorge
Copy link
Member

dpgeorge commented Oct 4, 2017

Re: config('essid') returning the APs SSID when in STA mode: I think this should be returned by status (along with RSSI etc). 'config' suits read/write parameters

Yes, good point, config() is for configuring parameters of the wlan/eth/etc.

@nickzoic
Copy link
Collaborator

nickzoic commented Oct 4, 2017 via email

@dpgeorge
Copy link
Member

dpgeorge commented Oct 5, 2017

How do you feel about the dictionaries-and-lists format for status as I suggested in #186, eg for a connected WiFi station

@nickzoic actually, if you read again the current network.rst docs it has an example for getting the STA RSSI: sta.config('rssi'). So that would be a way to cover that specific case. And generalisig that, config() could be used to retrieve other info about the connection, and for AP mode the list of connected clients. Note also the existence of "attrtuples" which are an efficient version of a namedtuple used to return info like this (see uPy's sys.implementation).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants