def input_line(s): res = bytearray() s.read(s.available()) while True: if s.available() < 1: sfw.kick() sleep(1) continue c = s.read()[0] if c == __ORD('\r') or c == __ORD('\n'): break if c == __ORD('\b') and len(res) > 0: del res[-1] print('\b ', sep='', end='') else: res.append(c) print(chr(c), sep='', end='') print() return str(res)
def do_modem_passthru(s): print("Modem passthrough...[^ to exit]") modem.bypass(1) ms = streams.serial(polaris.gsm.SERIAL, baud=115200, set_default=False) ms.write('ATE1\r') while True: sfw.kick() # modem to stream n = ms.available() if n > 0: s.write(ms.read(n)) # stream to modem n = s.available() if n > 0: b = s.read(n) if n == 1 and b[0] == __ORD('^'): break ms.write(b) else: sleep(1) ms.write('ATE0\r') modem.bypass(0)
print("Starting Accelerometer...") import accel accel.start() print("Starting GNSS...") gnss.start() gnss.set_rate(2000) print("Starting Modem...") modem.startup() # enable modem/gnss utilities utils.modem = modem utils.gnss = gnss sfw.watchdog(0, 30000) sfw.kick() if utils.check_terminal(s): utils.do_terminal(s) minfo = gsm.mobile_info() print("Modem:", minfo) # enable SMS checking utils.check_sms = True except Exception as e: print("Failed init hw with", e) sleep(500) mcu.reset() # GATHERING SETTINGS
def write(self, packet): gpio.high(RS485EN) self.port.write(packet) gpio.low(RS485EN) sfw.kick()
def read(self): gpio.low(RS485EN) bc = self.port.available() sfw.kick() return self.port.read(bc)
def get_packets(sleep_time, iterations_per_channel, activity_percentage, scan_time_interval): print("Sniffing...") count = 0 while True: sfw.kick() payloads = [] if count % 60 == 0: print("Initializing RTC") init_rtc() sfw.kick() count = (count + 1) % 60 # If timer has reached the interval, perform another scan if t.get() >= scan_time_interval: t.reset() print() scan_for_active_channels(1000, 2) # Else, get packets else: try: for channel in range(1, number_of_channels + 1): print("Checking channel", channel) if channel_activity_stats[channel - 1] >= activity_percentage: print("Starting sniffer on channel", channel) wifi_driver.start_sniffer( packet_types=[wifi_driver.WIFI_PKT_MGMT], channels = [channel], mgmt_subtypes=[wifi_driver.WIFI_PKT_MGMT_PROBE_REQ], direction = wifi_driver.WIFI_DIR_TO_NULL_FROM_NULL, pkt_buffer=32, max_payloads=0, hop_time=2000) print("Start acquisition for", iterations_per_channel, "seconds") for iteration in range(iterations_per_channel): print(gc.info()) # Sleep for a given time sleep(sleep_time) # Sniff packets pkts = wifi_driver.sniff() now = rtc.get_utc() for pkt in pkts: payloads.append({ 'scanner_id': mac_addr, 'type': pkt[0], 'subtype': pkt[1], 'mac1': pkt[7], 'mac2': pkt[8], 'mac3': pkt[9], 'mac4': pkt[10], 'rssi': pkt[11], 'channel': pkt[12], 'timestamp': now.tv_seconds + (now.tv_microseconds/1000000) #mantenere solo i secondi }) print("Sniffed", len(pkts), "in channel", channel) # Stop sniffer print("STOP") wifi_driver.stop_sniffer() sfw.kick() print("STOPPED") sleep(500) print("Connecting to Wi-Fi network") try: sfw.kick() for j in range(3): try: wifi.link(SSID, wifi.WIFI_WPA2, PASSWORD) break except Exception as e: print("Can't link",e) sleep(100) else: mcu.reset() sleep(100) sleep(100) print(gc.info()) print("Storing", len(payloads), "packets in database") sfw.kick() page = 0 page_size = 5 page_num = math.ceil(len(payloads) / page_size) device.connect() page = 0 page_size = 5 page_num = math.ceil(len(payloads) / page_size) while page < page_num: print(page + 1, "/", page_num) for j in range(3): try: data=json.dumps({"data":payloads[page*page_size:(page+1)*page_size]}) device.publish(data,TAG) break except Exception as e: print("Can't post data",e) sleep(100) else: mcu.reset() page = page + 1 sfw.kick() sleep(5000) wifi.unlink() except Exception as e: print("Error!", e) sleep(100) except Exception as e: print("Error while sniffing:", e)