news 2026/1/11 16:15:52

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/1/8 3:35:23

【强烈收藏】上下文工程六大组件:构建高效大模型系统的核心指南

本文深入探讨上下文工程在大语言模型应用中的核心地位,解释上下文窗口的局限性及其带来的挑战。系统介绍了上下文工程的六大核心组件:智能体、查询增强、检索、提示技术、记忆和工具,并通过实例展示如何构建高效大模型系统。文章强调&#xf…

作者头像 李华
网站建设 2026/1/7 13:04:28

JAVA打造宠物新宠:无人共享自助洗澡系统

Java通过高并发架构、智能化算法与全链路自动化流程,为宠物无人共享自助洗澡系统提供了高效、安全、个性化的服务体验,推动宠物服务行业的数字化转型,开启“无人值守、随时嗨洗”的全新时代。以下从技术架构、核心功能、商业价值、生态扩展四…

作者头像 李华
网站建设 2026/1/7 5:10:13

从零开始玩转TensorFlow 2.9:镜像环境快速启动指南

从零开始玩转TensorFlow 2.9:镜像环境快速启动指南 在深度学习项目开发中,最让人头疼的往往不是模型调参或数据清洗,而是——“为什么我的代码在别人机器上跑不起来?” 你有没有经历过这样的场景:花了一整天配置 Py…

作者头像 李华
网站建设 2026/1/9 10:51:46

告别环境冲突:TensorFlow 2.9一体化开发镜像优势分析

告别环境冲突:TensorFlow 2.9一体化开发镜像优势分析 在深度学习项目中,你是否经历过这样的场景?——本地训练好一个模型,信心满满地推送到服务器,结果运行时报错:“ImportError: cannot import name Batch…

作者头像 李华
网站建设 2026/1/7 10:56:20

DiskInfo监控SSD寿命:保障GPU训练稳定性

DiskInfo监控SSD寿命:保障GPU训练稳定性 在现代深度学习系统中,一次大规模模型训练可能持续数天甚至数周。你有没有经历过这样的场景:训练到第80个epoch时,突然I/O错误频发,checkpoint保存失败,日志显示“d…

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

Conda install与pip install混合使用注意事项

Conda 与 Pip 混合使用:在深度学习环境中如何避免“环境地狱” 在一场深夜的模型训练中,你兴冲冲地拉起一个预配置的 TensorFlow-v2.9 深度学习镜像,准备复现一篇新论文。Jupyter 启动顺利,GPU 也检测到了——一切看起来都完美。但…

作者头像 李华