Search the Community
Showing results for tags 'micropython'.
-
Kāds iepriekš ieminējās ka būtu lietderīgi izveidot Arduino (u.c.) sadaļu, kurā biedri varētu padalīties ar saviem bezjēdzīgajiem projektiem. Ja admini to izdarītu būtu lieliski. Šodien aiz neko darīt iesāku spēlēties ar Lora moduļiem, lai paskatītos cik tālu pilsētas vidē Lora darbojas. Tākā pašam sava gateway pagaidām nav, tad doma ir nolikt mājā vienu moduli un tad uztaisīt otru, kuram būtu gps, tad staigāt pa pilsētu un sūtīt koordinātas uz pirmo. Kā moduļus izmantoju LoPy moduļus, kuri pa lielam ir ESP32 uz kura uzlikts MicroPython + Semtech SX1272 Lora radio. Saliku savu "hi-tec" mobilo staciju un uzrakstiju nelielu skriptu. Datus pārsūta, bet slinkums šodien iet staigāt pa pilsētu, jāatliek uz nākamnedēļu, plus jāuztaisa kautkādu weblapu ar karti kur atzīmēt koordinātas. Datu sūtītājs import time import _thread import os import socket import struct from network import LoRa from machine import UART class Queue(): def __init__(self, size): self.size = size self.lock = _thread.allocate_lock() self.data = list() def push(self, item): with self.lock: if len(self.data) < self.size: self.data.append(item) def len(self): with self.lock: return len(self.data) def pop(self): with self.lock: if len(self.data) > 0: return self.data.pop(0) return None class Application(): def __init__(self): self.gpsMessages = Queue(128) def start(self): _thread.start_new_thread(self.thread_gps, ()) _thread.start_new_thread(self.thread_lora, ()) def thread_gps(self): print("Starting gps thread") uart = UART(1, baudrate=9600) while True: while uart.any(): data = uart.readline() code = data[0:6] if (code == b"$GNGGA") or (code == b"$GNGLL"): print(data) self.gpsMessages.push(data) time.sleep(1) def thread_lora(self): print("Starting lora thread") _LORA_PKG_FORMAT = "BB%ds" _DEVICE_ID = 0x01 lora = LoRa(mode=LoRa.LORA, tx_iq=True) lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW) lora_sock.setblocking(False) while True: while self.gpsMessages.len() > 0: msg = self.gpsMessages.pop() if msg is not None: print("Sending message ...") pkg = struct.pack(_LORA_PKG_FORMAT % len(msg), _DEVICE_ID, len(msg), msg) try: lora_sock.send(pkg) print("Message sent") except OSError: print("Failed to send") time.sleep(1) def main(): app = Application() app.start() main() un saņēmējs from network import LoRa import socket import time import binascii import struct _LORA_PKG_FORMAT = "!BB%ds" lora = LoRa(mode=LoRa.LORA, rx_iq=True) lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW) lora_sock.setblocking(False) print("start lora server ....") while (True): recv_pkg = lora_sock.recv(512) if (len(recv_pkg) > 2): recv_pkg_len = recv_pkg[1] device_id, pkg_len, msg = struct.unpack(_LORA_PKG_FORMAT % recv_pkg_len, recv_pkg) print('Device: %d - Pkg: %s' % (device_id, msg))
- 113 atbildes
-
- gps
- micropython
-
(un vēl 3 ieraksti)
Tagged with: