mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 08:06:34 +01:00
GitBook: [master] 105 pages and 326 assets modified
This commit is contained in:
committed by
gitbook-bot
parent
7f83446ce9
commit
764a0073d6
@@ -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 won’t 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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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 there’s 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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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,13 +64,13 @@ 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.
|
||||
|
||||
The arguments are:
|
||||
|
||||
* `mode` can be either `Sigfox.SIGFOX` or `Sigfox.FSK`. `Sigfox.SIGFOX` uses the Sigfox modulation and protocol while `Sigfox.FSK` allows to create point to point communication between 2 Devices using FSK modulation. _Note: `Sigfox.FSK` mode is not supported on LoPy 4 and FiPy._
|
||||
* `mode` can be either `Sigfox.SIGFOX` or `Sigfox.FSK`. `Sigfox.SIGFOX` uses the Sigfox modulation and protocol while `Sigfox.FSK` allows to create point to point communication between 2 Devices using FSK modulation. _Note:_ `Sigfox.FSK` _mode is not supported on LoPy 4 and FiPy._
|
||||
* `rcz` takes the following values: `Sigfox.RCZ1`, `Sigfox.RCZ2`, `Sigfox.RCZ3`, `Sigfox.RCZ4`. The `rcz` argument is only required if the mode is `Sigfox.SIGFOX`.
|
||||
* `frequency` sets the frequency value in `FSK` mode. Can take values between 863 and 928 MHz.
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -154,5 +154,3 @@ Get a 6-byte long `bytes` object with the WiFI MAC address.
|
||||
* WLAN network security: `WLAN.WEP`, `WLAN.WPA`, `WLAN.WPA2`, `WLAN.WPA2_ENT`
|
||||
* Antenna type: `WLAN.INT_ANT`, `WLAN.EXT_ANT`
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user