pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

DTU LoRaWAN 915

This program uses the LoRaWAN 915 DTU module to connect to the network in OTAA mode. During the connection, the brightness of the RGB light changes to indicate the connection status. Once connected, the device sends data "012345678" every 5 seconds and checks for downlink data.

Example

from m5stack import *
from m5ui import *
from uiflow import *
from base.DTU_LoRaWAN import DTU_LoRaWAN
import time

j = None

rgb.setColorAll(0xcc6600)
dtu_lora915 = DTU_LoRaWAN()
dtu_lora915.set_join_mode(0)
dtu_lora915.config_OTAA('d896e0ff00000241', '0000000000000001', '98929b92f09e2daf676d646d0f61d251')
dtu_lora915.set_frequency_band_mask('0001')
dtu_lora915.set_rx_window_param(0, 0, 923300000)
dtu_lora915.set_class_mode(2)
dtu_lora915.set_uplink_downlink_mode(1)
dtu_lora915.join(1, 1, 8, 15)
rgb.setColorAll(0xff6666)
while not dtu_lora915.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_lora915.send_data('012345678', 1, 15)
  print(dtu_lora915.check_downlink_data())
  wait(5)
  wait_ms(2)

API

dtu_lora915 = DTU_LoRaWAN()
  • Initializes the LoRaWAN 915 DTU module.
dtu_lora915.any()
  • Retains cached data.
dtu_lora915.check_downlink_data()
  • Checks and receives downlink data.
dtu_lora915.check_join_status()
  • Checks the status of joining the LoRaWAN network.
dtu_lora915.check_uplink_status()
  • Checks the uplink data status.
dtu_lora915.set_frequency_band_mask('0001')
dtu_lora915.set_rx_window_param(0, 0, 923300000)
dtu_lora915.set_class_mode(0)
dtu_lora915.set_uplink_downlink_mode(1)
  • Configures LoRaWAN parameters, including frequency mask, receive window parameters, RX1 offset, RX2 data rate, RX2 frequency, operating mode, and downlink mode.
dtu_lora915.config_OTAA('', '', '')
  • Configures OTAA mode, setting the device EUI, application key (App Key), and application EUI.
dtu_lora915.get_ABP_config()
  • Retrieves ABP (Activation By Personalization) configuration.
dtu_lora915.get_OTAA_config()
  • Retrieves OTAA (Over-The-Air Activation) configuration.
dtu_lora915.join(1, 1, 8, 1)
  • Initiates joining the LoRaWAN network, setting automatic join mode, interval time (seconds), and maximum number of attempts.
dtu_lora915.join(0)
  • Stops the process of joining the LoRaWAN network.
dtu_lora915.read()
  • Reads all available data.
dtu_lora915.readline()
  • Reads data line by line.
dtu_lora915.read(10)
  • Reads 10 characters.
dtu_lora915.read_coils(1, 1, 0)
  • Reads coil registers from the specified slave address, starting address, and number of coils.
dtu_lora915.read_discrete_inputs(1, 1, 0)
  • Reads discrete input registers from the specified slave address, starting address, and number of inputs.
dtu_lora915.read_holding_registers(1, 1, 0, True)
  • Reads holding registers from the specified slave address, starting address, and number of registers. Supports signed or unsigned data.

<img class="blockly_svg" src=" https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/static/assets

/img/uiflow/blockly/atomic_base/dtu_lorawan_915/uiflow_block_base_lorawan915_read_input_registers.svg">

dtu_lora915.read_input_registers(1, 1, 0, True)
  • Reads input registers from the specified slave address, starting address, and number of registers. Supports signed or unsigned data.
dtu_lora915.receive_data()
  • Receives downlink data from the buffer.
dtu_lora915.send_data('')
  • Sends data payload, with the option for acknowledgment mode.
dtu_lora915.set_join_mode(0)
  • Sets the join mode, here set to OTAA (Over-the-Air Activation).
dtu_lora915.set_uplink_app_port(1)
  • Sets the uplink application port, with a range from 1 to 233.
dtu_lora915.write('')
  • Writes data via UART.
dtu_lora915.write(''+"\r\n")
  • Writes a line of data via UART.
dtu_lora915.write_multiple_coils(1, 1, 0)
  • Writes multiple coils to the specified slave address, with customizable start address and output values.
dtu_lora915.write_multiple_registers(1, 1, 0, True)
  • Writes multiple registers to the slave address, with customizable start address and register values.
dtu_lora915.write(bytes([0, 0, 0]))
  • Writes raw data via UART, with data passed as a list.
dtu_lora915.write_single_coil(1, 1, 0)
  • Writes a single coil to the specified slave address, with customizable start address and output value.
dtu_lora915.write_single_register(1, 1, 0, True)
  • Writes a single register to the slave address, with customizable start address and register value, and supports signed data.
On This Page