news 2026/4/23 13:45:53

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/22 18:06:08

PyTorch安装教程GPU卸载重装全流程

PyTorch GPU环境卸载与重装全流程:从问题排查到稳定部署 在深度学习项目开发中,一个常见的“拦路虎”并不是模型结构设计或数据质量问题,而是看似基础的运行环境配置。你是否曾遇到过这样的场景:刚写好的训练脚本,执行…

作者头像 李华
网站建设 2026/4/23 10:50:26

AI开发者必备:TensorFlow 2.9深度学习镜像全面解析

AI开发者必备:TensorFlow 2.9深度学习镜像全面解析 在现代AI开发实践中,一个常见的场景是:算法工程师刚刚完成模型调优,信心满满地将代码交给后端团队部署,结果对方反馈“本地跑不通”——依赖版本冲突、CUDA驱动不匹…

作者头像 李华
网站建设 2026/4/23 10:50:43

【C++与Rust双向绑定终极指南】:深入解析cxx-qt库的高性能跨语言集成

第一章:C与Rust双向绑定的演进与现状随着系统级编程语言生态的演进,C与Rust之间的互操作性成为跨语言集成的关键议题。两者均具备高性能与底层控制能力,但在内存安全、编译模型和ABI兼容性方面存在显著差异。为实现高效双向绑定,开…

作者头像 李华
网站建设 2026/4/22 17:10:26

PyTorch安装教程GPU常见报错解决方案汇总

PyTorch安装教程GPU常见报错解决方案汇总 在深度学习项目开发中,最让人头疼的往往不是模型调参或算法设计,而是环境配置——尤其是当你兴冲冲地准备训练一个新模型时,却发现 ImportError: libcudnn.so.8 not found 或者 No GPU devices foun…

作者头像 李华
网站建设 2026/4/23 10:57:41

Markdown表格对比TensorFlow与PyTorch特性

TensorFlow 与 PyTorch 深度对比:从开发到部署的全链路抉择 在如今的深度学习世界里,几乎每一个项目都会面临一个看似简单却影响深远的问题:该用 TensorFlow 还是 PyTorch?这个问题背后,不只是技术选型,更关…

作者头像 李华
网站建设 2026/4/23 10:57:36

手把手教你用C++打造低延迟分布式AI推理系统:任务调度不再是难题

第一章:手把手教你用C打造低延迟分布式AI推理系统:任务调度不再是难题在构建高性能AI服务时,低延迟与高吞吐是核心目标。传统的单机推理架构难以应对突发流量和复杂模型的计算压力,而分布式系统结合智能任务调度机制,能…

作者头像 李华