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.
When operating in
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:
for i in range(1, 100): # send something s.send('Hello ' + str(i))
There will be a 20 second delay after every 2 packets.
This class provides a driver for the Sigfox network processor in the Sigfox enabled Pycom devices.
from network import Sigfox import socket # init Sigfox for RCZ1 (Europe) sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) # create a Sigfox socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) # make the socket blocking s.setblocking(True) # configure it as uplink only s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) # send some bytes s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]))
Please ensure that there is an antenna connected to your device before sending/receiving Sigfox messages as in proper use (e.g. without an antenna), may damage the device.
Create and configure a Sigfox object. See init for params of configuration. Examples:
# configure radio for the Sigfox network, using RCZ1 (868 MHz) sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) # configure radio for FSK, device to device across 912 MHz sigfox = Sigfox(mode=Sigfox.FSK, frequency=912000000)
Sigfox.FSKmode is not supported on LoPy 4 and FiPy.
Set the Sigfox radio configuration.
The arguments are:
modecan be either
Sigfox.SIGFOXuses the Sigfox modulation and protocol while
Sigfox.FSKallows to create point to point communication between 2 Devices using FSK modulation. Note:
Sigfox.FSKmode is not supported on LoPy 4 and FiPy.
rcztakes the following values:
rczargument is only required if the mode is
frequencysets the frequency value in
FSKmode. Can take values between 863 and 928 MHz. The SiPy comes in 2 different hardware flavours: a +14dBm Tx power version which can only work with
RCZ3and a +22dBm version which works exclusively on
Returns a byte object with the 8-Byte MAC address of the Sigfox radio.
Returns a byte object with the 4-Byte bytes object with the Sigfox ID.
Returns a signed integer with indicating the signal strength value of the last received packet.
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:
Returns a tuple of the form:
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. The public key is used in SigFox testing / certification and can not be used for encryption purposes.
# enable encrypted packets sigfox.public_key(True) # return state of public_key sigfox.public_key()
SIGFOXto specify usage of the Sigfox Public Network.
FSKto specify device to device communication.
RCZ1to specify Europe, Oman & South Africa.
RCZ2for the USA, Mexico & Brazil.
RCZ4for Australia, New Zealand, Singapore, Taiwan, Hong Kong, Colombia & Argentina.
Sigfox sockets are created in the following way:
import socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
And they must be created after initialising the Sigfox network card.
Sigfox sockets support the following standard methods from the
Use it to close an existing socket.
In Sigfox mode the maximum data size is 12 bytes. In FSK the maximum is 64.
# send a Sigfox payload of bytes s.send(bytes([1, 2, 3])) # send a Sigfox payload containing a string s.send('Hello')
This method can be used to receive a Sigfox downlink or FSK message.
# size of buffer should be passed for expected payload, e.g. 64 bytes s.recv(64)
Set the value of the given socket option. For the Sigfox level, the following options are available (all options accept the values
SO_RX: Wait for a downlink after sending the uplink packet
SO_OOB: Use the socket to send a Sigfox Out Of Band (OOB) message
SO_BIT: Select the bit value when sending bit-only packets
# wait for a downlink after sending the uplink packet s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, True)
Sending a Sigfox packet with a single bit is achieved by sending an empty string, i.e.:
import socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) # send 1 bit s.setsockopt(socket.SOL_SIGFOX, socket.SO_BIT, True) s.send('') socket.settimeout(value) # set timeout for the socket, e.g. 5 seconds s.settimeout(5.0) socket.setblocking(flag) # specifies if socket should be blocking based upon Boolean flag. s.setblocking(True)
If the socket is set to blocking, your code will be wait until the socket completes sending/receiving.
For additional information about sockets, take a look at the usockets API