news 2026/4/26 21:58:34

lora25-lora26跨年收发测试

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
lora25-lora26跨年收发测试

普通lora测试

发送

import os, sys currentdir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.dirname(os.path.dirname(currentdir))) from LoRaRF import SX126x import time # Begin LoRa radio and set NSS, reset, busy, IRQ, txen, and rxen pin with connected Raspberry Pi gpio pins # IRQ pin not used in this example (set to -1). Set txen and rxen pin to -1 if RF module doesn't have one busId = 0; csId = 0 resetPin = 18; busyPin = 20; irqPin = 16; txenPin = 6; rxenPin = -1 LoRa = SX126x() print("Begin LoRa radio") if not LoRa.begin(busId, csId, resetPin, busyPin, irqPin, txenPin, rxenPin) : raise Exception("Something wrong, can't begin LoRa radio") LoRa.setDio2RfSwitch() # Set frequency to 868 Mhz print("Set frequency to 868 Mhz") LoRa.setFrequency(868000000) # Set TX power, default power for SX1262 and SX1268 are +22 dBm and for SX1261 is +14 dBm # This function will set PA config with optimal setting for requested TX power print("Set TX power to +22 dBm") LoRa.setTxPower(22, LoRa.TX_POWER_SX1262) # TX power +17 dBm using PA boost pin # Configure modulation parameter including spreading factor (SF), bandwidth (BW), and coding rate (CR) # Receiver must have same SF and BW setting with transmitter to be able to receive LoRa packet print("Set modulation parameters:\n\tSpreading factor = 7\n\tBandwidth = 125 kHz\n\tCoding rate = 4/5") sf = 7 # LoRa spreading factor: 7 bw = 125000 # Bandwidth: 125 kHz cr = 5 # Coding rate: 4/5 LoRa.setLoRaModulation(sf, bw, cr) # Configure packet parameter including header type, preamble length, payload length, and CRC type # The explicit packet includes header contain CR, number of byte, and CRC type # Receiver can receive packet with different CR and packet parameters in explicit header mode print("Set packet parameters:\n\tExplicit header type\n\tPreamble length = 12\n\tPayload Length = 15\n\tCRC on") headerType = LoRa.HEADER_EXPLICIT # Explicit header mode preambleLength = 12 # Set preamble length to 12 payloadLength = 15 # Initialize payloadLength to 15 crcType = True # Set CRC enable LoRa.setLoRaPacket(headerType, preambleLength, payloadLength, crcType) # Set syncronize word for public network (0x3444) print("Set syncronize word to 0x3444") LoRa.setSyncWord(0x3444) print("\n-- LoRa Transmitter --\n") # Message to transmit message = "HeLoRa World!\0" messageList = list(message) for i in range(len(messageList)) : messageList[i] = ord(messageList[i]) counter = 0 # Transmit message continuously while True : # Transmit message and counter # write() method must be placed between beginPacket() and endPacket() LoRa.beginPacket() LoRa.write(messageList, len(messageList)) LoRa.write([counter], 1) LoRa.endPacket() # Print message and counter print(f"{message} {counter}") # Wait until modulation process for transmitting packet finish LoRa.wait() # Print transmit time and data rate print("Transmit time: {0:0.2f} ms | Data rate: {1:0.2f} byte/s".format(LoRa.transmitTime(), LoRa.dataRate())) # Don't load RF module with continous transmit time.sleep(5) counter = (counter + 1) % 256 try : pass except : LoRa.end()

接受

