GitBook: [master] 45 pages modified

This commit is contained in:
Daniel Spindelbauer
2018-08-21 06:05:15 +00:00
committed by gitbook-bot
parent f893111ff5
commit 35e1c304f6
45 changed files with 372 additions and 364 deletions

View File

@@ -21,7 +21,7 @@ ubinascii.hexlify(b'12345') # Script will not return any the console
In order to use these functions that do not print out any values, you will need to either wrap them in a `print()` statement or assign them to variables and call them later when you wish to use them.
### For example:
For example:
```python
# immediately print to console when using a script

View File

@@ -6,17 +6,17 @@ Supported format codes: `b, B, h, H, i, I, l, L, q, Q, f, d` \(the latter 2 depe
## Classes
### class array.array\(typecode\[, iterable\]\)
#### class array.array\(typecode\[, iterable\]\)
Create array with elements of given type. Initial contents of the array are given by an iterable. If it is not provided, an empty array is created.
## Methods
### array.append\(val\)
#### array.append\(val\)
Append new element to the end of array, growing it.
### array.extend\(iterable\)
#### array.extend\(iterable\)
Append new elements as contained in an iterable to the end of array, growing it.

View File

@@ -4,39 +4,39 @@ The `cmath` module provides some basic mathematical functions for working with c
## Methods
### cmath.cos\(z\)
#### cmath.cos\(z\)
Return the cosine of `z`.
### cmath.exp\(z\)
#### cmath.exp\(z\)
Return the exponential of `z`.
### cmath.log\(z\)
#### cmath.log\(z\)
Return the natural logarithm of `z`. The branch cut is along the negative real axis.
### cmath.log10\(z\)
#### cmath.log10\(z\)
Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
### cmath.phase\(z\)
#### cmath.phase\(z\)
Returns the phase of the number `z`, in the range \(-pi, +pi\).
### cmath.polar\(z\)
#### cmath.polar\(z\)
Returns, as a tuple, the polar form of `z`.
### cmath.rect\(r, phi\)
#### cmath.rect\(r, phi\)
Returns the complex number with modulus `r` and phase `phi`.
### cmath.sin\(z\)
#### cmath.sin\(z\)
Return the sine of `z`.
### cmath.sqrt\(z\)
#### cmath.sqrt\(z\)
Return the square-root of `z`.

View File

@@ -2,23 +2,23 @@
## Methods
### gc.enable\(\)
#### gc.enable\(\)
Enable automatic garbage collection.
### gc.disable\(\)
#### gc.disable\(\)
Disable automatic garbage collection. Heap memory can still be allocated, and garbage collection can still be initiated manually using `gc.collect()`.
### gc.collect\(\)
#### gc.collect\(\)
Run a garbage collection.
### gc.mem\_alloc\(\)
#### gc.mem\_alloc\(\)
Return the number of bytes of heap RAM that are allocated.
### gc.mem\_free\(\)
#### gc.mem\_free\(\)
Return the number of bytes of available heap RAM.

View File

@@ -4,155 +4,155 @@ The math module provides some basic mathematical functions for working with floa
## Methods
### math.acos\(x\)
#### math.acos\(x\)
Return the inverse cosine of `x`.
### math.acosh\(x\)
#### math.acosh\(x\)
Return the inverse hyperbolic cosine of `x`.
### math.asin\(x\)
#### math.asin\(x\)
Return the inverse sine of `x`.
### math.asinh\(x\)
#### math.asinh\(x\)
Return the inverse hyperbolic sine of `x`.
### math.atan\(x\)
#### math.atan\(x\)
Return the inverse tangent of `x`.
### math.atan2\(y, x\)
#### math.atan2\(y, x\)
Return the principal value of the inverse tangent of `y/x`.
### math.atanh\(x\)
#### math.atanh\(x\)
Return the inverse hyperbolic tangent of `x`.
### math.ceil\(x\)
#### math.ceil\(x\)
Return an integer, being x rounded towards positive infinity.
### math.copysign\(x, y\)
#### math.copysign\(x, y\)
Return x with the sign of `y`.
### math.cos\(x\)
#### math.cos\(x\)
Return the cosine of `x`.
### math.cosh\(x\)
#### math.cosh\(x\)
Return the hyperbolic cosine of `x`.
### math.degrees\(x\)
#### math.degrees\(x\)
Return radians `x` converted to degrees.
### math.erf\(x\)
#### math.erf\(x\)
Return the error function of `x`.
### math.erfc\(x\)
#### math.erfc\(x\)
Return the complementary error function of `x`.
### math.exp\(x\)
#### math.exp\(x\)
Return the exponential of `x`.
### math.expm1\(x\)
#### math.expm1\(x\)
Return `exp(x) - 1`.
### math.fabs\(x\)
#### math.fabs\(x\)
Return the absolute value of `x`.
### math.floor\(x\)
#### math.floor\(x\)
Return an integer, being `x` rounded towards negative infinity.
### math.fmod\(x, y\)
#### math.fmod\(x, y\)
Return the remainder of `x/y`.
### math.frexp\(x\)
#### math.frexp\(x\)
Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple `(m, e)` such that `x == m * 2**e` exactly. If `x == 0` then the function returns `(0.0, 0)`, otherwise the relation `0.5 <= abs(m) < 1` holds.
### math.gamma\(x\)
#### math.gamma\(x\)
Return the gamma function of `x`.
### math.isfinite\(x\)
#### math.isfinite\(x\)
Return `True` if `x` is finite.
### math.isinf\(x\)
#### math.isinf\(x\)
Return `True` if `x` is infinite.
### math.isnan\(x\)
#### math.isnan\(x\)
Return `True` if `x` is not-a-number
### math.ldexp\(x, exp\)
#### math.ldexp\(x, exp\)
Return `x * (2**exp)`.
### math.lgamma\(x\)
#### math.lgamma\(x\)
Return the natural logarithm of the gamma function of `x`.
### math.log\(x\)
#### math.log\(x\)
Return the natural logarithm of `x`.
### math.log10\(x\)
#### math.log10\(x\)
Return the base-10 logarithm of `x`.
### math.log2\(x\)
#### math.log2\(x\)
Return the base-2 logarithm of `x`.
### math.modf\(x\)
#### math.modf\(x\)
Return a tuple of two floats, being the fractional and integral parts of `x`. Both return values have the same sign as `x`.
### math.pow\(x, y\)
#### math.pow\(x, y\)
Returns `x` to the power of `y`.
### math.radians\(x\)
#### math.radians\(x\)
Return degrees `x` converted to radians.
### math.sin\(x\)
#### math.sin\(x\)
Return the sine of `x`.
### math.sinh\(x\)
#### math.sinh\(x\)
Return the hyperbolic sine of `x`.
### math.sqrt\(x\)
#### math.sqrt\(x\)
Return the square root of `x`.
### math.tan\(x\)
#### math.tan\(x\)
Return the tangent of `x`.
### math.tanh\(x\)
#### math.tanh\(x\)
Return the hyperbolic tangent of `x`.
### math.trunc\(x\)
#### math.trunc\(x\)
Return an integer, being `x` rounded towards `0`.

View File

@@ -2,13 +2,13 @@
## Methods
### micropython.alloc\_emergency\_exception\_buf\(size\)
#### micropython.alloc\_emergency\_exception\_buf\(size\)
Allocate size bytes of RAM for the emergency exception buffer \(a good size is around 100 bytes\). The buffer is used to create exceptions in cases when normal RAM allocation would fail \(eg within an interrupt handler\) and therefore give useful traceback information in these situations.
A good way to use this function is to place it at the start of a main script \(e.g. `boot.py` or `main.py`\) and then the emergency exception buffer will be active for all the code following it.
### micropython.const\(expr\)
#### micropython.const\(expr\)
Used to declare that the expression is a constant so that the compile can optimise it. The use of this function should be as follows:
@@ -23,35 +23,35 @@ Constants declared this way are still accessible as global variables from outsid
This const function is recognised directly by the MicroPython parser and is provided as part of the `micropython` module mainly so that scripts can be written which run under both CPython and MicroPython, by following the above pattern.
### micropython.opt\_level\(\[level\]\)
#### micropython.opt\_level\(\[level\]\)
If `level` is given then this function sets the optimisation level for subsequent compilation of scripts, and returns `None`. Otherwise it returns the current optimisation level.
### micropython.mem\_info\(\[verbose\]\)
#### micropython.mem\_info\(\[verbose\]\)
Print information about currently used memory. If the `verbose` argument is given then extra information is printed.
The information that is printed is implementation dependent, but currently includes the amount of stack and heap used. In verbose mode it prints out the entire heap indicating which blocks are used and which are free.
### micropython.qstr\_info\(\[verbose\]\)
#### micropython.qstr\_info\(\[verbose\]\)
Print information about currently interned strings. If the `verbose` argument is given then extra information is printed.
The information that is printed is implementation dependent, but currently includes the number of interned strings and the amount of RAM they use. In verbose mode it prints out the names of all RAM-interned strings.
### micropython.stack\_use\(\)
#### micropython.stack\_use\(\)
Return an integer representing the current amount of stack that is being used. The absolute value of this is not particularly useful, rather it should be used to compute differences in stack usage at different points.
### micropython.heap\_lock\(\)
#### micropython.heap\_lock\(\)
### micropython.heap\_unlock\(\)
#### micropython.heap\_unlock\(\)
Lock or unlock the heap. When locked no memory allocation can occur and a `MemoryError` will be raised if any heap allocation is attempted.
These functions can be nested, i.e. `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.
### micropython.kbd\_intr\(chr\)
#### micropython.kbd\_intr\(chr\)
Set the character that will raise a `KeyboardInterrupt` exception. By default this is set to 3 during script execution, corresponding to `Ctrl-C`. Passing `-1` to this function will disable capture of `Ctrl-C`, and passing `3` will restore it.

View File

@@ -2,11 +2,11 @@
## Methods
### sys.exit\(retval=0\)
#### sys.exit\(retval=0\)
Terminate current program with a given exit code. Underlyingly, this function raise as `SystemExit` exception. If an argument is given, its value given as an argument to `SystemExit`.
### sys.print\_exception\(exc, file=sys.stdout\)
#### sys.print\_exception\(exc, file=sys.stdout\)
Print exception with a traceback to a file-like object file \(or `sys.stdout` by default\).

View File

@@ -4,7 +4,7 @@ This module implements conversions between binary data and various encodings of
## Methods
### ubinascii.hexlify\(data\[, sep\]\)
#### ubinascii.hexlify\(data\[, sep\]\)
Convert binary data to hexadecimal representation. Returns bytes string.
@@ -14,15 +14,15 @@ Convert binary data to hexadecimal representation. Returns bytes string.
If additional argument, `sep` is supplied, it is used as a separator between hexadecimal values.
{% endhint %}
### ubinascii.unhexlify\(data\)
#### ubinascii.unhexlify\(data\)
Convert hexadecimal data to binary representation. Returns bytes string. \(i.e. inverse of `hexlify`\)
### ubinascii.a2b\_base64\(data\)
#### ubinascii.a2b\_base64\(data\)
Convert Base64-encoded data to binary representation. Returns bytes string.
### ubinascii.b2a\_base64\(data\)
#### ubinascii.b2a\_base64\(data\)
Encode binary data in Base64 format. Returns string.

