Library Utilities
Utility classes and function which are not part of the main library, but which assist in the building of servers using the library.
All code in here is strictly optional, and nothing inside the library should directly depend on it.
Wireless Network Support
Utility function and exceptions which handle the network initialisation for
the Pico W are provided by the urest.utils.network_connect
module. The
majority of the urest.utils.network_connect
module is boiler-plate, and
mimics the C library set-up required by the Pico W. For compatibility with that
library (and the documentation) the errors enumerated by the
LinkStatus
mirror the names and the
code of the C library.
Pico W Only
This module will only work on the Pico W, and with the Pico W network library. Loading this module on a Pico H, or without the Pico W network library, will result in an error.
References
Classes
LinkStatus
Bases: IntEnum
Source code in urest/utils/network_connect.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
Attributes
CYW43_LINK_BADAUTH
class-attribute
instance-attribute
CYW43_LINK_BADAUTH = const(-3)
General failure code before authentication.
Check the supplied password.
CYW43_LINK_DOWN
class-attribute
instance-attribute
CYW43_LINK_DOWN = const(0)
Failure code indicating the wireless link is unavailable.
Check the SSID is correct.
CYW43_LINK_FAIL
class-attribute
instance-attribute
CYW43_LINK_FAIL = const(-1)
General failure code.
The link specified by the SSID is unavailable for unknown reasons.
CYW43_LINK_JOIN
class-attribute
instance-attribute
CYW43_LINK_JOIN = const(1)
Failure code indicating the SSID or password is incorrect and the specified SSID cannot be joined.
Check the SSID and password.
CYW43_LINK_NOIP
class-attribute
instance-attribute
CYW43_LINK_NOIP = const(2)
Failure code indicating the join request was successful: but no IP address was returned.
Check the DHCP settings for the specified SSID
CYW43_LINK_NONET
class-attribute
instance-attribute
CYW43_LINK_NONET = const(-2)
General failure code after authentication.
The authentication likely succeeded: but the subsequent attempts to complete the connection failed.
CYW43_LINK_UP
class-attribute
instance-attribute
CYW43_LINK_UP = const(3)
Success code indicating a successful join, and that an IP address was obtained from the network.
WirelessNetworkError
Bases: Exception
General Wireless Network Exception. Thrown in response to one of the
codes listed in the module Attributes
, and originating from the
underlying C library.
The message of the the Exception
is set to an appropriate
response, and it should be assumed that the text of the Exception
will be passed back to the user. Therefore it is important that the
message aids further debugging without having to consult the
underlying library documentation.
Source code in urest/utils/network_connect.py
119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
Functions
netcode_to_str
netcode_to_str(error_code: LinkStatus) -> str
Convert the given wireless network error code to a short string, indicating the possible error.
Note that no validation for sanity of the error code is attempted by this function. However the returned values are expected to be displayed directly to the user, and so should indicate (at least minimally) where further investigation might be helpful.
Source code in urest/utils/network_connect.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
wireless_enable
wireless_enable(
ssid: str,
password: str,
link_light: Union[int, str] = "WL_GPIO0",
) -> None
Enable the default wireless interface, connecting to the networking
using the specified ssid
and password
. Optionally also supply the name,
or the pin number, of the GPIO pin to use as the link_light
, which will
be ‘on’ if the network connection succeeds (and ‘off’ otherwise).
Clear Text Password
As with the default wireless library, the password
must be supplied to
this function in clear text. This presents a potential exposure risk
of the password
, and that risk should be mitigated by appropriate storage and
handling of the password before calling this function.
Parameters: |
|
---|
Raises: |
|
---|
Source code in urest/utils/network_connect.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|