该程序使用LoRaWAN 868 DTU模块在OTAA模式下连接网络,RGB灯在连接期间通过亮度变化指示状态。连接成功后,设备每5秒发送一次数据“012345678”并检查下行数据。
from m5stack import *
from m5ui import *
from uiflow import *
from base.DTU_LoRaWAN import DTU_LoRaWAN
import time
j = None
rgb.setColorAll(0xcc6600)
dtu_lora868 = DTU_LoRaWAN()
dtu_lora868.set_join_mode(0)
dtu_lora868.config_OTAA('00bb9da5b97addf8', '00000000000000000000000000000000', '27dfe264ca33ac1957c005eb48ba4728')
dtu_lora868.set_frequency_band_mask('0001')
dtu_lora868.set_rx_window_param(0, 0, 869525000)
dtu_lora868.set_class_mode(2)
dtu_lora868.set_uplink_downlink_mode(1)
dtu_lora868.join(1, 1, 8, 10)
rgb.setColorAll(0xff6666)
while not dtu_lora868.check_join_status():
print('waiting join....')
for j in range(101):
rgb.setBrightness(j)
wait_ms(10)
for j in range(100, -1, -1):
rgb.setBrightness(j)
wait_ms(10)
print('connected!')
rgb.setBrightness(100)
rgb.setColorAll(0x33ff33)
while True:
dtu_lora868.send_data('012345678', 1, 15)
print(dtu_lora868.check_downlink_data())
wait(5)
wait_ms(2)
dtu_lora868 = DTU_LoRaWAN()
dtu_lora868.any()
dtu_lora868.check_downlink_data()
dtu_lora868.check_join_status()
dtu_lora868.check_uplink_status()
dtu_lora868.set_frequency_band_mask('')
dtu_lora868.set_rx_window_param(0, 0, 869525000)
dtu_lora868.set_class_mode(0)
dtu_lora868.set_uplink_downlink_mode(1)
dtu_lora868.config_OTAA('', '', '')
dtu_lora868.get_ABP_config()
dtu_lora868.get_OTAA_config()
dtu_lora868.join(1, 1, 8, 1)
dtu_lora868.join(0)
dtu_lora868.read()
dtu_lora868.readline()
dtu_lora868.read(10)
dtu_lora868.read_coils(1, 1, 0)
dtu_lora868.read_discrete_inputs(1, 1, 0)
dtu_lora868.read_holding_registers(1, 1, 0, True)
dtu_lora868.read_input_registers(1, 1, 0, True)
dtu_lora868.receive_data()
dtu_lora868.send_data('')
dtu_lora868.set_join_mode(0)
dtu_lora868.set_uplink_app_port(1)
dtu_lora868.write('')
dtu_lora868.write(''+"\r\n")
dtu_lora868.write_multiple_coils(1, 1, 0)
dtu_lora868.write_multiple_registers(1, 1, 0, True)
dtu_lora868.write(bytes([0, 0, 0]))
dtu_lora868.write_single_coil(1, 1, 0)
dtu_lora868.write_single_register(1, 1, 0, True)