Rename endpoint, format

This commit is contained in:
Ádám Kovács
2023-12-08 07:41:47 +01:00
parent dd92fbc62f
commit fd5fc9e5f8
27 changed files with 781 additions and 117 deletions

View File

@@ -1,4 +1,5 @@
# allows for type checking of additional builtins by pyright
"""Allows for type checking of Micropython specific builtins by pyright and pylance.
"""
from typing import Tuple, TypeVar

View File

@@ -1,4 +1,40 @@
from _typeshed import Incomplete as Incomplete
"""
Asynchronous I/O scheduler for writing concurrent code.
MicroPython module: https://docs.micropython.org/en/v1.21.0/library/asyncio.html
CPython module:
`asyncio `<https://docs.python.org/3.8/library/asyncio.html>
Example::
import asyncio
async def blink(led, period_ms):
while True:
led.on()
await asyncio.sleep_ms(5)
led.off()
await asyncio.sleep_ms(period_ms)
async def main(led1, led2):
asyncio.create_task(blink(led1, 700))
asyncio.create_task(blink(led2, 400))
await asyncio.sleep_ms(10_000)
# Running on a pyboard
from pyb import LED
asyncio.run(main(LED(1), LED(2)))
# Running on a generic board
from machine import Pin
asyncio.run(main(Pin(1), Pin(2)))
Core functions
--------------
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from typing import Any, Coroutine, List, Tuple
class TaskQueue:
def push(self, *args, **kwargs) -> Incomplete: ...
@@ -8,4 +44,12 @@ class TaskQueue:
def __init__(self, *argv, **kwargs) -> None: ...
class Task:
def __init__(self, *argv, **kwargs) -> None: ...
"""
This object wraps a coroutine into a running task. Tasks can be waited on
using ``await task``, which will wait for the task to complete and return
the return value of the task.
Tasks should not be created directly, rather use `create_task` to create them.
"""
def __init__(self) -> None: ...

View File

@@ -1,15 +1,58 @@
from _typeshed import Incomplete as Incomplete
"""
Functionality specific to the RP2.
MicroPython module: https://docs.micropython.org/en/v1.21.0/library/rp2.html
The ``rp2`` module contains functions and classes specific to the RP2040, as
used in the Raspberry Pi Pico.
See the `RP2040 Python datasheet
<https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf>`_
for more information, and `pico-micropython-examples
<https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio>`_
for example code.
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from typing import Any, Optional
def country(*args, **kwargs) -> Incomplete: ...
def bootsel_button(*args, **kwargs) -> Incomplete: ...
def bootsel_button() -> Incomplete:
"""
Temporarily turns the QSPI_SS pin into an input and reads its value,
returning 1 for low and 0 for high.
On a typical RP2040 board with a BOOTSEL button, a return value of 1
indicates that the button is pressed.
Since this function temporarily disables access to the external flash
memory, it also temporarily disables interrupts and the other core to
prevent them from trying to execute code from flash.
"""
...
class Flash:
def readblocks(self, *args, **kwargs) -> Incomplete: ...
def writeblocks(self, *args, **kwargs) -> Incomplete: ...
def ioctl(self, *args, **kwargs) -> Incomplete: ...
def __init__(self, *argv, **kwargs) -> None: ...
"""
Gets the singleton object for accessing the SPI flash memory.
"""
def readblocks(self, block_num, buf, offset: Optional[int] = 0) -> Incomplete: ...
def writeblocks(self, block_num, buf, offset: Optional[int] = 0) -> Incomplete: ...
def ioctl(self, cmd, arg) -> Incomplete:
"""
These methods implement the simple and extended
:ref:`block protocol <block-device-interface>` defined by
:class:`os.AbstractBlockDev`.
"""
...
def __init__(self) -> None: ...
class PIO:
"""
Gets the PIO instance numbered *id*. The RP2040 has two PIO instances,
numbered 0 and 1.
Raises a ``ValueError`` if any other argument is provided.
"""
JOIN_TX: int
JOIN_NONE: int
JOIN_RX: int
@@ -23,20 +66,191 @@ class PIO:
IRQ_SM2: int
IRQ_SM0: int
IRQ_SM1: int
def state_machine(self, *args, **kwargs) -> Incomplete: ...
def remove_program(self, *args, **kwargs) -> Incomplete: ...
def irq(self, *args, **kwargs) -> Incomplete: ...
def add_program(self, *args, **kwargs) -> Incomplete: ...
def __init__(self, *argv, **kwargs) -> None: ...
def state_machine(self, id, program, *args, **kwargs) -> Incomplete:
"""
Gets the state machine numbered *id*. On the RP2040, each PIO instance has
four state machines, numbered 0 to 3.
Optionally initialize it with a *program*: see `StateMachine.init`.
>>> rp2.PIO(1).state_machine(3)
StateMachine(7)
"""
...
def remove_program(self, program: Optional[Any] = None) -> None:
"""
Remove *program* from the instruction memory of this PIO instance.
If no program is provided, it removes all programs.
It is not an error to remove a program which has already been removed.
"""
...
def irq(self, handler=None, trigger=IRQ_SM0, hard=False) -> Incomplete:
"""
Returns the IRQ object for this PIO instance.
MicroPython only uses IRQ 0 on each PIO instance. IRQ 1 is not available.
Optionally configure it.
"""
...
def add_program(self, program) -> Incomplete:
"""
Add the *program* to the instruction memory of this PIO instance.
The amount of memory available for programs on each PIO instance is
limited. If there isn't enough space left in the PIO's program memory
this method will raise ``OSError(ENOMEM)``.
"""
...
def __init__(self, id) -> None: ...
class StateMachine:
def irq(self, *args, **kwargs) -> Incomplete: ...
def put(self, *args, **kwargs) -> Incomplete: ...
def restart(self, *args, **kwargs) -> Incomplete: ...
def rx_fifo(self, *args, **kwargs) -> Incomplete: ...
def tx_fifo(self, *args, **kwargs) -> Incomplete: ...
def init(self, *args, **kwargs) -> Incomplete: ...
def exec(self, *args, **kwargs) -> Incomplete: ...
def get(self, *args, **kwargs) -> Incomplete: ...
def active(self, *args, **kwargs) -> Incomplete: ...
def __init__(self, *argv, **kwargs) -> None: ...
"""
Get the state machine numbered *id*. The RP2040 has two identical PIO
instances, each with 4 state machines: so there are 8 state machines in
total, numbered 0 to 7.
Optionally initialize it with the given program *program*: see
`StateMachine.init`.
"""
def irq(self, handler=None, trigger=0 | 1, hard=False) -> Incomplete:
"""
Returns the IRQ object for the given StateMachine.
Optionally configure it.
"""
...
def put(self, value, shift=0) -> Incomplete:
"""
Push words onto the state machine's TX FIFO.
*value* can be an integer, an array of type ``B``, ``H`` or ``I``, or a
`bytearray`.
This method will block until all words have been written to the FIFO. If
the FIFO is, or becomes, full, the method will block until the state machine
pulls enough words to complete the write.
Each word is first shifted left by *shift* bits, i.e. the state machine
receives ``word << shift``.
"""
...
def restart(self) -> Incomplete:
"""
Restarts the state machine and jumps to the beginning of the program.
This method clears the state machine's internal state using the RP2040's
``SM_RESTART`` register. This includes:
- input and output shift counters
- the contents of the input shift register
- the delay counter
- the waiting-on-IRQ state
- a stalled instruction run using `StateMachine.exec()`
"""
...
def rx_fifo(self) -> int:
"""
Returns the number of words in the state machine's RX FIFO. A value of 0
indicates the FIFO is empty.
Useful for checking if data is waiting to be read, before calling
`StateMachine.get()`.
"""
...
def tx_fifo(self) -> int:
"""
Returns the number of words in the state machine's TX FIFO. A value of 0
indicates the FIFO is empty.
Useful for checking if there is space to push another word using
`StateMachine.put()`.
"""
...
def init(
self,
program,
freq=-1,
*,
in_base=None,
out_base=None,
set_base=None,
jmp_pin=None,
sideset_base=None,
in_shiftdir=None,
out_shiftdir=None,
push_thresh=None,
pull_thresh=None,
) -> None:
"""
Configure the state machine instance to run the given *program*.
The program is added to the instruction memory of this PIO instance. If the
instruction memory already contains this program, then its offset is
re-used so as to save on instruction memory.
- *freq* is the frequency in Hz to run the state machine at. Defaults to
the system clock frequency.
The clock divider is computed as ``system clock frequency / freq``, so
there can be slight rounding errors.
The minimum possible clock divider is one 65536th of the system clock: so
at the default system clock frequency of 125MHz, the minimum value of
*freq* is ``1908``. To run state machines at slower frequencies, you'll
need to reduce the system clock speed with `machine.freq()`.
- *in_base* is the first pin to use for ``in()`` instructions.
- *out_base* is the first pin to use for ``out()`` instructions.
- *set_base* is the first pin to use for ``set()`` instructions.
- *jmp_pin* is the first pin to use for ``jmp(pin, ...)`` instructions.
- *sideset_base* is the first pin to use for side-setting.
- *in_shiftdir* is the direction the ISR will shift, either
`PIO.SHIFT_LEFT` or `PIO.SHIFT_RIGHT`.
- *out_shiftdir* is the direction the OSR will shift, either
`PIO.SHIFT_LEFT` or `PIO.SHIFT_RIGHT`.
- *push_thresh* is the threshold in bits before auto-push or conditional
re-pushing is triggered.
- *pull_thresh* is the threshold in bits before auto-pull or conditional
re-pulling is triggered.
"""
...
def exec(self, instr) -> Incomplete:
"""
Execute a single PIO instruction.
If *instr* is a string then uses `asm_pio_encode` to encode the instruction
from the given string.
>>> sm.exec("set(0, 1)")
If *instr* is an integer then it is treated as an already encoded PIO
machine code instruction to be executed.
>>> sm.exec(rp2.asm_pio_encode("out(y, 8)", 0))
"""
...
def get(self, buf=None, shift=0) -> Incomplete:
"""
Pull a word from the state machine's RX FIFO.
If the FIFO is empty, it blocks until data arrives (i.e. the state machine
pushes a word).
The value is shifted right by *shift* bits before returning, i.e. the
return value is ``word >> shift``.
"""
...
def active(self, value: Optional[Any] = None) -> Incomplete:
"""
Gets or sets whether the state machine is currently running.
>>> sm.active()
True
>>> sm.active(0)
False
"""
...
def __init__(self, id, program, *args, **kwargs) -> None: ...

