当前位置: 首页 > news >正文

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()
http://www.rkmt.cn/news/187498.html

相关文章:

  • Conda update更新TensorFlow-v2.9到最新补丁版本
  • Git Log高级用法追踪TensorFlow项目演变
  • 自动化脚本批量启动TensorFlow-v2.9容器实例
  • 销售都在偷偷用的工具?天下工厂查询能力大揭秘
  • 2025年水泥行业需切割加工耐磨钢板评测报告 - 优质品牌商家
  • 解决罗德与施瓦茨MXO44示波器新探头量程不匹配的实用指南
  • 【收藏级】大模型从入门到实战全解析:小白程序员必看的技术体系与学习指南
  • 手把手教你用C++打造低延迟分布式AI推理系统:任务调度不再是难题
  • Rust如何安全暴露API给C++?(基于cxx-qt的最佳实践全披露)
  • 如何在Linux系统中通过Docker运行TensorFlow镜像
  • 2025年口碑好的名贵奢侈品回收店推荐,温州乐清专业奢侈品回收联系方式全解析 - mypinpai
  • 孤能子视角:“融智学“理论分析,观点碰撞
  • 【C++与Rust双向绑定终极指南】:深入解析cxx-qt库的高性能跨语言集成
  • 手把手教你用Docker安装TensorFlow 2.9 GPU版本
  • 数据结构解释
  • C++26协程、模式匹配落地在即(Clang 17早期实践报告)
  • PyTorch安装教程GPU与CUDA版本对应关系
  • 【AIGC时代C++核心竞争力】:掌握这7种吞吐量优化技巧,性能遥遥领先
  • 【AI推理效率提升300%】:基于C++的分布式任务调度优化全解析
  • 7大AI岗位,哪些最有前景?
  • transformer模型详解自注意力机制的数学原理与实现
  • 【C++异步网络架构设计】:手把手教你重构千万级连接系统
  • GitHub上最受欢迎的TensorFlow-v2.9项目合集分享
  • 【稀缺资料】C++游戏引擎多线程渲染优化全路径拆解:涵盖任务调度与内存屏障
  • 解决python--UI自动化iframe切换问题
  • Jupyter魔法命令提升TensorFlow调试效率
  • 接口自动化不是救命稻草
  • 如何选择适合工业4.0的设备监控系统以提升智能制造水平?
  • 2025年市场评价高的微信朋友圈广告公司推荐,信息流广告代运营/抖音短视频矩阵、AI广告,微信朋友圈广告公司口碑推荐 - 品牌推荐师
  • 使用Git进行版本控制:避免TensorFlow实验结果丢失