import os, sys currentdir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.dirname(os.path.dirname(currentdir))) from LoRaRF import SX126x import time # Begin LoRa radio and set NSS, reset, busy, IRQ, txen, and rxen pin with connected Raspberry Pi gpio pins # IRQ pin not used in this example (set to -1). Set txen and rxen pin to -1 if RF module doesn't have one busId = 0; csId = 0 resetPin = 18; busyPin = 20; irqPin = 16; txenPin = 6; rxenPin = -1 LoRa = SX126x() print("Begin LoRa radio") if not LoRa.begin(busId, csId, resetPin, busyPin, irqPin, txenPin, rxenPin) : raise Exception("Something wrong, can't begin LoRa radio") LoRa.setDio2RfSwitch() # Set frequency to 868 Mhz print("Set frequency to 868 Mhz") LoRa.setFrequency(868000000) # Set RX gain. RX gain option are power saving gain or boosted gain print("Set RX gain to power saving gain") LoRa.setRxGain(LoRa.RX_GAIN_POWER_SAVING) # Power saving gain # Configure modulation parameter including spreading factor (SF), bandwidth (BW), and coding rate (CR) # Receiver must have same SF and BW setting with transmitter to be able to receive LoRa packet print("Set modulation parameters:\n\tSpreading factor = 7\n\tBandwidth = 125 kHz\n\tCoding rate = 4/5") sf = 7 # LoRa spreading factor: 7 bw = 125000 # Bandwidth: 125 kHz cr = 5 # Coding rate: 4/5 LoRa.setLoRaModulation(sf, bw, cr) # Configure packet parameter including header type, preamble length, payload length, and CRC type # The explicit packet includes header contain CR, number of byte, and CRC type # Receiver can receive packet with different CR and packet parameters in explicit header mode print("Set packet parameters:\n\tExplicit header type\n\tPreamble length = 12\n\tPayload Length = 15\n\tCRC on") headerType = LoRa.HEADER_EXPLICIT # Explicit header mode preambleLength = 12 # Set preamble length to 12 payloadLength = 15 # Initialize payloadLength to 15 crcType = True # Set CRC enable LoRa.setLoRaPacket(headerType, preambleLength, payloadLength, crcType) # Set syncronize word for public network (0x3444) print("Set syncronize word to 0x3444") LoRa.setSyncWord(0x3444) print("\n-- LoRa Receiver --\n") # Receive message continuously while True : # Request for receiving new LoRa packet LoRa.request() # Wait for incoming LoRa packet LoRa.wait() # Put received packet to message and counter variable # read() and available() method must be called after request() or listen() method message = "" # available() method return remaining received payload length and will decrement each read() or get() method called while LoRa.available() > 1 : message += chr(LoRa.read()) counter = LoRa.read() # Print received message and counter in serial print(f"{message} {counter}") # Print packet/signal status including RSSI, SNR, and signalRSSI print("Packet status: RSSI = {0:0.2f} dBm | SNR = {1:0.2f} dB".format(LoRa.packetRssi(), LoRa.snr())) # Show received status in case CRC or header error occur status = LoRa.status() if status == LoRa.STATUS_CRC_ERR : print("CRC error") elif status == LoRa.STATUS_HEADER_ERR : print("Packet header error") try : pass except : LoRa.end()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/26 1:08:30

JAVA驱动:羽毛球馆线上自助预约新体验

JAVA驱动:羽毛球馆线上自助预约新体验一、引言:羽毛球馆预约的数字化转型需求在全民健身与体育消费升级的背景下,羽毛球作为一项普及度极高的运动,其场馆预约需求呈现爆发式增长。传统的人工预约方式(如电话、现场登记…

作者头像 李华
网站建设 2026/4/24 21:51:58

C++26即将发布,Clang 17支持进度到哪了?一文看懂所有新特性适配状态

第一章:C26新特性全景与Clang 17支持概览随着C标准的持续演进,C26正逐步成形,引入多项提升语言表达力、性能与安全性的新特性。尽管C26尚未最终定稿,但主要编译器厂商已开始实验性支持部分提案,其中Clang 17作为先行者…

作者头像 李华
网站建设 2026/4/25 4:01:38

使用SSH反向隧道穿透内网运行TensorFlow任务

使用SSH反向隧道穿透内网运行TensorFlow任务 在深度学习项目中,我们常常面临一个看似简单却棘手的问题:如何从外部安全地访问位于内网的GPU服务器?尤其是当这台机器部署在实验室、企业私有云或家庭网络中时——没有公网IP、防火墙层层设限&am…

作者头像 李华
网站建设 2026/4/14 15:40:02

同惠TH2830LCR测试仪的频率响应特性解析

作为一款高性能的LCR测试仪,同惠TH2830在频率响应特性上展现出卓越的技术优势,为电子元件的高精度测量提供了可靠保障。其频率响应特性主要体现在宽频测试范围、高精度稳定性及智能化功能设计三个方面,以下将详细解析其核心特点与应用价值。一…

作者头像 李华
网站建设 2026/4/22 21:14:52

Mac M1芯片适配TensorFlow-v2.9镜像的方法分享

Mac M1芯片适配TensorFlow-v2.9镜像的方法分享 在苹果推出M1芯片的那一刻,Mac电脑的性能和能效迎来了质的飞跃。但随之而来的,是整个软件生态的一次“地震”——尤其是深度学习领域。许多开发者兴奋地抱着新Mac跑起TensorFlow模型时,却发现要…

作者头像 李华
网站建设 2026/4/24 7:22:20

Conda install tensorflow-gpu2.9指定版本安装

Conda 安装 TensorFlow-GPU 2.9:构建稳定高效的深度学习环境 在现代深度学习项目中,一个常见的痛点是:“代码没问题,但跑不起来。” 这背后往往不是模型设计的问题,而是环境配置的灾难——CUDA 版本不对、cuDNN 不兼容…

作者头像 李华