View File

@@ -46,7 +46,7 @@ class ScanResult:
connectable: bool
def __init__(self, device) -> None: ...
def _update(self, adv_type, rssi, adv_data): ...
def __str__(self): ...
def __str__(self) -> str: ...
def _decode_field(self, *adv_type) -> Generator[Incomplete, None, None]: ...
def name(self): ...
def services(self) -> Generator[Incomplete, None, None]: ...

View File

@@ -46,7 +46,7 @@ class ClientService:
_end_handle: Incomplete
uuid: Incomplete
def __init__(self, connection, start_handle, end_handle, uuid) -> None: ...
def __str__(self): ...
def __str__(self) -> str: ...
async def characteristic(self, uuid, timeout_ms: int = ...): ...
def characteristics(self, uuid: Incomplete | None = ..., timeout_ms: int = ...): ...
def _start_discovery(connection, uuid: Incomplete | None = ...) -> None: ...
@@ -79,7 +79,7 @@ class ClientCharacteristic(BaseClientCharacteristic):
_indicate_event: Incomplete
_indicate_queue: Incomplete
def __init__(self, service, end_handle, value_handle, properties, uuid) -> None: ...
def __str__(self): ...
def __str__(self) -> str: ...
def _connection(self): ...
async def descriptor(self, uuid, timeout_ms: int = ...): ...
def descriptors(self, timeout_ms: int = ...): ...
@@ -95,6 +95,6 @@ class ClientCharacteristic(BaseClientCharacteristic):
class ClientDescriptor(BaseClientCharacteristic):
characteristic: Incomplete
def __init__(self, characteristic, dsc_handle, uuid) -> None: ...
def __str__(self): ...
def __str__(self) -> str: ...
def _connection(self): ...
def _start_discovery(characteristic, uuid: Incomplete | None = ...) -> None: ...

View File

@@ -15,7 +15,9 @@ class DeviceTimeout:
def __init__(self, connection, timeout_ms) -> None: ...
async def _timeout_sleep(self) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, exc_type, exc_val, exc_traceback) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_traceback: types.TracebackType | None
) -> None: ...
class Device:
addr_type: Incomplete
@@ -24,7 +26,7 @@ class Device:
def __init__(self, addr_type, addr) -> None: ...
def __eq__(self, rhs): ...
def __hash__(self): ...
def __str__(self): ...
def __str__(self) -> str: ...
def addr_hex(self): ...
async def connect(self, timeout_ms: int = ...): ...

View File

