|
| 1 | +from network import Sigfox |
| 2 | +from network import LoRa |
| 3 | +import socket |
| 4 | +import machine |
| 5 | +import time |
| 6 | + |
| 7 | +hop_num = 68 |
| 8 | +start_freq = 863000000 |
| 9 | +end_freq = 870000000 |
| 10 | + |
| 11 | +lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868) |
| 12 | +sigfox = None |
| 13 | + |
| 14 | +sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW) |
| 15 | +sock.setblocking(False) |
| 16 | + |
| 17 | +def select_new_frequency(): |
| 18 | + global hop_num |
| 19 | + global start_freq |
| 20 | + |
| 21 | + r_num = (machine.rng() % hop_num) + 1 |
| 22 | + hop = r_num * 100000 |
| 23 | + frequency = start_freq + hop |
| 24 | + return frequency |
| 25 | + |
| 26 | +def sock_send_repeat(packt_len, num_packts, delay_secs, fhss=False): |
| 27 | + global sock |
| 28 | + global lora |
| 29 | + |
| 30 | + if delay_secs <= 0: |
| 31 | + delay_secs = 0.1 |
| 32 | + |
| 33 | + for i in range(num_packts): |
| 34 | + packet = bytes([machine.rng() & 0xFF for b in range(packt_len)]) |
| 35 | + print("Sending packet number {}: {}".format(i, packet)) |
| 36 | + if fhss: |
| 37 | + lora.frequency(select_new_frequency()) |
| 38 | + sock.send(packet) |
| 39 | + time.sleep(delay_secs) |
| 40 | + |
| 41 | +def sock_send_all_channels(packt_len, delay_secs=0.1): |
| 42 | + global sock |
| 43 | + global lora |
| 44 | + global start_freq |
| 45 | + global end_freq |
| 46 | + |
| 47 | + start = start_freq |
| 48 | + end = end_freq |
| 49 | + |
| 50 | + if delay_secs <= 0: |
| 51 | + delay_secs = 0.1 |
| 52 | + |
| 53 | + for i in range((end - start) / 100000): |
| 54 | + packet = bytes([machine.rng() & 0xFF for b in range(packt_len)]) |
| 55 | + print("Sending packet number {}: {}".format(i, packet)) |
| 56 | + lora.frequency(start + (i * 100000)) |
| 57 | + sock.send(packet) |
| 58 | + time.sleep(delay_secs) |
| 59 | + |
| 60 | +def start_test_fcc(): |
| 61 | + global sigfox |
| 62 | + global lora |
| 63 | + global start_freq |
| 64 | + global end_freq |
| 65 | + global hop_num |
| 66 | + |
| 67 | + sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ2) |
| 68 | + lora = LoRa(mode=LoRa.LORA, region=LoRa.US915) |
| 69 | + start_freq = 902000000 |
| 70 | + end_freq = 928000000 |
| 71 | + hop_num = 258 |
| 72 | + |
| 73 | +def start_test_rcm(): |
| 74 | + global sigfox |
| 75 | + global lora |
| 76 | + global start_freq |
| 77 | + global end_freq |
| 78 | + global hop_num |
| 79 | + |
| 80 | + sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ4) |
| 81 | + lora = LoRa(mode=LoRa.LORA, region=LoRa.AU915) |
| 82 | + start_freq = 915000000 |
| 83 | + end_freq = 928000000 |
| 84 | + hop_num = 128 |
| 85 | + |
| 86 | +def start_test_ce(): |
| 87 | + global sigfox |
| 88 | + global lora |
| 89 | + global start_freq |
| 90 | + global end_freq |
| 91 | + global hop_num |
| 92 | + |
| 93 | + sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) |
| 94 | + lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868) |
| 95 | + start_freq = 863000000 |
| 96 | + end_freq = 870000000 |
| 97 | + hop_num = 68 |
| 98 | + |
| 99 | +def do_freq_hopping_fcc(): |
| 100 | + global sigfox |
| 101 | + |
| 102 | + frequency = 902200000 + 25000 |
| 103 | + |
| 104 | + while frequency < 904700000: |
| 105 | + sigfox.test_mode(8, frequency) |
| 106 | + frequency += 25000 |
| 107 | + |
| 108 | + |
| 109 | +def do_freq_hopping_rcm(): |
| 110 | + global sigfox |
| 111 | + |
| 112 | + frequency = 915000000 + 25000 |
| 113 | + |
| 114 | + while frequency < 928000000: |
| 115 | + sigfox.test_mode(8, frequency) |
| 116 | + frequency += 25000 |
| 117 | + |
| 118 | + |
| 119 | +def do_freq_hopping_ce(): |
| 120 | + global sigfox |
| 121 | + |
| 122 | + frequency = 863000000 + 100000 |
| 123 | + |
| 124 | + while frequency < 870000000: |
| 125 | + sigfox.test_mode(8, frequency) |
| 126 | + frequency += 100000 |
| 127 | + |
| 128 | + |
| 129 | +def do_continuos_transmit(frequency): |
| 130 | + global sigfox |
| 131 | + |
| 132 | + while True: |
| 133 | + sigfox.test_mode(8, frequency) |
| 134 | + time.sleep_ms(5) |
| 135 | + |
| 136 | +print() |
| 137 | +print("*** LoRa/Sigfox radio setup complete, ready to test ***") |
| 138 | +print() |
0 commit comments