当前位置: 首页 > 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.jsqmd.com/news/171682/

相关文章:

  • Conda update更新TensorFlow-v2.9到最新补丁版本
  • 2025年多场景测力传感器优质产品推荐指南精准匹配工业新能源 - 优质品牌商家
  • Git Log高级用法追踪TensorFlow项目演变
  • Conda install tensorflow-gpu2.9指定版本安装
  • 如何用Boost.Asio重构C++网络层?资深架构师的8年经验总结
  • 2025年12月评价高的精密冷挤压企业评测报告 - 优质品牌商家
  • 7大AI岗位,哪些最有前景?
  • 销售都在偷偷用的工具?天下工厂查询能力大揭秘
  • 客户端音视频开发全指南
  • 解决罗德与施瓦茨MXO44示波器新探头量程不匹配的实用指南
  • 2025年水泥行业需切割加工耐磨钢板评测报告 - 优质品牌商家
  • 为什么选择TensorFlow 2.9镜像进行大模型训练?
  • 歌曲文件转换,mgg文件如何转换程ogg,再转换到mp3
  • 【收藏级】大模型从入门到实战全解析:小白程序员必看的技术体系与学习指南
  • 2026年焊接操作机厂家权威推荐榜:通用型、重型、载人型、固定式、精密型等全系列焊接操作机实力解析与选购指南 - 品牌企业推荐师(官方)
  • 集成控制与自动启停ProfiNet转CAN协议转换网关实现西门子1200 PLC与阿特拉斯空气压缩机G 7-22 VSD通讯案例
  • 2025年电热膜电地暖主流品牌选择深度评测报告:发热膜电地暖、合金丝发热电缆电地暖、护套膜电地暖、电热膜电地暖选择指南 - 优质品牌商家
  • 3.与menuconfig有关的文件
  • 如何在TensorFlow-v2.9中启用XLA优化提升训练速度
  • transformer模型详解之输出概率分布计算
  • 邮件传输与SMTP协议深度解析
  • 使用Git Stash临时保存未完成的TensorFlow代码
  • C++高并发网络编程进阶(异步重构关键技术全公开)
  • 多线程+内存池+CUDA协同优化,C++如何让AIGC推理吞吐量跃升3倍?
  • Conda+TensorFlow-v2.9:科学计算环境的最佳搭配
  • Shotcut 25.12 (Linux, macOS, Windows) - 免费开源视频编辑器
  • 手把手教你用C++打造低延迟分布式AI推理系统:任务调度不再是难题
  • Rust如何安全暴露API给C++?(基于cxx-qt的最佳实践全披露)
  • C++26即将发布,你准备好使用std::future实现链式异步了吗?
  • 2025年窑密封厂家权威推荐榜:烘干窑/氧化锌窑/锂电处理窑/高温旋转窑/氧化铝窑/回转窑/油泥处理窑密封源头厂家精选 - 品牌推荐官