@@ -12,7 +12,7 @@ floating-point support).
from _typeshed import Incomplete, Incomplete as Incomplete
from typing import Any, List, Optional
class array:
class array(List):
"""
Create array with elements of given type. Initial contents of the
array are given by *iterable*. If it is not provided, an empty

View File

@@ -17,7 +17,7 @@ class Stream:
def readexactly(self, n) -> Generator[Incomplete, None, Incomplete]: ...
def readline(self) -> Generator[Incomplete, None, Incomplete]: ...
def write(self, buf) -> None: ...
def drain(self) -> Generator[Incomplete, None, Incomplete]: ...
def drain(self) -> Generator[Incomplete, Incomplete, Incomplete]: ...
StreamReader = Stream
StreamWriter = Stream

View File

@@ -7,6 +7,70 @@ CPython module: :mod:`python:io` https://docs.python.org/3/library/io.html .
This module contains additional types of `stream` (file-like) objects
and helper functions.
Conceptual hierarchy
--------------------
Difference to CPython
Conceptual hierarchy of stream base classes is simplified in MicroPython,
as described in this section.
(Abstract) base stream classes, which serve as a foundation for behaviour
of all the concrete classes, adhere to few dichotomies (pair-wise
classifications) in CPython. In MicroPython, they are somewhat simplified
and made implicit to achieve higher efficiencies and save resources.
An important dichotomy in CPython is unbuffered vs buffered streams. In
MicroPython, all streams are currently unbuffered. This is because all
modern OSes, and even many RTOSes and filesystem drivers already perform
buffering on their side. Adding another layer of buffering is counter-
productive (an issue known as "bufferbloat") and takes precious memory.
Note that there still cases where buffering may be useful, so we may
introduce optional buffering support at a later time.
But in CPython, another important dichotomy is tied with "bufferedness" -
it's whether a stream may incur short read/writes or not. A short read
is when a user asks e.g. 10 bytes from a stream, but gets less, similarly
for writes. In CPython, unbuffered streams are automatically short
operation susceptible, while buffered are guarantee against them. The
no short read/writes is an important trait, as it allows to develop
more concise and efficient programs - something which is highly desirable
for MicroPython. So, while MicroPython doesn't support buffered streams,
it still provides for no-short-operations streams. Whether there will
be short operations or not depends on each particular class' needs, but
developers are strongly advised to favour no-short-operations behaviour
for the reasons stated above. For example, MicroPython sockets are
guaranteed to avoid short read/writes. Actually, at this time, there is
no example of a short-operations stream class in the core, and one would
be a port-specific class, where such a need is governed by hardware
peculiarities.
The no-short-operations behaviour gets tricky in case of non-blocking
streams, blocking vs non-blocking behaviour being another CPython dichotomy,
fully supported by MicroPython. Non-blocking streams never wait for
data either to arrive or be written - they read/write whatever possible,
or signal lack of data (or ability to write data). Clearly, this conflicts
with "no-short-operations" policy, and indeed, a case of non-blocking
buffered (and this no-short-ops) streams is convoluted in CPython - in
some places, such combination is prohibited, in some it's undefined or
just not documented, in some cases it raises verbose exceptions. The
matter is much simpler in MicroPython: non-blocking stream are important
for efficient asynchronous operations, so this property prevails on
the "no-short-ops" one. So, while blocking streams will avoid short
reads/writes whenever possible (the only case to get a short read is
if end of file is reached, or in case of error (but errors don't
return short data, but raise exceptions)), non-blocking streams may
produce short data to avoid blocking the operation.
The final dichotomy is binary vs text streams. MicroPython of course
supports these, but while in CPython text streams are inherently
buffered, they aren't in MicroPython. (Indeed, that's one of the cases
for which we may introduce buffering support.)
Note that for efficiency, MicroPython doesn't provide abstract base
classes corresponding to the hierarchy above, and it's not possible
to implement, or subclass, a stream class in pure Python.
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from stdlib.io import *

View File

@@ -983,14 +983,14 @@ class UART:
poll.poll(timeout)
"""
...
def write(self, buf) -> int:
def write(self, buf) -> Union[int, None]:
"""
Write the buffer of bytes to the bus.
Return value: number of bytes written or ``None`` on timeout.
"""
...
def readinto(self, buf, nbytes: Optional[Any] = None) -> int:
def readinto(self, buf, nbytes: Optional[Any] = None) -> Union[int, None]:
"""
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
that many bytes. Otherwise, read at most ``len(buf)`` bytes. It may return sooner if a timeout
@@ -1000,7 +1000,7 @@ class UART:
timeout.
"""
...
def readline(self) -> None:
def readline(self) -> Union[str, None]:
"""
Read a line, ending in a newline character. It may return sooner if a timeout
is reached. The timeout is configurable in the constructor.

View File

@@ -4,7 +4,7 @@ Access and control MicroPython internals.
MicroPython module: https://docs.micropython.org/en/latest/library/micropython.html
"""
# source version: v1_20_0
# source version: v1_21_0
# origin module:: repos/micropython/docs/library/micropython.rst
from typing import Any, Callable, Optional, Tuple, TypeVar, Union
@@ -98,11 +98,9 @@ def stack_use() -> int:
"""
...
def heap_lock() -> int: ...
def heap_unlock() -> int: ...
def heap_locked() -> bool:
def heap_lock() -> int:
"""
Lock or unlock the heap. When locked no memory allocation can occur and a
Lock the heap. When locked no memory allocation can occur and a
`MemoryError` will be raised if any heap allocation is attempted.
`heap_locked()` returns a true value if the heap is currently locked.
@@ -117,6 +115,40 @@ def heap_locked() -> bool:
If the REPL becomes active with the heap locked then it will be forcefully
unlocked.
Note: `heap_locked()` is not enabled on most ports by default,
requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``.
"""
...
def heap_unlock() -> int:
"""
Unlock the heap. When locked no memory allocation can occur and a
`MemoryError` will be raised if any heap allocation is attempted.
`heap_locked()` returns a true value if the heap is currently locked.
These functions can be nested, ie `heap_lock()` can be called multiple times
in a row and the lock-depth will increase, and then `heap_unlock()` must be
called the same number of times to make the heap available again.
Both `heap_unlock()` and `heap_locked()` return the current lock depth
(after unlocking for the former) as a non-negative integer, with 0 meaning
the heap is not locked.
If the REPL becomes active with the heap locked then it will be forcefully
unlocked.
Note: `heap_locked()` is not enabled on most ports by default,
requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``.
"""
...
def heap_locked() -> bool:
"""
Both `heap_unlock()` and `heap_locked()` return the current lock depth
(after unlocking for the former) as a non-negative integer, with 0 meaning
the heap is not locked.
If the REPL becomes active with the heap locked then it will be forcefully
unlocked.
Note: `heap_locked()` is not enabled on most ports by default,
requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``.
"""

View File

@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: micropython-rp2-rpi_pico_w-stubs
Version: 1.21.0.post1
Version: 1.21.0.post2
Summary: MicroPython stubs
Home-page: https://github.com/josverl/micropython-stubs#micropython-stubs
License: MIT
@@ -55,7 +55,7 @@ For an overview of Micropython Stubs please see: https://micropython-stubs.read
* List of all stubs : https://micropython-stubs.readthedocs.io/en/main/firmware_grp.html
Included stubs:
* Merged stubs from `stubs/micropython-v1_21_0-rp2-rpi_pico_w-merged`
* Merged stubs from `stubs/micropython-v1_21_0-rp2-RPI_PICO_W-merged`
* Frozen stubs from `stubs/micropython-v1_21_0-frozen/rp2/RPI_PICO_W`
* Core stubs from `stubs/micropython-core`

View File

@@ -1,26 +1,26 @@
__builtins__.pyi,sha256=SRa_5xpV_qKoNdAgXY1G1TGP59HAYvZxp-ew4M2s3dY,1068
_asyncio.pyi,sha256=oJgEZ1Axm6cN0eO1Ke7oj5YckMoicmwKfUO9vL_Y810,416
__builtins__.pyi,sha256=P0dwpsSqizQRPmaI6J275kc7G35m38YjafDPz4SEdKI,1097
_asyncio.pyi,sha256=4qCOzAujVuQ2U-NCPCPgKbR1RaCu7B8-AmaUGdbgH8w,1619
_boot.pyi,sha256=sE1k2jzwUqn1o5YjnKlavj6468D8XQNhJNJ69gVrdtg,71
_boot_fat.pyi,sha256=sE1k2jzwUqn1o5YjnKlavj6468D8XQNhJNJ69gVrdtg,71
_onewire.pyi,sha256=_BXH4KbavKcoxnFA9OF24eERDydSk7EfXlx6N2mlBw8,343
_rp2.pyi,sha256=MCGcgPRjp_mQlh3SN7TWalfzSXP6GAC2ojkCFPpSQj4,1556
_rp2.pyi,sha256=PJsr5IXFWEaEVrb-K7iR3sUBSuanTuqlF06UJ-CYHvQ,9082
_thread.pyi,sha256=8qtf48y90MbHs4wEY_eSDeZ7QP__qf5DnYSJa7r18Ps,953
aioble/__init__.pyi,sha256=Wjhrff1BWzqTqQh5pMss5q9gT51FhkzMF3tN_QV1cGc,600
aioble/central.pyi,sha256=hZmbJnu3ccyO9Z9zjd29KiW6CGTvBmsNJx2Nv1nzLzo,2448
aioble/client.pyi,sha256=KkXt3661i_eKYozYTW1BaZkZjbpOhrhfK1SBxKpC0eo,4180
aioble/central.pyi,sha256=w-WTvqKSYAvGJ80q7ObyJUpF3_0m155ZGRPQmiHWLD4,2455
aioble/client.pyi,sha256=qIAj_QJGZMlh5ndg7inxdksJ4MbI_WwnXNazZfeTDtk,4201
aioble/core.pyi,sha256=juai87amOQhoM_Vum3OTUcbkNiQVhXT3mYNyGzLLhe0,520
aioble/device.pyi,sha256=7lzYKge6yfFNWwmwyViUQgEClY6lVXWKPneR4oCtifc,2311
aioble/device.pyi,sha256=zKyWBM-2rVyPa-LbpS8uXITQKu2TN-0-R0iDFCD1oLY,2412
aioble/l2cap.pyi,sha256=k4NiXgzbvI25TqyfPbuWfu_v0KmF2dVXGtt3FuaicAs,1509
aioble/peripheral.pyi,sha256=Rz6k4Jpk-_h6r_BAXp6-rwfnPMRcNJ8KT1uhiujugwM,1425
aioble/security.pyi,sha256=-POdQrFOH67f9vtr2vbrf5U4TdZzipfx_qzRWDo6wEM,1071
aioble/server.pyi,sha256=Wd4ESEM63-A-7q3sPS3ed6Pl19j4DVh112C2WqUCaxM,3364
array.pyi,sha256=ZPtcObYk-XaI4AknOYrfMOJPXOS2ho0p35xdCgYcuVQ,1090
array.pyi,sha256=AbuS-Y4R7zO-_UFfQtsVQrwAi8J-5UkrtC_iE6kmbo4,1096
asyncio/__init__.pyi,sha256=fa4aomSb_KMbJVCimrP6IfegajK_KSN8muiH_lbqc7k,132
asyncio/core.pyi,sha256=xzNDXF3b6zq-OGz22ZPoPIJ_m5TVxgSg0YfUmG_CDzY,1530
asyncio/event.pyi,sha256=fFBZxUa_PzdiiE8I14F9IZeqg9lJgIAH8s--6SBd-9E,623
asyncio/funcs.pyi,sha256=3uEqPbVQPEqsaids5pFDkvmYUpufmkw4XuoyjwrouvI,390
asyncio/lock.pyi,sha256=QF9HAL_ayvACAPYG9Rd2kB0-WeUFYPZazG-MFFVSvtE,414
asyncio/stream.pyi,sha256=Uih1xMqHeZY4RwBQ4g-ut3_NauUjF10yxjGvh4Z3zeQ,1427
asyncio/stream.pyi,sha256=A3LKIU0m5Pk9xPIcDRQ5SbqXwy1wQNl8qu3YbdQXyzI,1433
binascii.pyi,sha256=kOai4wTFKZ1BQkyHe5WO2fkRDGST6eEetLS3KdtQ388,1488
bluetooth.pyi,sha256=eKIXx2TJHUUHtKsSL4NawmGdnp02pCLbURKMQzSPvv0,30033
cmath.pyi,sha256=Hvtu5G3iSwPeuJHZLWliHC3_g07MtMBEVErlOCRXqO0,1529
@@ -34,20 +34,20 @@ framebuf.pyi,sha256=AlWAUXju3GDe8cD5SUFMb3iz90uLkbFet0BS64eDKUg,6474
gc.pyi,sha256=rh6cpwqew57KbQm6aD92AY0cb0mSPM8KFrqxjQpLX6I,2524
hashlib.pyi,sha256=9b65Uc6P92RHUGIgf00qCHOb2KSytlkRUnSNEj8q4r8,1743
heapq.pyi,sha256=JE1S9UQ38DvuchjejRgb65S_tAYvK8CYYpQT4vEl4JA,1000
io.pyi,sha256=ltx99WnM7_72vpSIRbTiiSh9Z5D90SbCeKaNrGISsOs,2702
io.pyi,sha256=Uxc0cYGbTQ5jXrVjSFIpS3xFjb-Fi3krQcwfTgl5ZSA,6347
json.pyi,sha256=mP4C0XMgUt1ZcT7AQSteCY-n0rd0bREU_dnSQnjO5d0,1454
lwip.pyi,sha256=0vIYgPwL5EnAbcoS1U2p_8e1SgPWiIYNevZDxMrO0kk,1582
machine.pyi,sha256=HVtm4Fkv-HfqGxcE0koQVerU7acXqGkYBf8SKCKMPoM,50379
machine.pyi,sha256=iWhu0jzGHJzEF1sHTueJW0T467ogqqGcsQL-3WYYwGM,50417
math.pyi,sha256=KgjOuv3rpLNWcKWe7fVkB0PQ0Spv2VsBeE-pPhWNCWs,4827
micropython.pyi,sha256=a72FE6dfhvby6MIVPeTOPcgh46wsJUyRJr4W4TJsGKA,8423
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/LICENSE.md,sha256=EerY3Evf4ZqwZBZMGIokOHR70txtsAlS_GGHuxmxUJY,1092
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/METADATA,sha256=i_ZZ0I4ExOQn4KCrRnXpajKX5Rdco9aYtYIPJdqAcds,3225
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/RECORD,,
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
micropython_rp2_rpi_pico_w_stubs-1.21.0.post1.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
micropython.pyi,sha256=2EF95bd5sDev9NZh94vUcgpcnxZdSYp-7OQiGfRWENc,9727
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/LICENSE.md,sha256=EerY3Evf4ZqwZBZMGIokOHR70txtsAlS_GGHuxmxUJY,1092
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/METADATA,sha256=B7sbI0jwxWw2O_YEqRTHYtyvtHB1P4H2vKmN1XGcSnE,3225
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/RECORD,,
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
micropython_rp2_rpi_pico_w_stubs-1.21.0.post2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
mip/__init__.pyi,sha256=Zd0De2fcvpCue3E5iPFUmmXdpf_IeciR9Pty29Id_fk,598
neopixel.pyi,sha256=jOhE-kR8bRy0dEwqFLLY3Z7v7dp0n2XFwXTCwty0TuY,448
neopixel.pyi,sha256=4mz5RYvFk0E9D8MP0VhIFRQP1ZOri8Xvtnqb29q9kc4,1800
network.pyi,sha256=OQjwBgmxsx5ICq3GCOL3vzqIfUBb4X_gUTEPJ9PWIQQ,7633
ntptime.pyi,sha256=CmHJaGQFWjMig6JCTnWF0tY0KIw6jFWN362TnJWaWZQ,72
onewire.pyi,sha256=DgLSo0kBX1ox2Qm0x76XY00m2x17GM0uh8J4GWU1Tgs,617
@@ -56,15 +56,15 @@ platform.pyi,sha256=3xuJleRh1wBIkS51WeiUkfQtwgYK1CLjDqXteBQIWaY,1463
random.pyi,sha256=GDIgpkmplAsckapDEHlkkRdsRq8fCS_hBBRCS5gFmZI,2687
requests.pyi,sha256=Mk3u-Y3RUz3YXbe8bkC5gzNE12dF8Z7SGEp0-lhckLQ,609
requests/__init__.pyi,sha256=yNYrzq9TMRID3tAXLhHRRdzaiku2o6OfjDXjaF2bhYA,739
rp2.pyi,sha256=ghYwOcTINmxwfGdaL3tE1z5soZvskgoBbjvSLiuOb2E,1918
rp2.pyi,sha256=qmNBOTNQvr9LZsxCWfKZoTiGGRz91tvh6uy9n1sr2rU,4362
select.pyi,sha256=LKJ75d0F4BJg_7VAH3L07H1qqG3IkLuVEc82j-xMFWM,4114
socket.pyi,sha256=YUTOaiosablCnk-corhGdTRNpQScrllJxdw9pZyWrYo,11622
socket.pyi,sha256=Cr4ZO_8GCrnMKhvRUNO68TnpR1Hux48d9dE6JZIvLVU,13869
ssl.pyi,sha256=u94PkXN_NoaRnj2bBdMFq2x7JUHVmjeJcA8tvL1wMyI,3758
struct.pyi,sha256=4Mf6SQIchLMnVNPnFG-iNgeIqqpaAYx89xvz1FAKJQA,4316
sys.pyi,sha256=aL8EhWS78hy24Ir-y4QWB6QYdj5hYVooEiNQZ-MxMK0,1442
time.pyi,sha256=Df5LIT2n7WwXRXjLKBlqQ7g0ZHsQe1mnkTdyKyAtYno,13313
uarray.pyi,sha256=ZPtcObYk-XaI4AknOYrfMOJPXOS2ho0p35xdCgYcuVQ,1090
uasyncio.pyi,sha256=eu4a7KxASOh_jGsRn7zmGtUt2rJYtOpjVuGYB4ty4fc,28
uarray.pyi,sha256=AbuS-Y4R7zO-_UFfQtsVQrwAi8J-5UkrtC_iE6kmbo4,1096
uasyncio.pyi,sha256=NLrXIdFG43A4WJJ69TN81mfH8aI0IIVY_SFF--I6WyY,924
uasyncio/__init__.pyi,sha256=bmpai6ZIJXDZ00aZz11BZZ92VGbfdQwqUL1jmUz3ZHU,2015
uasyncio/core.pyi,sha256=6mmEJjdYJhiYRHY4c4Hs47AYuY2zEq_ZJXitr4XSlR8,1029
uasyncio/event.pyi,sha256=OGzLIKk8AkbwIMK5l5CPy4QZTNc0uFQJzUftEgeUOzQ,580
@@ -79,16 +79,16 @@ uctypes.pyi,sha256=tUGuvBHmFbcLBOZCHZ--OKBe6dZdee-8B8ALYbTuV2Q,2417
uerrno.pyi,sha256=fT9TQhrfWRbRou7wVcyJQWPysPh372koMw_GNZCC7SU,777
uhashlib.pyi,sha256=9b65Uc6P92RHUGIgf00qCHOb2KSytlkRUnSNEj8q4r8,1743
uheapq.pyi,sha256=JE1S9UQ38DvuchjejRgb65S_tAYvK8CYYpQT4vEl4JA,1000
uio.pyi,sha256=ltx99WnM7_72vpSIRbTiiSh9Z5D90SbCeKaNrGISsOs,2702
uio.pyi,sha256=Uxc0cYGbTQ5jXrVjSFIpS3xFjb-Fi3krQcwfTgl5ZSA,6347
ujson.pyi,sha256=mP4C0XMgUt1ZcT7AQSteCY-n0rd0bREU_dnSQnjO5d0,1454
umachine.pyi,sha256=HVtm4Fkv-HfqGxcE0koQVerU7acXqGkYBf8SKCKMPoM,50379
umachine.pyi,sha256=iWhu0jzGHJzEF1sHTueJW0T467ogqqGcsQL-3WYYwGM,50417
uos.pyi,sha256=BNYJHi5PymNeepTYUD27GoUDmXWrAreN3bIiU8-sB64,9677
uplatform.pyi,sha256=3xuJleRh1wBIkS51WeiUkfQtwgYK1CLjDqXteBQIWaY,1463
urandom.pyi,sha256=GDIgpkmplAsckapDEHlkkRdsRq8fCS_hBBRCS5gFmZI,2687
ure.pyi,sha256=bLeXSxERwfWOsjH_TCaRE4bcguKddfOgSAf2Bw9Fu7o,239
urequests.pyi,sha256=eu4a7KxASOh_jGsRn7zmGtUt2rJYtOpjVuGYB4ty4fc,28
uselect.pyi,sha256=LKJ75d0F4BJg_7VAH3L07H1qqG3IkLuVEc82j-xMFWM,4114
usocket.pyi,sha256=YUTOaiosablCnk-corhGdTRNpQScrllJxdw9pZyWrYo,11622
usocket.pyi,sha256=Cr4ZO_8GCrnMKhvRUNO68TnpR1Hux48d9dE6JZIvLVU,13869
ussl.pyi,sha256=u94PkXN_NoaRnj2bBdMFq2x7JUHVmjeJcA8tvL1wMyI,3758
ustruct.pyi,sha256=4Mf6SQIchLMnVNPnFG-iNgeIqqpaAYx89xvz1FAKJQA,4316
usys.pyi,sha256=aL8EhWS78hy24Ir-y4QWB6QYdj5hYVooEiNQZ-MxMK0,1442

View File

@@ -1,15 +1,58 @@
"""
Control of WS2812 / NeoPixel LEDs.
MicroPython module: https://docs.micropython.org/en/v1.21.0/library/neopixel.html
This module provides a driver for WS2818 / NeoPixel LEDs.
``Note:`` This module is only included by default on the ESP8266, ESP32 and RP2
ports. On STM32 / Pyboard and others, you can either install the
``neopixel`` package using :term:`mip`, or you can download the module
directly from :term:`micropython-lib` and copy it to the filesystem.
"""
from _typeshed import Incomplete
from typing import Tuple
class NeoPixel:
"""
Construct an NeoPixel object. The parameters are:
- *pin* is a machine.Pin instance.
- *n* is the number of LEDs in the strip.
- *bpp* is 3 for RGB LEDs, and 4 for RGBW LEDs.
- *timing* is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz).
"""
ORDER: Incomplete
pin: Incomplete
n: Incomplete
bpp: Incomplete
buf: Incomplete
timing: Incomplete
def __init__(self, pin, n, bpp: int = ..., timing: int = ...) -> None: ...
def __len__(self) -> int: ...
def __setitem__(self, i, v) -> None: ...
def __getitem__(self, i): ...
def fill(self, v) -> None: ...
def write(self) -> None: ...
def __init__(self, pin, n, *, bpp=3, timing=1) -> None: ...
def __len__(self) -> int:
"""
Returns the number of LEDs in the strip.
"""
...
def __setitem__(self, index, val) -> None:
"""
Set the pixel at *index* to the value, which is an RGB/RGBW tuple.
"""
...
def __getitem__(self, index) -> Tuple:
"""
Returns the pixel at *index* as an RGB/RGBW tuple.
"""
...
def fill(self, pixel) -> None:
"""
Sets the value of all pixels to the specified *pixel* value (i.e. an
RGB/RGBW tuple).
"""
...
def write(self) -> None:
"""
Writes the current pixel data to the strip.
"""
...

View File

@@ -1,3 +1,17 @@
"""
Functionality specific to the RP2.
MicroPython module: https://docs.micropython.org/en/v1.21.0/library/rp2.html
The ``rp2`` module contains functions and classes specific to the RP2040, as
used in the Raspberry Pi Pico.
See the `RP2040 Python datasheet
<https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf>`_
for more information, and `pico-micropython-examples
<https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio>`_
for example code.
"""
from _rp2 import *
from _typeshed import Incomplete
@@ -58,5 +72,61 @@ class PIOASMEmit:
_pio_funcs: Incomplete
def asm_pio(**kw): ...
def asm_pio_encode(instr, sideset_count, sideset_opt: bool = ...): ...
def asm_pio(
*,
out_init=None,
set_init=None,
sideset_init=None,
in_shiftdir=0,
out_shiftdir=0,
autopush=False,
autopull=False,
push_thresh=32,
pull_thresh=32,
fifo_join=PIO.JOIN_NONE,
) -> Incomplete:
"""
Assemble a PIO program.
The following parameters control the initial state of the GPIO pins, as one
of `PIO.IN_LOW`, `PIO.IN_HIGH`, `PIO.OUT_LOW` or `PIO.OUT_HIGH`. If the
program uses more than one pin, provide a tuple, e.g.
``out_init=(PIO.OUT_LOW, PIO.OUT_LOW)``.
- *out_init* configures the pins used for ``out()`` instructions.
- *set_init* configures the pins used for ``set()`` instructions. There can
be at most 5.
- *sideset_init* configures the pins used side-setting. There can be at
most 5.
The following parameters are used by default, but can be overridden in
`StateMachine.init()`:
- *in_shiftdir* is the default direction the ISR will shift, either
`PIO.SHIFT_LEFT` or `PIO.SHIFT_RIGHT`.
- *out_shiftdir* is the default direction the OSR will shift, either
`PIO.SHIFT_LEFT` or `PIO.SHIFT_RIGHT`.
- *push_thresh* is the threshold in bits before auto-push or conditional
re-pushing is triggered.
- *pull_thresh* is the threshold in bits before auto-pull or conditional
re-pulling is triggered.
The remaining parameters are:
- *autopush* configures whether auto-push is enabled.
- *autopull* configures whether auto-pull is enabled.
- *fifo_join* configures whether the 4-word TX and RX FIFOs should be
combined into a single 8-word FIFO for one direction only. The options
are `PIO.JOIN_NONE`, `PIO.JOIN_RX` and `PIO.JOIN_TX`.
"""
...
def asm_pio_encode(instr, sideset_count, sideset_opt=False) -> Incomplete:
"""
Assemble a single PIO instruction. You usually want to use `asm_pio()`
instead.
>>> rp2.asm_pio_encode("set(0, 1)", 0)
57345
"""
...

View File

@@ -14,6 +14,51 @@ Difference to CPython
a file-like object using `makefile()` method. This method is still supported
by MicroPython (but is a no-op), so where compatibility with CPython matters,
be sure to use it.
Socket address format(s)
------------------------
The native socket address format of the ``socket`` module is an opaque data type
returned by `getaddrinfo` function, which must be used to resolve textual address
(including numeric addresses)::
sockaddr = socket.getaddrinfo('www.micropython.org', 80)[0][-1]
# You must use getaddrinfo() even for numeric addresses
sockaddr = socket.getaddrinfo('127.0.0.1', 80)[0][-1]
# Now you can use that address
sock.connect(sockaddr)
Using `getaddrinfo` is the most efficient (both in terms of memory and processing
power) and portable way to work with addresses.
However, ``socket`` module (note the difference with native MicroPython
``socket`` module described here) provides CPython-compatible way to specify
addresses using tuples, as described below. Note that depending on a
:term:`MicroPython port`, ``socket`` module can be builtin or need to be
installed from `micropython-lib` (as in the case of :term:`MicroPython Unix port`),
and some ports still accept only numeric addresses in the tuple format,
and require to use `getaddrinfo` function to resolve domain names.
Summing up:
* Always use `getaddrinfo` when writing portable applications.
* Tuple addresses described below can be used as a shortcut for
quick hacks and interactive use, if your port supports them.
Tuple address format for ``socket`` module:
* IPv4: *(ipv4_address, port)*, where *ipv4_address* is a string with
dot-notation numeric IPv4 address, e.g. ``"8.8.8.8"``, and *port* is and
integer port number in the range 1-65535. Note the domain names are not
accepted as *ipv4_address*, they should be resolved first using
`socket.getaddrinfo()`.
* IPv6: *(ipv6_address, port, flowinfo, scopeid)*, where *ipv6_address*
is a string with colon-notation numeric IPv6 address, e.g. ``"2001:db8::1"``,
and *port* is an integer port number in the range 1-65535. *flowinfo*
must be 0. *scopeid* is the interface scope identifier for link-local
addresses. Note the domain names are not accepted as *ipv6_address*,
they should be resolved first using `socket.getaddrinfo()`. Availability
of IPv6 support depends on a :term:`MicroPython port`.
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from stdlib.socket import *

View File

@@ -12,7 +12,7 @@ floating-point support).
from _typeshed import Incomplete, Incomplete as Incomplete
from typing import Any, List, Optional
class array:
class array(List):
"""
Create array with elements of given type. Initial contents of the
array are given by *iterable*. If it is not provided, an empty