View File

@@ -8,7 +8,7 @@ This module provides native support for cryptographic algorithms. Its loosely
## **Methods**
### crypto.getrandbits\(bits\)
#### crypto.getrandbits\(bits\)
Returns a bytes object filled with random bits obtained from the hardware random number generator.

View File

@@ -77,35 +77,35 @@ Note that bitfield operations are independent of target byte endianness, in part
## Module Contents
### class uctypes.struct\(addr, descriptor, layout\_type=NATIVE\)
#### class uctypes.struct\(addr, descriptor, layout\_type=NATIVE\)
Instantiate a "foreign data structure" object based on structure address in memory, descriptor \(encoded as a dictionary\), and layout type \(see below\).
### uctypes.LITTLE\_ENDIAN
#### uctypes.LITTLE\_ENDIAN
Layout type for a little-endian packed structure. \(Packed means that every field occupies exactly as many bytes as defined in the descriptor, i.e. the alignment is 1\).
### uctypes.BIG\_ENDIAN
#### uctypes.BIG\_ENDIAN
Layout type for a big-endian packed structure.
### uctypes.NATIVE
#### uctypes.NATIVE
Layout type for a native structure - with data endianness and alignment conforming to the ABI of the system on which MicroPython runs.
### uctypes.sizeof\(struct\)
#### uctypes.sizeof\(struct\)
Return size of data structure in bytes. Argument can be either structure class or specific instantiated structure object \(or its aggregate field\).
### uctypes.addressof\(obj\)
#### uctypes.addressof\(obj\)
Return address of an object. Argument should be bytes, `bytearray` or other object supporting buffer protocol \(and address of this buffer is what actually returned\).
### uctypes.bytes\_at\(addr, size\)
#### uctypes.bytes\_at\(addr, size\)
Capture memory at the given address and size as bytes object. As bytes object is immutable, memory is actually duplicated and copied into bytes object, so if memory contents change later, created object retains original value.
### uctypes.bytearray\_at\(addr, size\)
#### uctypes.bytearray\_at\(addr, size\)
Capture memory at the given address and size as `bytearray` object. Unlike `bytes_at()` function above, memory is captured by reference, so it can be both written too, and you will access current value at the given memory address.

View File

@@ -4,41 +4,41 @@ This module implements binary data hashing algorithms. MD5 and SHA are supported
## Constructors
### class uhashlib.md5\(\[data\]\)
#### class uhashlib.md5\(\[data\]\)
Create a MD5 hasher object and optionally feed data into it.
### class uhashlib.sha1\(\[data\]\)
#### class uhashlib.sha1\(\[data\]\)
Create a SHA-1 hasher object and optionally feed data into it.
### class uhashlib.sha224\(\[data\]\)
#### class uhashlib.sha224\(\[data\]\)
Create a SHA-224 hasher object and optionally feed data into it.
### class uhashlib.sha256\(\[data\]\)
#### class uhashlib.sha256\(\[data\]\)
Create a SHA-256 hasher object and optionally feed data into it.
### class uhashlib.sha384\(\[data\]\)
#### class uhashlib.sha384\(\[data\]\)
Create a SHA-384 hasher object and optionally feed data into it.
### class uhashlib.sha512\(\[data\]\)
#### class uhashlib.sha512\(\[data\]\)
Create a SHA-512 hasher object and optionally feed data into it.
## Methods
### hash.update\(data\)
#### hash.update\(data\)
Feed more binary data into hash.
### hash.digest\(\)
#### hash.digest\(\)
Return hash for all data passed through hash, as a bytes object. After this method is called, more data cannot be fed into hash any longer.
### hash.hexdigest\(\)
#### hash.hexdigest\(\)
This method is NOT implemented. Use `ubinascii.hexlify(hash.digest())` to achieve a similar effect.

View File

@@ -4,15 +4,15 @@ This modules allows to convert between Python objects and the JSON data format.
## Methods
### ujson.dumps\(obj\)
#### ujson.dumps\(obj\)
Return `obj` represented as a JSON string.
### ujson.loads\(str\)
#### ujson.loads\(str\)
Parse the JSON `str` and return an object. Raises `ValueError` if the string is not correctly formed.
### ujson.load\(fp\)
#### ujson.load\(fp\)
Parse contents of `fp` \(a `.read()`-supporting file-like object containing a JSON document\). Raises `ValueError` if the content is not correctly formed.

View File

@@ -11,39 +11,39 @@ The filesystem has `/` as the root directory and the available physical drives a
## Methods
### uos.uname\(\)
#### uos.uname\(\)
Return information about the system, firmware release version, and MicroPython interpreter version.
### uos.chdir\(path\)
#### uos.chdir\(path\)
Change current directory.
### uos.getcwd\(\)
#### uos.getcwd\(\)
Get the current directory.
### uos.listdir\(\[dir\]\)
#### uos.listdir\(\[dir\]\)
With no argument, list the current directory. Otherwise list the given directory.
### uos.mkdir\(path\)
#### uos.mkdir\(path\)
Create a new directory.
### uos.remove\(path\)
#### uos.remove\(path\)
Remove a file.
### uos.rmdir\(path\)
#### uos.rmdir\(path\)
Remove a directory.
### uos.rename\(old\_path, new\_path\)
#### uos.rename\(old\_path, new\_path\)
Rename a file.
### uos.stat\(path\)
#### uos.stat\(path\)
Get the status of a file or directory.
@@ -60,23 +60,23 @@ The return value is a tuple with the following 10 values, in order:
* `st_mtime`: time of most recent content modification.
* `st_ctime`: time of most recent metadata change.
### uos.getfree\(path\)
#### uos.getfree\(path\)
Returns the free space \(in KiB\) in the drive specified by path.
### uos.sync\(\)
#### uos.sync\(\)
Sync all filesystems.
### uos.urandom\(n\)
#### uos.urandom\(n\)
Return a bytes object with n random bytes.
### uos.unlink\(path\)
#### uos.unlink\(path\)
Alias for the `remove()` method.
### uos.mount\(block\_device, mount\_point, \* , readonly=False\)
#### uos.mount\(block\_device, mount\_point, \* , readonly=False\)
Mounts a block device \(like an SD object\) in the specified mount point. Example:
@@ -87,11 +87,11 @@ uos.unmount(path)
Unmounts a previously mounted block device from the given path.
### uos.mkfs\(block\_device or path\)
#### uos.mkfs\(block\_device or path\)
Formats the specified path, must be either `/flash` or `/sd`. A block device can also be passed like an SD object before being mounted.
### uos.dupterm\(stream\_object\)
#### uos.dupterm\(stream\_object\)
Duplicate the terminal \(the REPL\) on the passed stream-like object. The given object must at least implement the `read()` and `write()` methods.

View File

@@ -21,19 +21,19 @@ Counted repetitions `({m,n})`, more advanced assertions, named groups, etc. are
## Methods
### ure.compile\(regex\)
#### ure.compile\(regex\)
Compile regular expression, return `regex object`.
### ure.match\(regex, string\)
#### ure.match\(regex, string\)
Match regex against `string`. Match always happens from starting position in a string.
### ure.search\(regex, string\)
#### ure.search\(regex, string\)
Search regex in a string. Unlike match, this will search string for first position which matches regex \(which still may be 0 if regex is anchored\).
### ure.DEBUG
#### ure.DEBUG
Flag value, display debug information about compiled expression.
@@ -41,17 +41,17 @@ Flag value, display debug information about compiled expression.
Compiled regular expression. Instances of this class are created using `ure.compile()`.
### regex.match\(string\)
#### regex.match\(string\)
### regex.search\(string\)
#### regex.search\(string\)
### regex.split\(string, max\_split=-1\)
#### regex.split\(string, max\_split=-1\)
## Match objects
Match objects as returned by `match()` and `search()` methods.
### match.group\(\[index\]\)
#### match.group\(\[index\]\)
Only numeric groups are supported.

View File

