mirror of
https://github.com/sascha-hemi/pycom-documentation.git
synced 2026-03-21 07:06:20 +01:00
moved to single repos
This commit is contained in:
@@ -5,14 +5,16 @@ aliases:
|
||||
- firmwareapi/pycom/network/sigfox.md
|
||||
- chapter/firmwareapi/pycom/network/sigfox
|
||||
---
|
||||
|
||||
Sigfox is a Low Power Wide Area Network protocol that enables remote devices to connect using ultra-narrow band, UNB technology. The protocol is bi-directional, messages can both be sent up to and down from the Sigfox servers.
|
||||
|
||||
{{% hint style="info" %}}
|
||||
When operating in `RCZ2` and `RCZ4` the module can only send messages on the default macro-channel (this is due to Sigfox network limitations). Therefore, the device needs to reset automatically to the default macro-channel after every 2 transmissions. However, due to FCC duty cycle limitations, there must a minimum of a 20s delay after resetting to the default macro-channel. Our API takes care of this, (and in real life applications you should not be in the need to send Sigfox messages that often), so it will wait for the necessary amount of time to make sure that the duty cycle restrictions are fulfilled.
|
||||
When operating in RCZ2 and RCZ4 the module can only send messages on the default macro-channel (this is due to Sigfox network limitations). Therefore, the device needs to reset automatically to the default macro-channel after every 2 transmissions. However, due to FCC duty cycle limitations, there must a minimum of a 20s delay after resetting to the default macro-channel. Our API takes care of this, (and in real life applications you should not be in the need to send Sigfox messages that often), so it will wait for the necessary amount of time to make sure that the duty cycle restrictions are fulfilled.
|
||||
|
||||
This means that if you run a piece of test code like:
|
||||
|
||||
```python
|
||||
|
||||
for i in range(1, 100):
|
||||
# send something
|
||||
s.send('Hello ' + str(i))
|
||||
@@ -26,6 +28,7 @@ This class provides a driver for the Sigfox network processor in the Sigfox enab
|
||||
## Quick Usage Example
|
||||
|
||||
```python
|
||||
|
||||
from network import Sigfox
|
||||
import socket
|
||||
|
||||
@@ -56,6 +59,7 @@ Please ensure that there is an antenna connected to your device before sending/r
|
||||
Create and configure a Sigfox object. See init for params of configuration. Examples:
|
||||
|
||||
```python
|
||||
|
||||
# configure radio for the Sigfox network, using RCZ1 (868 MHz)
|
||||
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
|
||||
|
||||
@@ -64,7 +68,7 @@ sigfox = Sigfox(mode=Sigfox.FSK, frequency=912000000)
|
||||
```
|
||||
|
||||
{{% hint style="info" %}}
|
||||
`Sigfox.FSK` mode is not supported on LoPy 4 and FiPy.
|
||||
Sigfox.FSK mode is not supported on LoPy 4 and FiPy.
|
||||
{{< /hint >}}
|
||||
|
||||
## Methods
|
||||
@@ -103,6 +107,7 @@ Returns a byte object with the 8-Byte bytes object with the Sigfox PAC.
|
||||
To return human-readable values you should import `ubinascii` and convert binary values to hexidecimal representation. For example:
|
||||
|
||||
```python
|
||||
|
||||
print(ubinascii.hexlify(sigfox.mac()))
|
||||
```
|
||||
{{< /hint >}}
|
||||
@@ -116,6 +121,7 @@ Returns a tuple of the form: `(uplink_frequency_hz, downlink_frequency_hz)`
|
||||
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.
|
||||
|
||||
```python
|
||||
|
||||
# enable encrypted packets
|
||||
sigfox.public_key(True)
|
||||
|
||||
@@ -139,6 +145,7 @@ sigfox.public_key()
|
||||
Sigfox sockets are created in the following way:
|
||||
|
||||
```python
|
||||
|
||||
import socket
|
||||
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
|
||||
```
|
||||
@@ -156,6 +163,7 @@ Use it to close an existing socket.
|
||||
In Sigfox mode the maximum data size is 12 bytes. In FSK the maximum is 64.
|
||||
|
||||
```python
|
||||
|
||||
# send a Sigfox payload of bytes
|
||||
s.send(bytes([1, 2, 3]))
|
||||
|
||||
@@ -168,6 +176,7 @@ s.send('Hello')
|
||||
This method can be used to receive a Sigfox downlink or FSK message.
|
||||
|
||||
```python
|
||||
|
||||
# size of buffer should be passed for expected payload, e.g. 64 bytes
|
||||
s.recv(64)
|
||||
```
|
||||
@@ -177,6 +186,7 @@ s.recv(64)
|
||||
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:
|
||||
|
||||
```python
|
||||
|
||||
# wait for a downlink after sending the uplink packet
|
||||
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, True)
|
||||
|
||||
@@ -196,6 +206,7 @@ s.setsockopt(socket.SOL_SIGFOX, socket.SO_BIT, False)
|
||||
Sending a Sigfox packet with a single bit is achieved by sending an empty string, i.e.:
|
||||
|
||||
```python
|
||||
|
||||
import socket
|
||||
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
|
||||
|
||||
@@ -217,12 +228,14 @@ If the socket is set to blocking, your code will be wait until the socket comple
|
||||
A Sigfox capable Pycom devices (SiPy) can both send and receive data from the Sigfox network. To receive data, a message must first be sent up to Sigfox, requesting a downlink message. This can be done by passing a `True` argument into the `setsockopt()` method.
|
||||
|
||||
```python
|
||||
|
||||
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, True)
|
||||
```
|
||||
|
||||
An example of the downlink procedure can be seen below:
|
||||
|
||||
```python
|
||||
|
||||
# init Sigfox for RCZ1 (Europe)
|
||||
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
|
||||
|
||||
@@ -247,12 +260,13 @@ s.recv(32)
|
||||
To communicate between two Sigfox capable devices, it may be used in FSK mode. Two devices are required to be set to the same frequency, both using FSK.
|
||||
|
||||
{{% hint style="info" %}}
|
||||
`Sigfox.FSK` mode is not supported on LoPy 4 and FiPy.
|
||||
Sigfox.FSK mode is not supported on LoPy 4 and FiPy.
|
||||
{{< /hint >}}
|
||||
|
||||
**Device 1**:
|
||||
|
||||
```python
|
||||
|
||||
sigfox = Sigfox(mode=Sigfox.FSK, frequency=868000000)
|
||||
|
||||
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
|
||||
@@ -267,6 +281,7 @@ while True:
|
||||
**Device 2**:
|
||||
|
||||
```python
|
||||
|
||||
sigfox = Sigfox(mode=Sigfox.FSK, frequency=868000000)
|
||||
|
||||
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
|
||||
|
||||
Reference in New Issue
Block a user