View File

@@ -1 +1,38 @@
"""
Asynchronous I/O scheduler for writing concurrent code.
MicroPython module: https://docs.micropython.org/en/v1.21.0/library/asyncio.html
CPython module:
`asyncio `<https://docs.python.org/3.8/library/asyncio.html>
Example::
import asyncio
async def blink(led, period_ms):
while True:
led.on()
await asyncio.sleep_ms(5)
led.off()
await asyncio.sleep_ms(period_ms)
async def main(led1, led2):
asyncio.create_task(blink(led1, 700))
asyncio.create_task(blink(led2, 400))
await asyncio.sleep_ms(10_000)
# Running on a pyboard
from pyb import LED
asyncio.run(main(LED(1), LED(2)))
# Running on a generic board
from machine import Pin
asyncio.run(main(Pin(1), Pin(2)))
Core functions
--------------
"""
from _typeshed import Incomplete
def __getattr__(attr): ...

View File

@@ -7,6 +7,70 @@ CPython module: :mod:`python:io` https://docs.python.org/3/library/io.html .
This module contains additional types of `stream` (file-like) objects
and helper functions.
Conceptual hierarchy
--------------------
Difference to CPython
Conceptual hierarchy of stream base classes is simplified in MicroPython,
as described in this section.
(Abstract) base stream classes, which serve as a foundation for behaviour
of all the concrete classes, adhere to few dichotomies (pair-wise
classifications) in CPython. In MicroPython, they are somewhat simplified
and made implicit to achieve higher efficiencies and save resources.
An important dichotomy in CPython is unbuffered vs buffered streams. In
MicroPython, all streams are currently unbuffered. This is because all
modern OSes, and even many RTOSes and filesystem drivers already perform
buffering on their side. Adding another layer of buffering is counter-
productive (an issue known as "bufferbloat") and takes precious memory.
Note that there still cases where buffering may be useful, so we may
introduce optional buffering support at a later time.
But in CPython, another important dichotomy is tied with "bufferedness" -
it's whether a stream may incur short read/writes or not. A short read
is when a user asks e.g. 10 bytes from a stream, but gets less, similarly
for writes. In CPython, unbuffered streams are automatically short
operation susceptible, while buffered are guarantee against them. The
no short read/writes is an important trait, as it allows to develop
more concise and efficient programs - something which is highly desirable
for MicroPython. So, while MicroPython doesn't support buffered streams,
it still provides for no-short-operations streams. Whether there will
be short operations or not depends on each particular class' needs, but
developers are strongly advised to favour no-short-operations behaviour
for the reasons stated above. For example, MicroPython sockets are
guaranteed to avoid short read/writes. Actually, at this time, there is
no example of a short-operations stream class in the core, and one would
be a port-specific class, where such a need is governed by hardware
peculiarities.
The no-short-operations behaviour gets tricky in case of non-blocking
streams, blocking vs non-blocking behaviour being another CPython dichotomy,
fully supported by MicroPython. Non-blocking streams never wait for
data either to arrive or be written - they read/write whatever possible,
or signal lack of data (or ability to write data). Clearly, this conflicts
with "no-short-operations" policy, and indeed, a case of non-blocking
buffered (and this no-short-ops) streams is convoluted in CPython - in
some places, such combination is prohibited, in some it's undefined or
just not documented, in some cases it raises verbose exceptions. The
matter is much simpler in MicroPython: non-blocking stream are important
for efficient asynchronous operations, so this property prevails on
the "no-short-ops" one. So, while blocking streams will avoid short
reads/writes whenever possible (the only case to get a short read is
if end of file is reached, or in case of error (but errors don't
return short data, but raise exceptions)), non-blocking streams may
produce short data to avoid blocking the operation.
The final dichotomy is binary vs text streams. MicroPython of course
supports these, but while in CPython text streams are inherently
buffered, they aren't in MicroPython. (Indeed, that's one of the cases
for which we may introduce buffering support.)
Note that for efficiency, MicroPython doesn't provide abstract base
classes corresponding to the hierarchy above, and it's not possible
to implement, or subclass, a stream class in pure Python.
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from stdlib.io import *

