Пример #1
0
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=RCZ)
print("sigfox version:", sigfox.version())
print("sigfox ID:", ubinascii.hexlify(sigfox.id()))
print("sigfox PAC:", ubinascii.hexlify(sigfox.pac()))
print("sigfox region:", RCZ)
print("sigfox frequencies:", sigfox.frequencies())
print("sigfox rssi offset:", sigfox.rssi_offset())
# sigfox config
rcz3_config_test_mode = (
    1, 0x2ee0, 0x100
)  # ie, 1 retry, 12sec timeout, 3rd config is always ignored in R3
# rcz3_config_default = (3,   5000, 0x100) # ie, 3 retries, 5sec timeout
print("sigfox config:", sigfox.config())

# by default put the device into private key mode
sigfox.public_key(False)
print("sigfox public key:", sigfox.public_key())

s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
s.setblocking(True)
# by default configure socket as uplink only
# print("socket:", "uplink only")
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)

print("test:", test)
################################################################################

wait = 24  # how many seconds do we need to wait after every second packet (starting after the first) in RCZ2 and 4
last = -wait  # when was the last sigfox message sent. init to -wait, so we don't wait for the first packet
rgb_send = 0x110000
rgb_idle = 0x000a00
def th_send_sigfox(payload):
    # make the socket blocking
    s.setblocking(True)
    # Uplink + Downlink : Send then receive a reply from the network
    s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, True)
    output = s.send(payload)
    print("-- thread -- Message sent. Total size: ", output, " bytes")
    # response declared in global scope
    global response
    response = s.recv(8)


# init Sigfox for RCZ4
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ4)
# set sigfox Network Emulator Public Key
sigfox.public_key(True)

# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)

print('I am device ', binascii.hexlify(sigfox.id()))

message = bytes(
    [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x50, 0x79, 0x63, 0x6F, 0x6D, 0x21])
response = bytes()

# create new thread to manage message TX&RX
_thread.start_new_thread(th_send_sigfox, (message, ))

print("Here we run our main tasks while waiting for sigfox tx and rx...")
# loop will run for 50 sec max and stop once downlink is received