pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

DTU LoRaWAN 470

Example

This program connects to the network, sends, and receives data via the LoRaWAN protocol. After initialization, the device attempts to join the network in OTAA mode, with the RGB light brightness showing the connection status. Once connected, it sends data every 5 seconds and checks for downlink data.

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

j = None

rgb.setColorAll(0xcc6600)
dtu_lora470 = DTU_LoRaWAN()
dtu_lora470.set_join_mode(0)
dtu_lora470.config_OTAA('2fd1549588a2f196', '00000000000000000000000000000000', '059d230cf60aaf212783b4b7e801a389')
dtu_lora470.set_frequency_band_mask('0400')
dtu_lora470.set_rx_window_param(0, 0, 505300000)
dtu_lora470.set_class_mode(2)
dtu_lora470.set_uplink_downlink_mode(1)
dtu_lora470.join(1, 1, 8, 10)
rgb.setColorAll(0xff6666)
while not dtu_lora470.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_lora470.send_data('012345678', 1, 15)
  print(dtu_lora470.check_downlink_data())
  wait(5)
  wait_ms(2)

API

dtu_lora470 = DTU_LoRaWAN()
  • Initializes the LoRaWAN 470 DTU module, preparing the device for LoRa communication.
modbus._mdbus_uart.any()
  • Checks if there is any unprocessed cached data.
dtu_lora470.check_downlink_data()
  • Checks and receives downlink data from the gateway, typically used to receive network instructions or information.
dtu_lora470.check_join_status()
  • Checks if the device has successfully joined the LoRaWAN network.
dtu_lora470.check_uplink_status()
  • Checks the status of the uplink data sent by the device to confirm successful transmission.
dtu_lora470.set_frequency_band_mask('0001')
dtu_lora470.set_rx_window_param(0, 0, 505300000)
dtu_lora470.set_class_mode(0)
dtu_lora470.set_uplink_downlink_mode(1)
  • Configures the frequency band mask, RX window parameters, receive frequency, and data rate (e.g., RX1 and RX2 parameters).
  • Sets the device operating mode (Class A) and the frequency mode for uplink and downlink communication.
dtu_lora470.config_OTAA('', '', '')
  • Configures the device in OTAA (Over-The-Air Activation) mode with the device EUI, app key, and app EUI.
dtu_lora470.get_ABP_config()
  • Retrieves the device's ABP (Activation By Personalization) configuration information.
dtu_lora470.get_OTAA_config()
  • Retrieves the device's OTAA configuration information.
dtu_lora470.join(1, 1, 8, 1)
  • Initiates the process to join the LoRaWAN network. Allows setting the auto-join mode, interval (in seconds), and maximum number of attempts.
dtu_lora470.join(0)
  • Stops the network joining process.
dtu_lora470.read()
  • Reads all available data.
dtu_lora470.readline()
  • Reads data line by line.
dtu_lora470.read(10)
  • Reads a specified number of characters.
dtu_lora470.read_coils(1, 1, 0)
  • Reads the coil status using the Modbus protocol, specifying the slave address, start address, and number of coils.
dtu_lora470.read_discrete_inputs(1, 1, 0)
  • Reads the status of discrete inputs, specifying the slave address, start address, and number of inputs.


dtu_lora470.read_holding_registers(1, 1, 0, True)
  • Reads holding registers, specifying the slave address, start address, and number of registers, with an option to read signed or unsigned values.
dtu_lora470.read_input_registers(1, 1, 0, True)
  • Reads input registers, specifying the slave address, start address, and number of registers, with an option to read signed or unsigned values.
dtu_lora470.receive_data()
  • Receives downlink data from the buffer, typically used to process messages sent by the LoRaWAN network.
dtu_lora470.send_data('')
  • Sends a data payload with an option to use confirmation mode.
dtu_lora470.set_join_mode(0)
  • Sets the network join mode, such as OTAA (Over-The-Air Activation).
dtu_lora470.set_uplink_app_port(1)
  • Sets the uplink application port, ranging from 1 to 233.
dtu_lora470.write('')
  • Writes data to the UART port.
dtu_lora470.write(''+"\r\n")
  • Writes a line of data to the UART port.
dtu_lora470.write_multiple_coils(1, 1, 0)
  • Writes multiple coil states to a Modbus device, specifying the start address and output values.
dtu_lora470.write_multiple_registers(1, 1, 0, True)
  • Writes multiple register values to a Modbus device, specifying the start address, register values, and support for signed data.
dtu_lora470.write(bytes([0, 0, 0]))
  • Writes raw data to the UART port, with data passed as a list.
dtu_lora470.write_single_coil(1, 1, 0)
  • Writes the state of a single coil on a Modbus device, specifying the output address and value.
dtu_lora470.write_single_register(1, 1, 0, True)
  • Writes a value to a single register on a Modbus device, specifying the register address and value, with support for signed data.
On This Page