View File

@@ -983,14 +983,14 @@ class UART:
poll.poll(timeout)
"""
...
def write(self, buf) -> int:
def write(self, buf) -> Union[int, None]:
"""
Write the buffer of bytes to the bus.
Return value: number of bytes written or ``None`` on timeout.
"""
...
def readinto(self, buf, nbytes: Optional[Any] = None) -> int:
def readinto(self, buf, nbytes: Optional[Any] = None) -> Union[int, None]:
"""
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
that many bytes. Otherwise, read at most ``len(buf)`` bytes. It may return sooner if a timeout
@@ -1000,7 +1000,7 @@ class UART:
timeout.
"""
...
def readline(self) -> None:
def readline(self) -> Union[str, None]:
"""
Read a line, ending in a newline character. It may return sooner if a timeout
is reached. The timeout is configurable in the constructor.

View File

@@ -14,6 +14,51 @@ Difference to CPython
a file-like object using `makefile()` method. This method is still supported
by MicroPython (but is a no-op), so where compatibility with CPython matters,
be sure to use it.
Socket address format(s)
------------------------
The native socket address format of the ``socket`` module is an opaque data type
returned by `getaddrinfo` function, which must be used to resolve textual address
(including numeric addresses)::
sockaddr = socket.getaddrinfo('www.micropython.org', 80)[0][-1]
# You must use getaddrinfo() even for numeric addresses
sockaddr = socket.getaddrinfo('127.0.0.1', 80)[0][-1]
# Now you can use that address
sock.connect(sockaddr)
Using `getaddrinfo` is the most efficient (both in terms of memory and processing
power) and portable way to work with addresses.
However, ``socket`` module (note the difference with native MicroPython
``socket`` module described here) provides CPython-compatible way to specify
addresses using tuples, as described below. Note that depending on a
:term:`MicroPython port`, ``socket`` module can be builtin or need to be
installed from `micropython-lib` (as in the case of :term:`MicroPython Unix port`),
and some ports still accept only numeric addresses in the tuple format,
and require to use `getaddrinfo` function to resolve domain names.
Summing up:
* Always use `getaddrinfo` when writing portable applications.
* Tuple addresses described below can be used as a shortcut for
quick hacks and interactive use, if your port supports them.
Tuple address format for ``socket`` module:
* IPv4: *(ipv4_address, port)*, where *ipv4_address* is a string with
dot-notation numeric IPv4 address, e.g. ``"8.8.8.8"``, and *port* is and
integer port number in the range 1-65535. Note the domain names are not
accepted as *ipv4_address*, they should be resolved first using
`socket.getaddrinfo()`.
* IPv6: *(ipv6_address, port, flowinfo, scopeid)*, where *ipv6_address*
is a string with colon-notation numeric IPv6 address, e.g. ``"2001:db8::1"``,
and *port* is an integer port number in the range 1-65535. *flowinfo*
must be 0. *scopeid* is the interface scope identifier for link-local
addresses. Note the domain names are not accepted as *ipv6_address*,
they should be resolved first using `socket.getaddrinfo()`. Availability
of IPv6 support depends on a :term:`MicroPython port`.
"""
from _typeshed import Incomplete, Incomplete as Incomplete
from stdlib.socket import *

View File

@@ -9,8 +9,11 @@
".vscode\\Pico-W-Stub"
],
"python.analysis.extraPaths": [
".vscode\\Pico-W-Stub"
"",
"c:\\Users\\adakovacs\\.vscode\\extensions\\joedevivo.vscode-circuitpython-0.1.20-win32-x64\\stubs",
"c:\\Users\\adakovacs\\AppData\\Roaming\\Code\\User\\globalStorage\\joedevivo.vscode-circuitpython\\bundle\\20231207\\adafruit-circuitpython-bundle-py-20231207\\lib"
],
"micropico.syncFolder": "",
"micropico.openOnStart": true
"micropico.openOnStart": true,
"circuitpython.board.version": null
}

72
main.py
View File

@@ -180,44 +180,44 @@ try:
"}",
'application/json')
elif request.find('/prometheus') == GET_PATH_START:
elif request.find('/metrics') == GET_PATH_START:
attrs = "{mac=\"""" + mac_readable + "\",ip=\""+ ip +"\"} "
content = (
"""# HELP temperature Temperature in Celsius
# TYPE temperature gauge
temperature""" + attrs + with_fallback_to_str(temp_mcp9808, "NaN") +
"""
# HELP humidity Relative humidity in %
# TYPE humidity gauge
humidity""" + attrs + with_fallback_to_str(humidity_sht4x, "NaN") +
"""
# HELP pressure Pressure in Pa
# TYPE pressure gauge
pressure""" + attrs + with_fallback_to_str(pressure_bmp390, "NaN") +
"""
# HELP temp_mcp9808 Temperature in Celsius
# TYPE temp_mcp9808 gauge
temp_mcp9808""" + attrs + with_fallback_to_str(temp_mcp9808, "NaN") +
"""
# HELP humidity_sht4x Relative humidity in %
# TYPE humidity_sht4x gauge
humidity_sht4x""" + attrs + with_fallback_to_str(humidity_sht4x, "NaN") +
"""
# HELP temp_sht4x Temperature in Celsius
# TYPE temp_sht4x gauge
temp_sht4x""" + attrs + with_fallback_to_str(temp_sht4x, "NaN") +
"""
# HELP bmp390_temp Temperature in Celsius
# TYPE bmp390_temp gauge
bmp390_temp""" + attrs + with_fallback_to_str(temp_bmp390, "NaN") +
"""
# HELP bmp390_pressure Pressure in Pa
# TYPE bmp390_pressure gauge
bmp390_pressure""" + attrs + with_fallback_to_str(pressure_bmp390, "NaN") +
"""
# HELP bmp390_time Time in ms
# TYPE bmp390_time gauge
bmp390_time""" + attrs + with_fallback_to_str(time_bmp390, "NaN"))
"""# HELP temperature Temperature in Celsius
# TYPE temperature gauge
temperature""" + attrs + with_fallback_to_str(temp_mcp9808, "NaN") +
"""
# HELP humidity Relative humidity in %
# TYPE humidity gauge
humidity""" + attrs + with_fallback_to_str(humidity_sht4x, "NaN") +
"""
# HELP pressure Pressure in Pa
# TYPE pressure gauge
pressure""" + attrs + with_fallback_to_str(pressure_bmp390, "NaN") +
"""
# HELP temp_mcp9808 Temperature in Celsius
# TYPE temp_mcp9808 gauge
temp_mcp9808""" + attrs + with_fallback_to_str(temp_mcp9808, "NaN") +
"""
# HELP humidity_sht4x Relative humidity in %
# TYPE humidity_sht4x gauge
humidity_sht4x""" + attrs + with_fallback_to_str(humidity_sht4x, "NaN") +
"""
# HELP temp_sht4x Temperature in Celsius
# TYPE temp_sht4x gauge
temp_sht4x""" + attrs + with_fallback_to_str(temp_sht4x, "NaN") +
"""
# HELP bmp390_temp Temperature in Celsius
# TYPE bmp390_temp gauge
bmp390_temp""" + attrs + with_fallback_to_str(temp_bmp390, "NaN") +
"""
# HELP bmp390_pressure Pressure in Pa
# TYPE bmp390_pressure gauge
bmp390_pressure""" + attrs + with_fallback_to_str(pressure_bmp390, "NaN") +
"""
# HELP bmp390_time Time in ms
# TYPE bmp390_time gauge
bmp390_time""" + attrs + with_fallback_to_str(time_bmp390, "NaN"))
result_ok(cl, content)
else:
result_notfound(cl)