Also optimise both `isgenerator()` and `isgeneratorfunction()` so they use
the same lambda, and don't have to create it each time they are called.
Fixes issue #997.
Signed-off-by: Damien George <damien@micropython.org>
This commit will make it possible to add headers to a Websocket.
Among other things, this allows making a connection to online MQTT brokers
over websocket, using the header entry "Sec-WebSocket-Protocol":"mqtt" in
the handshake of the upgrade protocol.
Signed-off-by: Damien George <damien@micropython.org>
According to RFC https://datatracker.ietf.org/doc/html/rfc7230#section-3.2
header names are case-insensitive.
This commit makes sure that the module behaves consistently regardless of
the casing of "Content-type" and "Content-Length" (other headers are not
considered by the module).
Without this fix, the client seems to wait for the connection termination
(~10 seconds) prior to returning any content if the casing of
"Content-Length" is different.
Signed-off-by: FuNK3Y <fun__key@hotmail.com>
The host in headers extracted from the original url may not be the same as
the host in the redirect url. Poping out the host in headers force the
code to use the host in the redirect url, otherwise the redirect may fail
due to inconsistence of hosts in the original url and the redirect url.
Signed-off-by: 黃昕暐 <meebox@gmail.com>
Newer implementations of libc integrate the functions from librt, for
example glibc since 2.17 and uClibc-ng. So if the librt.so cannot be
loaded, it can be assumed that libc contains the expected functions.
Signed-off-by: Bas van Doren <basvdoren@gmail.com>
This commit fixes a typo and changes a tuple that needs to be mutable to a
list (because other parts of the code change elements of this list).
Signed-off-by: Damien George <damien@micropython.org>
The value of the STATUS register is always transmitted by the chip when
reading any command. So a R_REGISTER command and the turnaround time can
be spared by issuing a NOP command instead.
This implementation suggested by the datasheet.
This operation is compatible with both nRF24L01 and nRF24L01+.
Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
The timeout condition was not handled before. Upon timeout, this caused
the chip to stay active until another send command changed it's state.
Sometimes when it was unable to transmit the data, it got stuck in the tx
fifo causing it to fill up over time, which set the TX_FULL flag in the
STATUS register.
Since there was no exceptions raised, the user code could not differentiate
a successful send or a timeout condition.
Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
According to the datasheet of the NRF240L1 chip, 150 μs startup time is
only acceptable when the chip is clocked externally. Most modules use a
crystal, which require 1.5 ms to settle. It should be okay to wait more in
both cases, for a reliable startup.
Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
Commit 35d41dbb0e changed the API for using
SSL with umqtt, but only did a minor version increase. This broke various
uses of this library, eg
https://github.com/aws-samples/aws-iot-core-getting-started-micropython
Reinstate the original API for specifying an SSL connection. This library
now supports the following:
- default, ssl=None or ssl=False: no SSL
- ssl=True and optional ssl_params specified: use ssl.wrap_socket
- ssl=<SSLContext instance>: use provided SSL context to wrap socket
Signed-off-by: Damien George <damien@micropython.org>
If a ROMFS is mounted then "/rom/lib" is usually in `sys.path` before the
writable filesystem's "lib" entry. The ROMFS directory cannot be installed
to, so skip it if found.
Signed-off-by: Damien George <damien@micropython.org>
This allows to specify relative URLs in package.json, which are resolved
relative to the package.json URL. This mirrors the functionality added to
mpremote in https://github.com/micropython/micropython/pull/12477.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
The requests() function takes a headers dict argument
(call-by-reference). This object is then modified in the function. For
instance the host is added and authentication information. Such behavior
is not expected. It is also problematic:
- Modifications of the header dictionary will be visible on the caller
site.
- When reusing the same (supposedly read-only) headers object for
differenct calls, the second call will apparently re-use wrong headers
from the previous call and may fail.
This patch should also fix#839. Unfortunately the copy operation does
not preserve the key order and we have to touch the existing test cases.
Signed-off-by: Richard Weickelt <richard@weickelt.de>
So this code can be compiled with the MicroPython native emitter, which
does not support "raise" without any arguments.
Signed-off-by: Damien George <damien@micropython.org>
If there are any network issues, mqtt will block on the socket
non-deterministically. This commit introduces a `timeout` option which
can be used to set a finite timeout on the socket. Upon any issue, mqtth
lib will throw exception.
This allows the following arguments to be passed to `device.connect()`:
* scan_duration_ms
* min_conn_interval_us
* max_conn_interval_us
These are passed as-is to `gap_connect()`. The default value for all of
these is `None`, which causes gap_connect to use its own defaults.
Signed-off-by: Joris van der Wel <joris@jorisvanderwel.com>
To use this feature you need to create a usb device signaling remote wakeup
and then enable remote wakeup on the host (on linux write enabled to
/sys/bus/usb/devices/<device>/power/wakeup). Then you can wake up the host
when is on standby using USBDevice.remote_wakeup.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
This base64 library only uses `struct.unpack` which is available in the
built-in `struct` module, so no need for the micropython-lib extras.
Signed-off-by: Damien George <damien@micropython.org>
This is to replace a commit which added locking here but caused some other
problems. The idea behind the Buffer class is that a single producer can
call pend_write() more than once and it's idempotent, however this is very
complex to extend across multiple threads.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The USB pending transfer flag was cleared before calling the completion
callback, to allow the callback code to call submit_xfer() again.
Unfortunately this isn't safe in a multi-threaded environment, as another
thread may see the endpoint is available before the callback is done
executing and submit a new transfer.
Rather than adding extra locking, specifically treat the transfer as still
pending if checked from another thread while the callback is executing.
Closes#874
Signed-off-by: Angus Gratton <angus@redyak.com.au>
It looks like this example file was not added to the original commit back
in 6190cec14a.
Fixes issue #320.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
I hadn't used this feature for a while, and realised there's one confusing
element of it not previously mentioned in the docs.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
To increase the similarity between this module and CPythons sqlite3 module
the commit() and rollback() as defined in CPythons version have been
added, along with the different (auto)commit behaviors present there.
The defaults are also set to the same as in CPython, and can be changed
with the same parameters in connect(), as is showcased in the new test.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
The sqlite3_prepare and sqlite3_close have been changed to use the v2
version. For the prepare this was done as the v1 version is "legacy",
and for close the documentation describes the v2 version to be used for
"host languages that are garbage collected, and where the order in
which destructors are called is arbitrary", which fits here.
Some clean-up to comments has also be done, and the tests now also
close the Cursor and Connections.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
This commit adds the ability to enable URI on the connect, as can be done
in the cpython sqlite3 module. URI allows, among other things, to create
a shared named in-memory database, which non URI filenames cannot create.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
Currently, statements are only finalized upon a call to Cursor.close().
However, in Cursor.execute() new statements get created without the
previous statements being finalized, causing those to get leaked,
preventing the database from being closed. The fix addresses this by
finalizing the previous statement if it exists.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
Currently, the bytes object used to store the sqlite3 database pointer
is always 4 bytes, which causes segfaults on 64 bit platforms with 8
byte pointers. To address this, the size is now dynamically determined
using the uctypes modules pointer size.
Signed-off-by: Robert Klink <rhermanklink@ripe.net>
This points to the package's base directory of the within the
micropython-lib directory structure.
Signed-off-by: Damien George <damien@micropython.org>
Currently, the LoRa SX126x driver dynamically creates at least one,
sometimes two, memoryview objects with each call to `_cmd`. This commit
simply provides the class with a long-lived memoryview object for `_cmd` to
easily slice as necessary.
Unlike the SX127x chips, Semtech unfortunately designed the SX126x modems
to be more command-centric (as opposed to directly setting registers).
Given the amount `_cmd` is called during normal device operation, even a
minor improvement here should have a decent impact.
Basic TX and RX tests pass on hardware.
Signed-off-by: Max Holliday <maholli@stanford.edu>
If the CDC receive buffer was full and some code read less than 64 bytes
(wMaxTransferSize), the CDC code would submit an OUT transfer with N<64
bytes length to fill the buffer back up.
However if the host had more than N bytes to send then it would still send
the full 64 bytes (correctly) in the transfer. The remaining (64-N) bytes
would be lost.
Adds the restriction that CDCInterface rxbuf has to be at least 64 bytes.
Fixes issue #885.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
When running tests from subfolders, import by "full dotted path" rather
than just module name, removing the need to add the test parent folder to
`sys.path`.
This matches CPython more closely, which places `abspath(top)` at the start
of `sys.path` but doesn't include the test file parent dir at all.
It fixes issues where projects may include a `test_xxx.py` file in their
distribution which would (prior to this change) be unintentionally found by
unittest-discover.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>