@@ -4,7 +4,7 @@ This module provides access to Transport Layer Security \(often known as "Secure
## Methods
### ssl.wrap\_socket\(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\)
#### ssl.wrap\_socket\(sock, keyfile=None, certfile=None, server\_side=False, cert\_reqs=CERT\_NONE, ca\_certs=None\)
Takes an instance `sock` of `socket.socket`, and returns an instance of ssl.SSLSocket, a subtype of `socket.socket`, which wraps the underlying socket in an SSL context. Example:
@@ -32,7 +32,7 @@ SSL sockets inherit all methods and from the standard sockets, see the `usocket`
## Exceptions
`ssl.SSLError`
* `ssl.SSLError`
## Constants

View File

@@ -8,23 +8,23 @@ Supported format codes: `b, B, h, H, i, I, l, L, q, Q, s, P, f, d` \(the latter
## Methods
### ustruct.calcsize\(fmt\)
#### ustruct.calcsize\(fmt\)
Return the number of bytes needed to store the given `fmt`.
### ustruct.pack\(fmt, v1, v2, ...\)
#### ustruct.pack\(fmt, v1, v2, ...\)
Pack the values `v1, v2, ...` according to the format string `fmt`. The return value is a bytes object encoding the values.
### ustruct.pack\_into\(fmt, buffer, offset, v1, v2, ...\)
#### ustruct.pack\_into\(fmt, buffer, offset, v1, v2, ...\)
Pack the values `v1, v2, ...` according to the format string `fmt` into a buffer starting at `offset`. `offset` may be negative to count from the end of buffer.
### ustruct.unpack\(fmt, data\)
#### ustruct.unpack\(fmt, data\)
Unpack from the `data` according to the format string `fmt`. The return value is a tuple of the unpacked values.
### ustruct.unpack\_from\(fmt, data, offset=0\)
#### ustruct.unpack\_from\(fmt, data, offset=0\)
Unpack from the `data` starting at `offset` according to the format string `fmt`. `offset` may be negative to count from the end of buffer. The return value is a tuple of the unpacked values.

View File

@@ -16,7 +16,7 @@ If actual calendar time is not maintained with a system/MicroPython RTC, functio
## Methods
### utime.gmtime\(\[secs\]\)
#### utime.gmtime\(\[secs\]\)
Convert a time expressed in seconds since the Epoch \(see above\) into an 8-tuple which contains: `(year, month, mday, hour, minute, second, weekday, yearday)` If `secs` is not provided or `None`, then the current time from the RTC is used.
@@ -29,39 +29,39 @@ Convert a time expressed in seconds since the Epoch \(see above\) into an 8-tupl
* `weekday` is 0-6 for Mon-Sun
* `yearday` is 1-366
### utime.localtime\(\[secs\]\)
#### utime.localtime\(\[secs\]\)
Like `gmtime()` but converts to local time. If `secs` is not provided or `None`, the current time from the RTC is used.
### utime.mktime\(\)
#### utime.mktime\(\)
This is inverse function of `localtime`. Its argument is a full 8-tuple which expresses a time as per `localtime`. It returns an integer which is the number of seconds since `Jan 1, 2000`.
### utime.sleep\(seconds\)
#### utime.sleep\(seconds\)
Sleep for the given number of `seconds`. `seconds` can be a floating-point number to sleep for a fractional number of seconds. Note that other MicroPython ports may not accept floating-point argument, for compatibility with them use `sleep_ms()` and `sleep_us()` functions.
### utime.sleep\_ms\(ms\)
#### utime.sleep\_ms\(ms\)
Delay for given number of milliseconds, should be positive or 0.
### utime.sleep\_us\(us\)
#### utime.sleep\_us\(us\)
Delay for given number of microseconds, should be positive or 0
### utime.ticks\_ms\(\)
#### utime.ticks\_ms\(\)
Returns uptime, in milliseconds.
### utime.ticks\_us\(\)
#### utime.ticks\_us\(\)
Just like `ticks_ms` above, but in microseconds.
### utime.ticks\_cpu\(\)
#### utime.ticks\_cpu\(\)
Same as `ticks_us`, but faster.
### utime.ticks\_diff\(old, new\)
#### utime.ticks\_diff\(old, new\)
Measure period between consecutive calls to `ticks_ms()`, `ticks_us()`, or `ticks_cpu()`. The value returned by these functions may wrap around at any time, so directly subtracting them is not supported. `ticks_diff()` should be used instead. "old" value should actually precede "new" value in time, or result is undefined. This function should not be used to measure arbitrarily long periods of time \(because `ticks_*()` functions wrap around and usually would have short period\). The expected usage pattern is implementing event polling with timeout:
@@ -73,11 +73,11 @@ while pin.value() == 0:
raise TimeoutError
```
### utime.time\(\)
#### utime.time\(\)
Returns the number of seconds, as an integer, since the Epoch, assuming that underlying RTC is set. If an RTC is not set, this function returns number of seconds since power up or reset\). If you want to develop portable MicroPython application, you should not rely on this function to provide higher than second precision. If you need higher precision, use `ticks_ms()` and `ticks_us()` functions, if you need calendar time, `localtime()` without an argument is a better choice.
### utime.timezone\(\[secs\]\)
#### utime.timezone\(\[secs\]\)
Set or get the timezone offset, in seconds. If `secs` is not provided, it returns the current value.

View File

@@ -26,7 +26,7 @@ print(original)
## Constructors
### class ucrypto.AES\(key, mode, IV, \* , counter, segment\_size\)
#### class ucrypto.AES\(key, mode, IV, \* , counter, segment\_size\)
Create an AES object that will let you encrypt and decrypt messages.
@@ -40,11 +40,11 @@ The arguments are:
## Methods
### ucrypto.encrypt\(\)
#### ucrypto.encrypt\(\)
Encrypt data with the key and the parameters set at initialisation.
### ucrypto.decrypt\(\)
#### ucrypto.decrypt\(\)
Decrypt data with the key and the parameters set at initialisation.

View File

@@ -16,7 +16,7 @@ can.recv()
## Constructors
### class machine.CAN\(bus=0, ...\)
#### class machine.CAN\(bus=0, ...\)
Create an CAN object. See init for parameters of initialisation.:
@@ -27,7 +27,7 @@ can = CAN(0, mode=CAN.NORMAL, baudrate=500000, pins=('P22', 'P23')) # pin ord
## Methods
### can.init\(mode=CAN.NORMAL, baudrate=500000, \*, frame\_format=CAN.FORMAT\_STD, rx\_queue\_len=128, pins=\('P22', 'P23'\)\)
#### can.init\(mode=CAN.NORMAL, baudrate=500000, \*, frame\_format=CAN.FORMAT\_STD, rx\_queue\_len=128, pins=\('P22', 'P23'\)\)
Initialize the CAN controller. The arguments are:
@@ -37,11 +37,11 @@ Initialize the CAN controller. The arguments are:
* `rx_queue_len` defines the number of messages than can be queued by the receiver. Due to CAN being a high traffic bus, large values are recommended \(&gt;= 128\), otherwise messages will be dropped specially when no filtering is applied.
* `pins` selects the `Tx` and `Rx` pins \(in that order\).
### can.deinit\(\)
#### can.deinit\(\)
Disables the CAN bus.
### can.send\(id, \* , data=None, rtr=False, extended=False\)
#### can.send\(id, \* , data=None, rtr=False, extended=False\)
Send a CAN frame on the bus
@@ -60,7 +60,7 @@ can.send(id=0x010, data=bytes([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]))
can.send(id=0x012, rtr=True) # sends a remote request for message id=0x12
```
### can.recv\(timeout=0\)
#### can.recv\(timeout=0\)
Get a message from the receive queue, and optionally specify a timeout value in **s** \(can be a floating point value e.g. `0.2`\). This function returns `None` if no messages available. If a message is present, it will be returned as a named tuple with the following form:
@@ -71,7 +71,7 @@ Get a message from the receive queue, and optionally specify a timeout value in
(id=0x012, data=b'123', rtr=False, extended=False)
```
### can.soft\_filter\(mode, filter\_list\)
#### can.soft\_filter\(mode, filter\_list\)
Specify a software filter accepting only the messages that pass the filter test.
@@ -95,7 +95,7 @@ can.soft_filter(CAN.FILTER_MASK, [(0x100, 0x7FF), (0x200, 0x7FC)]) # more of the
can.soft_filter(None) # disable soft filters, all messages are accepted
```
### can.callback\(trigger, handler=None, arg=None\)
#### can.callback\(trigger, handler=None, arg=None\)
Set a callback to be triggered when any of this 3 events are present:
@@ -122,7 +122,7 @@ def can_cb(can_o):
can.callback(handler=can_cb, trigger=CAN.RX_FRAME)
```
### can.events\(\)
#### can.events\(\)
This method returns a value with bits sets \(if any\) indicating the events that have occurred in the bus. Please note that by calling this function the internal events registry is cleared automatically, therefore calling it immediately for a second time will most likely return a value of 0.

View File

@@ -16,25 +16,25 @@ dac_tone.tone(1000, 0) # set tone output to 1kHz
## Constructors
### class class machine.DAC\(pin\)
#### class class machine.DAC\(pin\)
Create a DAC object, that will let you associate a channel with a `pin`. `pin` can be a string argument.
## Methods
### dac.init\(\)
#### dac.init\(\)
Enable the DAC block. This method is automatically called on object creation.
### dac.deinit\(\)
#### dac.deinit\(\)
Disable the DAC block.
### dac.write\(value\)
#### dac.write\(value\)
Set the DC level for a DAC pin. `value` is a float argument, with values between 0 and 1.
### dac.tone\(frequency, amplitude\)
#### dac.tone\(frequency, amplitude\)
Sets up tone signal to the specified `frequency` at `amplitude` scale. `frequency` can be from `125Hz` to `20kHz` in steps of `122Hz`. `amplitude` is an integer specifying the tone amplitude to write the DAC pin. Amplitude value represents:

View File

@@ -21,7 +21,7 @@ p_in() # get value, 0 or 1
## Constructors
### class machine.Pin\(id, ...\)
#### class machine.Pin\(id, ...\)
Create a new Pin object associated with the string `id`. If additional arguments are given, they are used to initialise the pin. [See pin.init\(\)](pin.md#pin-init-mode-pull-alt)
@@ -32,7 +32,7 @@ p = Pin('P10', mode=Pin.OUT, pull=None, alt=-1)
## Methods
### pin.init\(mode, pull, \* , alt\)
#### pin.init\(mode, pull, \* , alt\)
Initialise the pin:
@@ -48,18 +48,18 @@ Initialise the pin:
Returns: `None`.
### pin.id\(\)
#### pin.id\(\)
Get the pin id.
### pin.value\(\[value\]\)
#### pin.value\(\[value\]\)
Get or set the digital logic level of the pin:
* With no argument, return 0 or 1 depending on the logic level of the pin.
* With value given, set the logic level of the pin. value can be anything that converts to a boolean. If it converts to True, the pin is set high, otherwise it is set low.
### pin\(\[value\]\)
#### pin\(\[value\]\)
Pin objects are callable. The call method provides a \(fast\) shortcut to set and get the value of the pin.
@@ -73,25 +73,25 @@ pin() # fast method to get the value
See `pin.value()` for more details.
### pin.toggle\(\)
#### pin.toggle\(\)
Toggle the value of the pin.
### pin.mode\(\[mode\]\)
#### pin.mode\(\[mode\]\)
Get or set the pin mode.
### pin.pull\(\[pull\]\)
#### pin.pull\(\[pull\]\)
Get or set the pin pull.
### pin.hold\(\[hold\]\)
#### pin.hold\(\[hold\]\)
Get or set the pin hold. You can apply a hold to a pin by passing `True` \(or clear it by passing `False`\). When a pin is held, its value cannot be changed by using `Pin.value()` or `Pin.toggle()` until the hold is released. This Can be used to retain the pin state through a core reset and system reset triggered by watchdog time-out or Deep-sleep events. Only pins in the RTC power domain can retain their value through deep sleep or reset.
These are: `P2, P3, P4, P6, P8, P9, P10, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23`
### pin.callback\(trigger, handler=None, arg=None\)
#### pin.callback\(trigger, handler=None, arg=None\)
Set a callback to be triggered when the input level at the pin changes.
@@ -124,7 +124,7 @@ For more information on how Pycoms products handle interrupts, see [here](../
## Attributes
### class pin.exp\_board
#### class pin.exp\_board
Contains all Pin objects supported by the expansion board. Examples:
@@ -134,7 +134,7 @@ led = Pin(Pin.exp_board.G16, mode=Pin.OUT)
Pin.exp_board.G16.id()
```
### class pin.module
#### class pin.module
Contains all `Pin` objects supported by the module. Examples:

View File

@@ -40,7 +40,7 @@ data = rmt.recv_pulses()
## Constructors
### class machine.RMT\(channel,...\)
#### class machine.RMT\(channel,...\)
Construct an RMT object on the given channel. `channel` can be 2-7. With no additional parameters, the RMT object is created but not initialised. If extra arguments are given, the RMT is initialised for transmission or reception. See `init` for parameters of initialisation. The resolution which a pulse can be sent/received depends on the selected channel:
@@ -57,7 +57,7 @@ Construct an RMT object on the given channel. `channel` can be 2-7. With no addi
## Methods
### rmt.init\(gpio, rx\_idle\_threshold, rx\_filter\_threshold, tx\_idle\_level, tx\_carrier\)
#### rmt.init\(gpio, rx\_idle\_threshold, rx\_filter\_threshold, tx\_idle\_level, tx\_carrier\)
Initialise the RMT peripheral with the given parameters:
@@ -75,7 +75,7 @@ The `tx_carrier` parameter is a tuple with the following structure:
* `carrier_duty_percent` is the duty percent of the carrier's signal, can be 0%-100%.
* `carrier_level` is the level of the pulse to modulate, can be RMT.HIGH or RMT.LOW.
### rmt.deinit\(\)
#### rmt.deinit\(\)
Deinitialise the RMT object.
@@ -83,7 +83,7 @@ Deinitialise the RMT object.
If an RMT object needs to be reconfigured from RX/TX to TX/RX, then either first `deinit()` must be called or the `init()` again with the desired configuration.
{% endhint %}
### rmt.pulses\_get\(pulses, timeout\)
#### rmt.pulses\_get\(pulses, timeout\)
Reads in pulses from the GPIO pin.
@@ -110,7 +110,7 @@ Return value: Tuple of items with the following structure: `(level, duration)`:
Maximum of 128 pulses can be received in a row without receiving "idle" signal. If the incoming pulse sequence contains more than 128 pulses the rest is dropped and the receiver waits for another sequence of pulses. The `pulses_get` function can be called to receive more than 128 pulses, however the above mentioned limitation should be kept in mind when evaluating the received data.
{% endhint %}
### rmt.pulses\_send\(duration, data, start\_level\)
#### rmt.pulses\_send\(duration, data, start\_level\)
Generates pulses as defined by the parameters below

View File

@@ -14,7 +14,7 @@ print(rtc.now())
## Constructors
### class machine.RTC\(id=0, ...\)
#### class machine.RTC\(id=0, ...\)
Create an RTC object. See init for parameters of initialisation.
@@ -25,11 +25,11 @@ rtc = RTC(id=0)
## Methods
### rtc.init\(datetime=None, source=RTC.INTERNAL\_RC\)
#### rtc.init\(datetime=None, source=RTC.INTERNAL\_RC\)
Initialise the RTC. The arguments are:
* `datetime` when passed it sets the current time. It is a tuple of the form: `(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])`.
* `datetime` when passed it sets the current time. It is a tuple of the form: `(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])`
* `source` selects the oscillator that drives the RTC. The options are RTC.INTERNAL\_RC and RTC.XTAL\_32KHZ
For example:
@@ -43,7 +43,7 @@ rtc.init((2017, 2, 28, 10, 30, 0, 0, 0))
`tzinfo` is ignored by this method. Use `time.timezone` to achieve similar results.
{% endhint %}
### rtc.now\(\)
#### rtc.now\(\)
Get get the current `datetime` tuple:
@@ -52,7 +52,7 @@ Get get the current `datetime` tuple:
rtc.now()
```
### rtc.ntp\_sync\(server, \* , update\_period=3600\)
#### rtc.ntp\_sync\(server, \* , update\_period=3600\)
Set up automatic fetch and update the time using NTP \(SNTP\).
@@ -65,7 +65,7 @@ Can be used like:
rtc.ntp_sync("pool.ntp.org") # this is an example. You can select a more specific server according to your geographical location
```
### rtc.synced\(\)
#### rtc.synced\(\)
Returns `True` if the last `ntp_sync` has been completed, `False` otherwise:

View File

@@ -33,17 +33,17 @@ f.close()
## Constructors
### class machine.SD\(id, ...\)
#### class machine.SD\(id, ...\)
Create a SD card object. See [`sd.init()`](sd.md#sd-init-id-0) for parameters if initialisation.
## Methods
### sd.init\(id=0\)
#### sd.init\(id=0\)
Enable the SD card.
### sd.deinit\(\)
#### sd.deinit\(\)
Disable the SD card.

View File

@@ -41,13 +41,13 @@ spi.write_readinto(bytes([0x01, 0x02, 0x03, 0x04, 0x05]), rbuf) # send a receive
## Constructors
### class machine.SPI\(id, ...\)
#### class machine.SPI\(id, ...\)
Construct an SPI object on the given bus. `id` can be only 0. With no additional parameters, the SPI object is created but not initialised \(it has the settings from the last initialisation of the bus, if any\). If extra arguments are given, the bus is initialised. See init for parameters of initialisation.
## Methods
### spi.init\(mode, baudrate=1000000, \* , polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=\(CLK, MOSI, MISO\)\)
#### spi.init\(mode, baudrate=1000000, \* , polarity=0, phase=0, bits=8, firstbit=SPI.MSB, pins=\(CLK, MOSI, MISO\)\)
Initialise the SPI bus with the given parameters:
@@ -59,23 +59,23 @@ Initialise the SPI bus with the given parameters:
* `firstbit` can be SPI.MSB or SPI.LSB.
* `pins` is an optional tuple with the pins to assign to the SPI bus. If the pins argument is not given the default pins will be selected \(`P10` as CLK,`P11` as MOSI and `P14` as MISO\). If pins is passed as None then no pin assignment will be made.
### spi.deinit\(\)
#### spi.deinit\(\)
Turn off the SPI bus.
### spi.write\(buf\)
#### spi.write\(buf\)
Write the data contained in `buf`. Returns the number of bytes written.
### spi.read\(nbytes, \* , write=0x00\)
#### spi.read\(nbytes, \* , write=0x00\)
Read the `nbytes` while writing the data specified by `write`. Returns the bytes read.
### spi.readinto\(buf, \* , write=0x00\)
#### spi.readinto\(buf, \* , write=0x00\)
Read into the buffer specified by `buf` while writing the data specified by `write`. Return the number of bytes read.
### spi.write\_readinto\(write\_buf, read\_buf\)
#### spi.write\_readinto\(write\_buf, read\_buf\)
Write from `write_buf` and read into `read_buf`. Both buffers must have the same length. Returns the number of bytes written

View File

@@ -61,7 +61,7 @@ uart.read(5) # read up to 5 bytes
## Constructors
### class machine.UART\(bus, ...\)
#### class machine.UART\(bus, ...\)
Construct a UART object on the given `bus`. `bus` can be `0, 1 or 2`. If the `bus` is not given, the default one will be selected \(`0`\) or the selection will be made based on the given pins.
@@ -71,7 +71,7 @@ On the GPy/FiPy UART2 is unavailable because it is used to communicate with the
## Methods
### uart.init\(baudrate=9600, bits=8, parity=None, stop=1, \* , timeout\_chars=2, pins=\(TXD, RXD, RTS, CTS\)\)
#### uart.init\(baudrate=9600, bits=8, parity=None, stop=1, \* , timeout\_chars=2, pins=\(TXD, RXD, RTS, CTS\)\)
Initialise the UART bus with the given parameters:
@@ -82,49 +82,49 @@ Initialise the UART bus with the given parameters:
* `timeout_chars` Rx timeout defined in number of characters. The value given here will be multiplied by the time a characters takes to be transmitted at the configured `baudrate`.
* `pins` is a 4 or 2 item list indicating the TXD, RXD, RTS and CTS pins \(in that order\). Any of the pins can be `None` if one wants the UART to operate with limited functionality. If the RTS pin is given the the RX pin must be given as well. The same applies to CTS. When no pins are given, then the default set of TXD \(P1\) and RXD \(P0\) pins is taken, and hardware flow control will be disabled. If `pins=None`, no pin assignment will be made.
### uart.deinit\(\)
#### uart.deinit\(\)
Turn off the UART bus.
### uart.any\(\)
#### uart.any\(\)
Return the number of characters available for reading.
### uart.read\(\[nbytes\]\)
#### uart.read\(\[nbytes\]\)
Read characters. If `nbytes` is specified then read at most that many bytes.
Return value: a bytes object containing the bytes read in. Returns `None` on timeout.
### uart.readall\(\)
#### uart.readall\(\)
Read as much data as possible.
Return value: a bytes object or `None` on timeout.
### uart.readinto\(buf\[, nbytes\]\)
#### uart.readinto\(buf\[, nbytes\]\)
Read bytes into the `buf`. If `nbytes` is specified then read at most that many bytes. Otherwise, read at most `len(buf)` bytes.
Return value: number of bytes read and stored into `buf` or `None` on timeout.
### uart.readline\(\)
#### uart.readline\(\)
Read a line, ending in a newline character. If such a line exists, return is immediate. If the timeout elapses, all available data is returned regardless of whether a newline exists.
Return value: the line read or `None` on timeout if no data is available.
### uart.write\(buf\)
#### uart.write\(buf\)
Write the buffer of bytes to the bus.
Return value: number of bytes written or None on timeout.
### uart.sendbreak\(\)
#### uart.sendbreak\(\)
Send a break condition on the bus. This drives the bus low for a duration of 13 bits. Return value: `None`.
### uart.wait\_tx\_done\(timeout\_ms\)
#### uart.wait\_tx\_done\(timeout\_ms\)
Waits at most `timeout_ms` for the last Tx transaction to complete. Returns `True` if all data has been sent and the TX buffer has no data in it, otherwise returns `False`.

View File

@@ -12,17 +12,17 @@ wdt.feed()
## Constructors
### class machine.WDT\(id=0, timeout\)
#### class machine.WDT\(id=0, timeout\)
Create a WDT object and start it. The `id` can only be `0`. See the init method for the parameters of initialisation.
## Methods
### wdt.init\(timeout\)
#### wdt.init\(timeout\)
Initialises the watchdog timer. The timeout must be given in milliseconds. Once it is running the WDT cannot be stopped but the timeout can be re-configured at any point in time.
### wdt.feed\(\)
#### wdt.feed\(\)
Feed the WDT to prevent it from resetting the system. The application should place this call in a sensible place ensuring that the WDT is only fed after verifying that everything is functioning correctly.

View File

@@ -43,7 +43,7 @@ GAP allows for devices to take various roles but generic flow works with devices
## Constructors
### class network.Bluetooth\(id=0, ...\)
#### class network.Bluetooth\(id=0, ...\)
Create a Bluetooth object, and optionally configure it. See init for params of configuration.
@@ -56,7 +56,7 @@ bluetooth = Bluetooth()
## Methods
### bluetooth.init\(id=0, mode=Bluetooth.BLE, antenna=None\)
#### bluetooth.init\(id=0, mode=Bluetooth.BLE, antenna=None\)
* `id` Only one Bluetooth peripheral available so must always be 0
* `mode` currently the only supported mode is `Bluetooth.BLE`
@@ -72,11 +72,11 @@ bluetooth = Bluetooth()
Initialises and enables the Bluetooth radio in BLE mode.
### bluetooth.deinit\(\)
#### bluetooth.deinit\(\)
Disables the Bluetooth radio.
### bluetooth.start\_scan\(timeout\)
#### bluetooth.start\_scan\(timeout\)
Starts performing a scan listening for BLE devices sending advertisements. This function always returns immediately, the scanning will be performed on the background. The return value is `None`. After starting the scan the function `get_adv()` can be used to retrieve the advertisements messages from the FIFO. The internal FIFO has space to cache 16 advertisements.
@@ -91,15 +91,15 @@ bluetooth.start_scan(10) # starts scanning and stop after 10 seconds
bluetooth.start_scan(-1) # starts scanning indefinitely until bluetooth.stop_scan() is called
```
### bluetooth.stop\_scan\(\)
#### bluetooth.stop\_scan\(\)
Stops an ongoing scanning process. Returns `None`.
### bluetooth.isscanning\(\)
#### bluetooth.isscanning\(\)
Returns `True` if a Bluetooth scan is in progress. `False` otherwise.
### bluetooth.get\_adv\(\)
#### bluetooth.get\_adv\(\)
Gets an named tuple with the advertisement data received during the scanning. The tuple has the following structure: `(mac, addr_type, adv_type, rssi, data)`
@@ -121,11 +121,11 @@ adv = bluetooth.get_adv() #
ubinascii.hexlify(adv.mac) # convert hexadecimal to ascii
```
### bluetooth.get\_advertisements\(\)
#### bluetooth.get\_advertisements\(\)
Same as the `get_adv()` method, but this one returns a list with all the advertisements received.
### bluetooth.resolve\_adv\_data\(data, data\_type\)
#### bluetooth.resolve\_adv\_data\(data, data\_type\)
Parses the advertisement data and returns the requested `data_type` if present. If the data type is not present, the function returns `None`.
@@ -155,7 +155,7 @@ while bluetooth.isscanning():
print(ubinascii.hexlify(mfg_data))
```
### bluetooth.connect\(mac\_addr\)
#### bluetooth.connect\(mac\_addr\)
Opens a BLE connection with the device specified by the `mac_addr` argument. This function blocks until the connection succeeds or fails. If the connections succeeds it returns a object of type `GATTCConnection`.
@@ -163,7 +163,7 @@ Opens a BLE connection with the device specified by the `mac_addr` argument. Thi
bluetooth.connect('112233eeddff') # mac address is accepted as a string
```
### bluetooth.callback\(trigger=None, handler=None, arg=None\)
#### bluetooth.callback\(trigger=None, handler=None, arg=None\)
Creates a callback that will be executed when any of the triggers occurs. The arguments are:
@@ -173,7 +173,7 @@ Creates a callback that will be executed when any of the triggers occurs. The ar
An example of how this may be used can be seen in the [`bluetooth.events()`](./#bluetooth-events) method.
### bluetooth.events\(\)
#### bluetooth.events\(\)
Returns a value with bit flags identifying the events that have occurred since the last call. Calling this function clears the events.
@@ -197,7 +197,7 @@ bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONN
bluetooth.advertise(True)
```
### bluetooth.set\_advertisement\(\* , name=None, manufacturer\_data=None, service\_data=None, service\_uuid=None\)
#### bluetooth.set\_advertisement\(\* , name=None, manufacturer\_data=None, service\_data=None, service\_uuid=None\)
Configure the data to be sent while advertising. If left with the default of `None` the data wont be part of the advertisement message.
@@ -214,11 +214,11 @@ Example:
bluetooth.set_advertisement(name="advert", manufacturer_data="lopy_v1")
```
### bluetooth.advertise\(\[Enable\]\)
#### bluetooth.advertise\(\[Enable\]\)
Start or stop sending advertisements. The `set_advertisement()` method must have been called prior to this one.
### bluetooth.service\(uuid, \* , isprimary=True, nbr\_chars=1, start=True\)
#### bluetooth.service\(uuid, \* , isprimary=True, nbr\_chars=1, start=True\)
Create a new service on the internal GATT server. Returns a object of type `BluetoothServerService`.
@@ -233,7 +233,7 @@ The arguments are:
bluetooth.service('abc123')
```
### bluetooth.disconnect\_client\(\)
#### bluetooth.disconnect\_client\(\)
Closes the BLE connection with the client.

View File

@@ -6,27 +6,27 @@ The following class allows you to manage characteristics from a Client.
## Methods
### characteristic.uuid\(\)
#### characteristic.uuid\(\)
Returns the UUID of the service. In the case of 16-bit or 32-bit long UUIDs, the value returned is an integer, but for 128-bit long UUIDs the value returned is a bytes object.
### characteristic.instance\(\)
#### characteristic.instance\(\)
Returns the instance ID of the service.
### characteristic.properties\(\)
#### characteristic.properties\(\)
Returns an integer indicating the properties of the characteristic. Properties are represented by bit values that can be OR-ed together. See the constants section for more details.
### characteristic.read\(\)
#### characteristic.read\(\)
Read the value of the characteristic, sending a request to the GATT server. Returns a bytes object representing the characteristic value.
### characteristic.value\(\)
#### characteristic.value\(\)
Returns the locally stored value of the characteristic without sending a read request to the GATT server. If the characteristic value hasn't been read from the GATT server yet, the value returned will be 0.
### characteristic.write\(value\)
#### characteristic.write\(value\)
Writes the given value on the characteristic. For now it only accepts bytes object representing the value to be written.
@@ -34,7 +34,7 @@ Writes the given value on the characteristic. For now it only accepts bytes obje
characteristic.write(b'x0f')
```
### characteristic.callback\(trigger=None, handler=None, arg=None\)
#### characteristic.callback\(trigger=None, handler=None, arg=None\)
This method allows to register for notifications on the characteristic.

View File

@@ -4,11 +4,11 @@ The GATT Client is the device that requests data from the server, otherwise know
## Methods
### connection.disconnect\(\)
#### connection.disconnect\(\)
Closes the BLE connection. Returns `None`.
### connection.isconnected\(\)
#### connection.isconnected\(\)
Returns `True` if the connection is still open. `False` otherwise.
@@ -35,7 +35,7 @@ while True:
print("Connected to device with addr = {}".format(ubinascii.hexlify(adv.mac)))
```
### connection.services\(\)
#### connection.services\(\)
Performs a service search on the connected BLE peripheral \(server\) a returns a list containing objects of the class GATTCService if the search succeeds.

View File

@@ -6,19 +6,19 @@ The following class allows control over Client services.
## Methods
### service.isprimary\(\)
#### service.isprimary\(\)
Returns `True` if the service is a primary one. `False` otherwise.
### service.uuid\(\)
#### service.uuid\(\)
Returns the UUID of the service. In the case of 16-bit or 32-bit long UUIDs, the value returned is an integer, but for 128-bit long UUIDs the value returned is a bytes object.
### service.instance\(\)
#### service.instance\(\)
Returns the instance ID of the service.
### service.characteristics\(\)
#### service.characteristics\(\)
Performs a get characteristics request on the connected BLE peripheral a returns a list containing objects of the class GATTCCharacteristic if the request succeeds.

View File

@@ -6,7 +6,7 @@ The following class allows you to manage Server characteristics.
## Methods
### characteristic.value\(\[value\]\)
#### characteristic.value\(\[value\]\)
Gets or sets the value of the characteristic. Can take an integer, a string or a bytes object.
@@ -15,7 +15,7 @@ characteristic.value(123) # set characteristic value to an integer with the valu
characteristic.value() # get characteristic value
```
### characteristic.callback\(trigger=None, handler=None, arg=None\)
#### characteristic.callback\(trigger=None, handler=None, arg=None\)
Creates a callback that will be executed when any of the triggers occurs. The arguments are:
@@ -25,7 +25,7 @@ Creates a callback that will be executed when any of the triggers occurs. The ar
An example of how this could be implemented can be seen in the [`characteristic.events()` ](gattscharacteristic.md#characteristic-events)section.
### characteristic.events\(\)
#### characteristic.events\(\)
Returns a value with bit flags identifying the events that have occurred since the last call. Calling this function clears the events.

View File

@@ -8,15 +8,15 @@ The following class allows control over Server services.
## Methods
### service.start\(\)
#### service.start\(\)
Starts the service if not already started.
### service.stop\(\)
#### service.stop\(\)
Stops the service if previously started.
### service.characteristic\(uuid, \* , permissions, properties, value\)
#### service.characteristic\(uuid, \* , permissions, properties, value\)
Creates a new characteristic on the service. Returns an object of the class `GATTSCharacteristic`. The arguments are:

View File

@@ -51,7 +51,7 @@ For various other complete LoRa examples, check here for additional examples.
## Constructors
### class network.LoRa\(id=0, ...\)
#### class network.LoRa\(id=0, ...\)
Create and configure a LoRa object. See init for params of configuration.
@@ -61,7 +61,7 @@ lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
## Methods
### lora.init\(mode, \* ,region=LoRa.EU868, frequency=868000000, tx\_power=14, bandwidth=LoRa.BW\_125KHZ, sf=7, preamble=8, coding\_rate=LoRa.CODING\_4\_5, power\_mode=LoRa.ALWAYS\_ON, tx\_iq=False, rx\_iq=False, adr=False, public=True, tx\_retries=1, device\_class=LoRa.CLASS\_A\)
#### lora.init\(mode, \* ,region=LoRa.EU868, frequency=868000000, tx\_power=14, bandwidth=LoRa.BW\_125KHZ, sf=7, preamble=8, coding\_rate=LoRa.CODING\_4\_5, power\_mode=LoRa.ALWAYS\_ON, tx\_iq=False, rx\_iq=False, adr=False, public=True, tx\_retries=1, device\_class=LoRa.CLASS\_A\)
This method is used to set the LoRa subsystem configuration and to specific raw LoRa or LoRaWAN.
@@ -101,7 +101,7 @@ or
lora.init(mode=LoRa.LORAWAN)
```
### lora.join\(activation, auth, \* ,timeout=None, dr=None\)
#### lora.join\(activation, auth, \* ,timeout=None, dr=None\)
Join a LoRaWAN network. Internally the stack will automatically retry every 15 seconds until a Join Accept message is received.
@@ -178,7 +178,7 @@ app_swkey = ubinascii.unhexlify('2B7E151628AED2A6ABF7158809CF4F3C')
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
```
### lora.bandwidth\(\[bandwidth\]\)
#### lora.bandwidth\(\[bandwidth\]\)
Get or set the bandwidth in raw LoRa mode \(`LoRa.LORA`\). Can be either `LoRa.BW_125KHZ` \(0\), `LoRa.BW_250KHZ` \(1\) or `LoRa.BW_500KHZ` \(2\):
@@ -190,7 +190,7 @@ lora.bandwidth()
lora.bandwidth(LoRa.BW_125KHZ)
```
### lora.frequency\(\[frequency\]\)
#### lora.frequency\(\[frequency\]\)
Get or set the frequency in raw LoRa mode \(`LoRa.LORA`\). The allowed range is between `863000000` and `870000000` Hz for the 868 MHz band version or between `902000000` and `928000000` Hz for the 915 MHz band version.
@@ -202,7 +202,7 @@ lora.frequency()
lora.frequency(868000000)
```
### lora.coding\_rate\(\[coding\_rate\]\)
#### lora.coding\_rate\(\[coding\_rate\]\)
Get or set the coding rate in raw LoRa mode \(`LoRa.LORA`\). The allowed values are: `LoRa.CODING_4_5` \(1\), `LoRa.CODING_4_6` \(2\), `LoRa.CODING_4_7` \(3\) and `LoRa.CODING_4_8` \(4\).
@@ -214,7 +214,7 @@ lora.coding_rate()
lora.coding_rate(LoRa.CODING_4_5)
```
### lora.preamble\(\[preamble\]\)
#### lora.preamble\(\[preamble\]\)
Get or set the number of preamble symbols in raw LoRa mode \(`LoRa.LORA`\):
@@ -226,7 +226,7 @@ lora.preamble()
lora.preamble(LoRa.CODING_4_5)
```
### lora.sf\(\[sf\]\)
#### lora.sf\(\[sf\]\)
Get or set the spreading factor value in raw LoRa mode \(`LoRa.LORA`\). The minimum value is 7 and the maximum is 12:
@@ -238,11 +238,11 @@ lora.sf()
lora.sf(7)
```
### lora.power\_mode\(\[power\_mode\]\)
#### lora.power\_mode\(\[power\_mode\]\)
Get or set the power mode in raw LoRa mode \(`LoRa.LORA`\). The accepted values are: `LoRa.ALWAYS_ON`, `LoRa.TX_ONLY`, and `LoRa.SLEEP`:
### lora.stats\(\)
#### lora.stats\(\)
Return a named tuple with useful information from the last received LoRa or LoRaWAN packet. The named tuple has the following form:
@@ -267,11 +267,11 @@ Where:
* `tx_counter` is the number of packets transmitted.
* `tx_frequency` is the frequency used for the last transmission.
### lora.has\_joined\(\)
#### lora.has\_joined\(\)
Returns `True` if a LoRaWAN network has been joined. `False` otherwise.
### lora.add\_channel\(index, \* , frequency, dr\_min, dr\_max\)
#### lora.add\_channel\(index, \* , frequency, dr\_min, dr\_max\)
Add a LoRaWAN channel on the specified `index`. If theres already a channel with that index it will be replaced with the new one.
@@ -288,7 +288,7 @@ Examples:
lora.add_channel(index=0, frequency=868000000, dr_min=5, dr_max=6)
```
### lora.remove\_channel\(index\)
#### lora.remove\_channel\(index\)
Removes the channel from the specified `index`. On the 868MHz band the channels 0 to 2 cannot be removed, they can only be replaced by other channels using the `lora.add_channel` method. A way to remove all channels except for one is to add the same channel, 3 times on indexes 0, 1 and 2. An example can be seen below:
@@ -298,11 +298,11 @@ lora.remove_channel()
On the 915MHz band there are no restrictions around this.
### lora.mac\(\)
#### lora.mac\(\)
Returns a byte object with the 8-Byte MAC address of the LoRa radio.
### lora.callback\(trigger, handler=None, arg=None\)
#### lora.callback\(trigger, handler=None, arg=None\)
Specify a callback handler for the LoRa radio. The `trigger` types are `LoRa.RX_PACKET_EVENT`, `LoRa.TX_PACKET_EVENT`, and `LoRa.TX_FAILED_EVENT`
@@ -310,7 +310,7 @@ The `LoRa.RX_PACKET_EVENT` event is raised for every received packet. The `LoRa.
An example of how this callback functions can be seen the in method [`lora.events()`](lora.md#lora-events).
### lora.ischannel\_free\(rssi\_threshold\)
#### lora.ischannel\_free\(rssi\_threshold\)
This method is used to check for radio activity on the current LoRa channel, and if the `rssi` of the measured activity is lower than the `rssi_threshold` given, the return value will be `True`, otherwise `False`. Example:
@@ -318,7 +318,7 @@ This method is used to check for radio activity on the current LoRa channel, and
lora.ischannel_free(-100)
```
### lora.set\_battery\_level\(level\)
#### lora.set\_battery\_level\(level\)
Set the battery level value that will be sent when the LoRaWAN MAC command that retrieves the battery level is received. This command is sent by the network and handled automatically by the LoRaWAN stack. The values should be according to the LoRaWAN specification:
@@ -330,7 +330,7 @@ Set the battery level value that will be sent when the LoRaWAN MAC command that
lora.set_battery_level(127) # 50% battery
```
### lora.events\(\)
#### lora.events\(\)
This method returns a value with bits sets \(if any\) indicating the events that have triggered the callback. Please note that by calling this function the internal events registry is cleared automatically, therefore calling it immediately for a second time will most likely return a value of 0.
@@ -347,7 +347,7 @@ def lora_cb(lora):
lora.callback(trigger=(LoRa.RX_PACKET_EVENT | LoRa.TX_PACKET_EVENT), handler=lora_cb)
```
### lora.nvram\_save\(\)
#### lora.nvram\_save\(\)
Save the LoRaWAN state \(joined status, network keys, packet counters, etc\) in non-volatile memory in order to be able to restore the state when coming out of deepsleep or a power cycle.
@@ -355,7 +355,7 @@ Save the LoRaWAN state \(joined status, network keys, packet counters, etc\) in
lora.nvram_save()
```
### lora.nvram\_restore\(\)
#### lora.nvram\_restore\(\)
Restore the LoRaWAN state \(joined status, network keys, packet counters, etc\) from non-volatile memory. State must have been previously stored with a call to `nvram_save` before entering deepsleep. This is useful to be able to send a LoRaWAN message immediately after coming out of deepsleep without having to join the network again. This can only be used if the current region matches the one saved.
@@ -363,7 +363,7 @@ Restore the LoRaWAN state \(joined status, network keys, packet counters, etc\)
lora.nvram_restore()
```
### lora.nvram\_erase\(\)
#### lora.nvram\_erase\(\)
Remove the LoRaWAN state \(joined status, network keys, packet counters, etc\) from non-volatile memory.
@@ -395,7 +395,7 @@ And they must be created after initialising the LoRa network card.
LoRa sockets support the following standard methods from the socket module:
### socket.close\(\)
#### socket.close\(\)
Usage:
@@ -403,7 +403,7 @@ Usage:
s.close()
```
### socket.bind\(port\_number\)
#### socket.bind\(port\_number\)
Usage:
@@ -415,7 +415,7 @@ s.bind(1)
The `bind()` method is only applicable when the radio is configured in `LoRa.LORAWAN` mode.
{% endhint %}
### socket.send\(bytes\)
#### socket.send\(bytes\)
Usage:
@@ -429,7 +429,7 @@ or
s.send('Hello')
```
### socket.recv\(bufsize\)
#### socket.recv\(bufsize\)
Usage:
@@ -437,7 +437,7 @@ Usage:
s.recv(128)
```
### socket.recvfrom\(bufsize\)
#### socket.recvfrom\(bufsize\)
This method is useful to know the destination port number of the message received. Returns a tuple of the form: `(data, port)`
@@ -447,7 +447,7 @@ Usage:
s.recvfrom(128)
```
### socket.setsockopt\(level, optname, value\)
#### socket.setsockopt\(level, optname, value\)
Set the value of the given socket option. The needed symbolic constants are defined in the socket module \(`SO_*` etc.\). In the case of LoRa the values are always integers. Examples:
@@ -466,7 +466,7 @@ s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, True)
Socket options are only applicable when the LoRa radio is used in LoRa.LORAWAN mode. When using the radio in LoRa.LORA mode, use the class methods to change the spreading factor, bandwidth and coding rate to the desired values.
{% endhint %}
### socket.settimeout\(value\)
#### socket.settimeout\(value\)
Sets the socket timeout value in seconds. Accepts floating point values.
@@ -476,7 +476,7 @@ Usage:
s.settimeout(5.5)
```
### socket.setblocking\(flag\)
#### socket.setblocking\(flag\)
Usage:

View File

@@ -23,7 +23,7 @@ The AT commands for the Sequans Monarch modem on the GPy/FiPy are available in a
## Constructors
### class network.LTE\(id=0, ...\)
#### class network.LTE\(id=0, ...\)
Create and configure a LTE object. See init for params of configuration.
@@ -34,27 +34,27 @@ lte = LTE()
## Methods
### lte.init\(\*, carrier=None\)
#### lte.init\(\*, carrier=None\)
This method is used to set up the LTE subsystem. After a `deinit()` this method can take several seconds to return waiting for the LTE modem to start-up. Optionally specify a carrier name. The available options are: `verizon, at&t, standard`. `standard` is generic for any carrier, and it's also the option used when no arguments are given.
### lte.deinit\(\)
#### lte.deinit\(\)
Disables LTE modem completely. This reduces the power consumption to the minimum. Call this before entering deepsleep.
### lte.attach\(\*, band=None\)
#### lte.attach\(\*, band=None\)
Enable radio functionality and attach to the LTE Cat M1 network authorised by the inserted SIM card. Optionally specify the band to scan for networks. If no band \(or `None`\) is specified, all 6 bands will be scanned. The possible values for the band are: `3, 4, 12, 13, 20 and 28`.
### lte.isattached\(\)
#### lte.isattached\(\)
Returns `True` if the cellular mode is attached to the network. `False` otherwise.
### lte.dettach\(\)
#### lte.dettach\(\)
Detach the modem from the LTE Cat M1 and disable the radio functionality.
### lte.connect\(\*, cid=1\)
#### lte.connect\(\*, cid=1\)
Start a data session and obtain and IP address. Optionally specify a CID \(Connection ID\) for the data session. The arguments are:
@@ -81,15 +81,15 @@ while not lte.isconnected():
# Now use sockets as usual...
```
### lte.isconnected\(\)
#### lte.isconnected\(\)
Returns `True` if there is an active LTE data session and IP address has been obtained. `False` otherwise.
### lte.disconnect\(\)
#### lte.disconnect\(\)
End the data session with the network.
### lte.send\_at\_cmd\(cmd\)
#### lte.send\_at\_cmd\(cmd\)
Send an AT command directly to the modem. Returns the raw response from the modem as a string object. **IMPORTANT:** If a data session is active \(i.e. the modem is _connected_\), sending the AT commands requires to pause and then resume the data session. This is all done automatically, but makes the whole request take around 2.5 seconds.
@@ -111,15 +111,15 @@ send_at_cmd_pretty('AT!="showphy"') # get the PHY status
send_at_cmd_pretty('AT!="fsm"') # get the System FSM
```
### lte.imei\(\)
#### lte.imei\(\)
Returns a string object with the IMEI number of the LTE modem.
### lte.iccid\(\)
#### lte.iccid\(\)
Returns a string object with the ICCID number of the SIM card.
### lte.reset\(\)
#### lte.reset\(\)
Perform a hardware reset on the cellular modem. This function can take up to 5 seconds to return as it waits for the modem to shutdown and reboot.

View File

@@ -26,25 +26,25 @@ server.isrunning() # check whether the server is running or not
## Constructors
### class network.Server\(id, ...\)
#### class network.Server\(id, ...\)
Create a server instance, see `init` for parameters of initialisation.
## Methods
### server.init\(\* , login=\('micro', 'python'\), timeout=300\)
#### server.init\(\* , login=\('micro', 'python'\), timeout=300\)
Init \(and effectively start the server\). Optionally a new `user`, `password` and `timeout` \(in seconds\) can be passed.
### server.deinit\(\)
#### server.deinit\(\)
Stop the server.
### server.timeout\(\[timeout\_in\_seconds\]\)
#### server.timeout\(\[timeout\_in\_seconds\]\)
Get or set the server timeout.
### server.isrunning\(\)
#### server.isrunning\(\)
Returns `True` if the server is running \(connected or accepting connections\), `False` otherwise.

View File

@@ -46,7 +46,7 @@ Please ensure that there is an antenna connected to your device before sending/r
## Constructors
### class network.Sigfox\(id=0, ...\)
#### class network.Sigfox\(id=0, ...\)
Create and configure a Sigfox object. See init for params of configuration. Examples:
@@ -64,7 +64,7 @@ sigfox = Sigfox(mode=Sigfox.FSK, frequency=912000000)
## Methods
### sigfox.init\(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1, \* , frequency=None\)
#### sigfox.init\(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1, \* , frequency=None\)
Set the Sigfox radio configuration.
@@ -78,19 +78,19 @@ The arguments are:
The SiPy comes in 2 different hardware flavours: a +14dBm Tx power version which can only work with `RCZ1` and `RCZ3` and a +22dBm version which works exclusively on `RCZ2` and `RCZ4`.
{% endhint %}
### sigfox.mac\(\)
#### sigfox.mac\(\)
Returns a byte object with the 8-Byte MAC address of the Sigfox radio.
### sigfox.id\(\)
#### sigfox.id\(\)
Returns a byte object with the 4-Byte bytes object with the Sigfox ID.
### sigfox.rssi\(\)
#### sigfox.rssi\(\)
Returns a signed integer with indicating the signal strength value of the last received packet.
### sigfox.pac\(\)
#### sigfox.pac\(\)
Returns a byte object with the 8-Byte bytes object with the Sigfox PAC.
@@ -102,11 +102,11 @@ print(ubinascii.hexlify(sigfox.mac()))
```
{% endhint %}
### sigfox.frequencies\(\)
#### sigfox.frequencies\(\)
Returns a tuple of the form: `(uplink_frequency_hz, downlink_frequency_hz)`
### sigfox.public\_key\(\[public\]\)
#### sigfox.public\_key\(\[public\]\)
Sets or gets the public key flag. When called passing a `True` value the Sigfox public key will be used to encrypt the packets. Calling it without arguments returns the state of the flag.
@@ -142,11 +142,11 @@ And they must be created after initialising the Sigfox network card.
Sigfox sockets support the following standard methods from the `socket` module:
### socket.close\(\)
#### socket.close\(\)
Use it to close an existing socket.
### socket.send\(bytes\)
#### socket.send\(bytes\)
In Sigfox mode the maximum data size is 12 bytes. In FSK the maximum is 64.
@@ -158,7 +158,7 @@ s.send(bytes([1, 2, 3]))
s.send('Hello')
```
### socket.recv\(bufsize\)
#### socket.recv\(bufsize\)
This method can be used to receive a Sigfox downlink or FSK message.
@@ -167,7 +167,7 @@ This method can be used to receive a Sigfox downlink or FSK message.
s.recv(64)
```
### socket.setsockopt\(level, optname, value\)
#### socket.setsockopt\(level, optname, value\)
Set the value of the given socket option. The needed symbolic constants are defined in the socket module \(`SO_*` etc.\). In the case of Sigfox the values are always an integer. Examples:

View File

@@ -34,7 +34,7 @@ print(wlan.ifconfig())
## Constructors
### class network.WLAN\(id=0, ...\)
#### class network.WLAN\(id=0, ...\)
Create a WLAN object, and optionally configure it. See [`init`](wlan.md#wlan-init-mode-ssid-none-auth-none-channel-1-antenna-none-power_save-false-hidden-false) for params of configuration.
@@ -44,7 +44,7 @@ The WLAN constructor is special in the sense that if no arguments besides the `i
## Methods
### wlan.init\(mode, \* , ssid=None, auth=None, channel=1, antenna=None, power\_save=False, hidden=False\)
#### wlan.init\(mode, \* , ssid=None, auth=None, channel=1, antenna=None, power\_save=False, hidden=False\)
Set or get the WiFi network processor configuration.
@@ -76,11 +76,11 @@ or
wlan.init(mode=WLAN.STA)
```
### wlan.deinit\(\)
#### wlan.deinit\(\)
Disables the WiFi radio.
### wlan.connect\(ssid, \* , auth=None, bssid=None, timeout=None, ca\_certs=None, keyfile=None, certfile=None, identity=None\)
#### wlan.connect\(ssid, \* , auth=None, bssid=None, timeout=None, ca\_certs=None, keyfile=None, certfile=None, identity=None\)
Connect to a wifi access point using the given SSID, and other security parameters.
@@ -98,19 +98,19 @@ Connect to a wifi access point using the given SSID, and other security paramete
The ESP32 only handles certificates with `pkcs8` format \(but not the "Traditional SSLeay RSAPrivateKey" format\). The private key should be RSA coded with 2048 bits at maximum.
{% endhint %}
### wlan.scan\(\)
#### wlan.scan\(\)
Performs a network scan and returns a list of named tuples with `(ssid, bssid, sec, channel, rssi)`. Note that channel is always `None` since this info is not provided by the WiPy.
### wlan.disconnect\(\)
#### wlan.disconnect\(\)
Disconnect from the WiFi access point.
### wlan.isconnected\(\)
#### wlan.isconnected\(\)
In case of STA mode, returns `True` if connected to a WiFi access point and has a valid IP address. In AP mode returns `True` when a station is connected, `False` otherwise.
### wlan.ifconfig\(id=0, config=\['dhcp' or configtuple\]\)
#### wlan.ifconfig\(id=0, config=\['dhcp' or configtuple\]\)
When `id` is 0, the configuration will be get/set on the Station interface. When `id` is 1 the configuration will be done for the AP interface.
@@ -124,27 +124,27 @@ If the 4-tuple config is given then a static IP is configured. For instance:
wlan.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
```
### wlan.mode\(\[mode\]\)
#### wlan.mode\(\[mode\]\)
Get or set the WLAN mode.
### wlan.ssid\(\[ssid\]\)
#### wlan.ssid\(\[ssid\]\)
Get or set the SSID when in AP mode.
### wlan.auth\(\[auth\]\)
#### wlan.auth\(\[auth\]\)
Get or set the authentication type when in AP mode.
### wlan.channel\(\[channel\]\)
#### wlan.channel\(\[channel\]\)
Get or set the channel \(only applicable in AP mode\).
### wlan.antenna\(\[antenna\]\)
#### wlan.antenna\(\[antenna\]\)
Get or set the antenna type \(external or internal\).
### wlan.mac\(\)
#### wlan.mac\(\)
Get a 6-byte long `bytes` object with the WiFI MAC address.

View File

@@ -15,19 +15,19 @@ pycom.rgbled(0xff00) # make the LED light up in green color
## Methods
### pycom.heartbeat\(\[enable\]\)
#### pycom.heartbeat\(\[enable\]\)
Get or set the state \(enabled or disabled\) of the heartbeat LED. Accepts and returns boolean values \(`True` or `False`\).
### pycom.heartbeat\_on\_boot\(\[enable\]\)
#### pycom.heartbeat\_on\_boot\(\[enable\]\)
Allows you permanently disable or enable the heartbeat LED. Once this setting is set, it will persist between reboots. Note, this only comes into effect on the next boot, it does not stop the already running heartbeat.
### pycom.rgbled\(color\)
#### pycom.rgbled\(color\)
Set the colour of the RGB LED. The colour is specified as 24 bit value representing red, green and blue, where the red colour is represented by the 8 most significant bits. For instance, passing the value `0x00FF00` will light up the LED in a very bright green.
### pycom.nvs\_set\(key, value\)
#### pycom.nvs\_set\(key, value\)
Set the value of the specified key in the NVRAM memory area of the external flash. Data stored here is preserved across resets and power cycles. Value can only take 32-bit integers at the moment. Example:
@@ -38,7 +38,7 @@ pycom.nvs_set('temp', 25)
pycom.nvs_set('count', 10)
```
### pycom.nvs\_get\(key\)
#### pycom.nvs\_get\(key\)
Get the value the specified key from the NVRAM memory area of the external flash. Example:
@@ -50,15 +50,15 @@ pulses = pycom.nvs_get('count')
If a non-existing key is given the returned value will be `None`.
### pycom.nvs\_erase\(key\)
#### pycom.nvs\_erase\(key\)
Erase the given key from the NVRAM memory area.
### pycom.nvs\_erase\_all\(\)
#### pycom.nvs\_erase\_all\(\)
Erase the entire NVRAM memory area.
### pycom.wifi\_on\_boot\(\[enable\]\)
#### pycom.wifi\_on\_boot\(\[enable\]\)
Get or set the WiFi on boot flag. When this flag is set to `True`, the AP with the default SSID \(`lopy-wlan-xxx` for example\) will be enabled as part of the boot process. If the flag is set to False, the module will boot with WiFi disabled until it's enabled by the script via the `WLAN` class. This setting is stored in non-volatile memory which preserves it across resets and power cycles. Example:
@@ -69,7 +69,7 @@ pycom.wifi_on_boot(True) # enable WiFi on boot
pycom.wifi_on_boot() # get the wifi on boot flag
```
### pycom.wdt\_on\_boot\(\[enable\]\)
#### pycom.wdt\_on\_boot\(\[enable\]\)
Enables the WDT at boot time with the timeout in ms set by the function `wdt_on_boot_timeout`. If this flag is set, the application needs to reconfigure the WDT with a new timeout and feed it regularly to avoid a reset.
@@ -80,7 +80,7 @@ pycom.wdt_on_boot(True) # enable WDT on boot
pycom.wdt_on_boot() # get the WDT on boot flag
```
### pycom.wdt\_on\_boot\_timeout\(\[timeout\]\)
#### pycom.wdt\_on\_boot\_timeout\(\[timeout\]\)
Sets or gets the WDT on boot timeout in milliseconds. The minimum value is 5000 ms.
@@ -91,7 +91,7 @@ pycom.wdt_on_boot_timeout(10000) # set the timeout to 5000ms
pycom.wdt_on_boot_timeout() # get the WDT timeout value
```
### pycom.pulses\_get\(pin, timeout\)
#### pycom.pulses\_get\(pin, timeout\)
Return a list of pulses at `pin`. The methods scans for transitions at `pin` and returns a list of tuples, each telling the pin value and the duration in microseconds of that value. `pin` is a pin object, which must have set to `INP` or `OPEN_DRAIN` mode. The scan stops if not transitions occurs within `timeout` milliseconds.
@@ -110,11 +110,11 @@ pin(1)
data = pulses_get(pin, 100)
```
### pycom.ota\_start\(\)
#### pycom.ota\_start\(\)
### pycom.ota\_write\(buffer\)
#### pycom.ota\_write\(buffer\)
### pycom.ota\_finish\(\)
#### pycom.ota\_finish\(\)
Perform a firmware update. These methods are internally used by a firmware update though FTP. The update starts with a call to `ota_start()`, followed by a series of calls to `ota_write(buffer)`, and is terminated with `ota_finish()`. After reset, the new image gets active. `buffer` shall hold the image data to be written, in arbitrary sizes. A block size of 4096 is recommended.

View File

@@ -18,7 +18,7 @@ At the last step of the "Add Device" process:
![](../../.gitbook/assets/8-1.png)
1. Copy the device token.
2. Copy the device token.
### Step 2: Firmware updater
@@ -30,16 +30,17 @@ Install the Firmware updater on your computer.
![](../../.gitbook/assets/2%20%281%29.png)
1. Select your device serial port \(Make sure your device is connected to your computer\);
2. Mark the options "Erase flash file system" and "Force update Pybytes registration";
2. Select your device serial port \(Make sure your device is connected to your computer\);
3. Mark the options "Erase flash file system" and "Force update Pybytes registration";
![](../../.gitbook/assets/3.png)
1. Paste your device token from Pybytes;
4. Paste your device token from Pybytes;
![](../../.gitbook/assets/5-1.gif)
1. The firmware updater will update the device's firmware.
5. The firmware updater will update the device's firmware.
![](../../.gitbook/assets/6%20%281%29.png)

View File

@@ -6,7 +6,7 @@ In this section, we will explain to you how to create widgets for data visualisa
We assume that you already have your device connected to Pybytes. In case you haven't, check how to [add your device here](add-device/). After your done with that, you can proceed to the next example.
{% endhint %}
## Step 1: Set up your application \(main.py\)
## Step 1: Set up your application \(`main.py`\)
The first step is to have an application running on your device. The application in this example sends data from a vector every 10 seconds to Pybytes.
@@ -39,7 +39,7 @@ def send_env_data():
_thread.start_new_thread(send_env_data, ())
```
1. Upload the code into your device. Now your device is sending data to Pybytes.
3. Upload the code into your device. Now your device is sending data to Pybytes.
{% hint style="info" %}
@@ -57,19 +57,19 @@ Go to Pybytes.
![](../.gitbook/assets/01%20%281%29.gif)
1. On your device's page click on `Data` tab.
2. On your device's page click on `Data` tab.
![](../.gitbook/assets/02-1.png)
1. Click on the `Define New Signal` button.
3. Click on the `Define New Signal` button.
![](../.gitbook/assets/03-1.png)
1. Define the new signal by entering a number, a name, a data type and a unit. Finally, click on the button `Define`.
4. Define the new signal by entering a number, a name, a data type and a unit. Finally, click on the button `Define`.
![](../.gitbook/assets/04-1.gif)
1. Your signal was added!
5. Your signal was added!
![](../.gitbook/assets/05%20%281%29.png)
@@ -87,27 +87,27 @@ The datatype also has to match the variable used as argument on `pybytes.send_vi
![](../.gitbook/assets/01.png)
1. Click on the button `Create a new display`.
2. Click on the button `Create a new display`.
![](../.gitbook/assets/02-1%20%281%29.png)
1. Select the type of visualisation \(e.g. Bar chart or Line chart\).
3. Select the type of visualisation \(e.g. Bar chart or Line chart\).
![](../.gitbook/assets/03.gif)
1. You can adjust the parameters of your widget at `Settings`. After, click on the button `Create`.
4. You can adjust the parameters of your widget at `Settings`. After, click on the button `Create`.
![](../.gitbook/assets/04-1.png)
1. Your widget was created. Now, add your widget to your device's dashboard. Click on the button `Edit` on your widget.
5. Your widget was created. Now, add your widget to your device's dashboard. Click on the button `Edit` on your widget.
![](../.gitbook/assets/05-1.png)
1. Mark the checkbox `Display on Dashboard` at `Settings`. Finally, click on the button `Save`.
6. Mark the checkbox `Display on Dashboard` at `Settings`. Finally, click on the button `Save`.
![](../.gitbook/assets/06.gif)
1. Click on the tab `Dashboard`. Your widget was successfully added there!
7. Click on the tab `Dashboard`. Your widget was successfully added there!
![](../.gitbook/assets/07.png)
@@ -117,11 +117,11 @@ The datatype also has to match the variable used as argument on `pybytes.send_vi
![](../.gitbook/assets/edit-mode%20%281%29.gif)
1. Resize a widget by clicking on the triangle icon at the bottom right corner of the widget and drag the cursor over the grid. After, click on the button `Save` to save this action.
2. Resize a widget by clicking on the triangle icon at the bottom right corner of the widget and drag the cursor over the grid. After, click on the button `Save` to save this action.
![](../.gitbook/assets/02-1.gif)
1. Change the widget's position by drag-and-dropping it over the grid. After, click on the button `Save` to save this action.
3. Change the widget's position by drag-and-dropping it over the grid. After, click on the button `Save` to save this action.
![](../.gitbook/assets/03-1.gif)

View File

@@ -8,19 +8,19 @@ Please follow these steps to install the Pymakr Plugin:
![](../../.gitbook/assets/atom_setup_step_1-1.png)
1. Navigate to the Install page, via `Atom > Preferences > Install`
2. Navigate to the Install page, via `Atom > Preferences > Install`
![](../../.gitbook/assets/atom_setup_step_2-1.png)
1. Search for `Pymakr` and select the official Pycom Pymakr Plugin.
3. Search for `Pymakr` and select the official Pycom Pymakr Plugin.
![](../../.gitbook/assets/atom_setup_step_3-1.png)
1. You should now see and click the Install button. This will download and install the Pymakr Plugin.
4. You should now see and click the Install button. This will download and install the Pymakr Plugin.
![](../../.gitbook/assets/atom_setup_step_4-1.png)
1. Thats it! Youve installed the Pymakr Plugin for Atom.
5. Thats it! Youve installed the Pymakr Plugin for Atom.
![](../../.gitbook/assets/atom_setup_step_5-1.png)
@@ -36,23 +36,23 @@ After installing the Pymakr Plugin, you need to take a few seconds to configure
![](../../.gitbook/assets/atom_config_step_2-1.png)
1. Open the Pymakr console by clicking the `^` button, located in the lower right side of the Atom window.
3. Open the Pymakr console by clicking the `^` button, located in the lower right side of the Atom window.
![](../../.gitbook/assets/atom_config_step_3%20%281%29.png)
1. Click, `More` followed by `Get Serial Ports`. This will copy the serial address of your expansion board to your clipboard.
4. Click, `More` followed by `Get Serial Ports`. This will copy the serial address of your expansion board to your clipboard.
![](../../.gitbook/assets/atom_config_step_4.png)
1. Navigate to `Settings > Global Settings`
5. Navigate to `Settings > Global Settings`
![](../../.gitbook/assets/atom_config_step_5.png)
1. Paste the serial address you copied earlier into the text field `Device Address`
6. Paste the serial address you copied earlier into the text field `Device Address`
![](../../.gitbook/assets/atom_config_step_6%20%281%29.png)
1. Press connect and the Pymakr console should show three arrows `>>>`, indicating that you are connected
7. Press connect and the Pymakr console should show three arrows `>>>`, indicating that you are connected
![](../../.gitbook/assets/atom_config_step_7%20%281%29.png)

View File

@@ -10,19 +10,19 @@ Please follow these steps to install the Pymakr VSCode Extension:
![](../../.gitbook/assets/vsc_setup_step_1-1.png)
1. Navigate to the Extensions page, using the 5th button in the left navigation
2. Navigate to the Extensions page, using the 5th button in the left navigation
![](../../.gitbook/assets/vsc_setup_step_2-1.png)
1. Search for `Pymakr` and click the install button next to it.
3. Search for `Pymakr` and click the install button next to it.
![](../../.gitbook/assets/vsc_setup_step_3.png)
1. Within a few minutes, a reload button should appear. Press it to reload VSCode.
4. Within a few minutes, a reload button should appear. Press it to reload VSCode.
![](../../.gitbook/assets/vsc_setup_step_4.png)
1. Thats it! Youve installed the Pymakr Extension for VSCode
5. Thats it! Youve installed the Pymakr Extension for VSCode
![](../../.gitbook/assets/vsc_setup_step_5%20%281%29.png)
@@ -40,23 +40,23 @@ After installing the Pymakr Plugin, you need to take a few seconds to configure
![](../../.gitbook/assets/vsc_config_step_1-1.png)
1. Click `All commands` on the bottom of the Visual Studio Code window
3. Click `All commands` on the bottom of the Visual Studio Code window
![](../../.gitbook/assets/vsc_config_step_2-1.png)
1. In the list that appears, click `Pymakr > Extra > List Serial Ports`
4. In the list that appears, click `Pymakr > Extra > List Serial Ports`
![](../../.gitbook/assets/vsc_config_step_3-1.png)
1. This will list the available serial ports. If Pymakr is able to auto-detect which to use, this will be copied to your clipboard. If not please manually copy the correct serial port.
5. This will list the available serial ports. If Pymakr is able to auto-detect which to use, this will be copied to your clipboard. If not please manually copy the correct serial port.
![](../../.gitbook/assets/vsc_config_step_4.png)
1. Once again click `All commands`, then click `Pymakr > Global Settings`. This will open a JSON file. Paste the serial address you copied earlier into the field `address` and save the file.
6. Once again click `All commands`, then click `Pymakr > Global Settings`. This will open a JSON file. Paste the serial address you copied earlier into the field `address` and save the file.
![](../../.gitbook/assets/vsc_config_step_5-1.png)
1. Finally close the JSON file, click `All commands`, then `Pymakr > Connect` to connect your device. The Pymakr console should show three arrows `>>>`, indicating that you are connected
7. Finally close the JSON file, click `All commands`, then `Pymakr > Connect` to connect your device. The Pymakr console should show three arrows `>>>`, indicating that you are connected
![](../../.gitbook/assets/vsc_config_step_6%20%281%29.png)

View File

@@ -44,11 +44,11 @@ py.go_to_sleep()
## Methods
### pytrack.get\_sleep\_remaining\(\)
#### pytrack.get\_sleep\_remaining\(\)
In the event of a sleep session that was awoken by an asynchronous event \(Accelerometer, INT pin or Reset button\) the approximate sleep remaining interval \(expressed in **seconds**\) can be found out. The user has to manually use `setup_sleep()` to configure the next sleep interval.
### pytrack.get\_wake\_reason\(\)
#### pytrack.get\_wake\_reason\(\)
Returns the last wakeup reason. Possible values are:
@@ -63,13 +63,13 @@ _Note: the_ `WAKE_REASON_INT_PIN` _can be used if the_ `PIC_RC1` _pin \(pin\#6 o
As in the above example, this method should be called at the beginning of the script, to find out the reset \(wakeup\) reason.
### pytrack.go\_to\_sleep\(\[gps=True\]\)
#### pytrack.go\_to\_sleep\(\[gps=True\]\)
Puts the board in sleep mode, for the duration, which has to be set previously with `pytrack.setup_sleep(timout_sec)`. The optional boolean parameter sets the GPS state during sleep.
MicroPython code, which is after this function, is not executed, as wakeup will restart MicroPython.
### pytrack.setup\_int\_wake\_up\(rising, falling\]\)
#### pytrack.setup\_int\_wake\_up\(rising, falling\]\)
Enables as wakeup source, the accelerometer INT pin \(PIC - RA5\). The boolean parameters will indicate rising edge \(activity detection\) and/or falling edge \(inactivity detection\) is configured.
@@ -89,11 +89,11 @@ py.setup_int_wake_up(True, True)
acc.enable_activity_interrupt(2000, 200)
```
### pytrack.setup\_int\_pin\_wake\_up\(\[rising\_edge = True\]\)
#### pytrack.setup\_int\_pin\_wake\_up\(\[rising\_edge = True\]\)
Enables as wakeup source, the INT pic \(PIC - RC1, pin\#6 on External IO Header\). Either rising or falling edge has to be set, by default it's rising edge.
### pytrack.setup\_sleep\(time\_seconds\)
#### pytrack.setup\_sleep\(time\_seconds\)
Sets the sleep interval, specified in seconds. The actual sleep will be started by calling `go_to_sleep()` method.

View File

@@ -96,4 +96,11 @@ while(True):
The node is always sending packages and waiting for the `ack` from the gateway.
{% hint style="info" %}
To adapt this code to user specific needs:
* Put a max waiting time for the `ack` to arrive and resend the package or mark it as invalid
* Increase the package size changing the `_LORA_PKG_FORMAT` to `BH%ds`. The `H` will allow the keeping of 2 bytes for size \(for more information about [struct format](https://docs.python.org/2/library/struct.html#format-characters)\)
* Reduce the package size with bitwise manipulation
* Reduce the message size \(for this demo, a string\) to something more useful for specific development
{% endhint %}