pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

Atomic Base

UIFlow 1.0 Project

Module Lan

Example

Connect to an MQTT server via LAN module, subscribe and publish messages, and poll for downlink messages to control device states (e.g., turning a relay on/off).

from m5stack import *
from m5ui import *
from uiflow import *
import module
import time

setScreenColor(0x810000)

lan_topic = None
lan_msg = None

lan = module.get(module.LAN_MODULE)

label2 = M5TextBox(53, 219, "ON", lcd.FONT_DejaVu18, 0x810000, rotate=0)
label3 = M5TextBox(230, 219, "OFF", lcd.FONT_DejaVu18, 0x810000, rotate=0)

def module_lan_mqtt_cb(lan_mq_topic, lan_mq_payload):
  global lan_topic, lan_msg
  lan_topic = lan_mq_topic
  lan_msg = lan_mq_payload
  print(lan_msg)
  pass

lan.lan_init(18, 23, 19, 5, 0, 35)
print('Lan Init')
wait(1.5)
lan.mqtt_config('mqtt.m5stack.com', 1883, 'm5mqttid', '', '', 120)
print('Mqtt Configured')
wait(1.5)
lan.mqtt_connect()
print('Connect Server')
wait(1.5)
lan.mqtt_subscribe('m5stack/relay', module_lan_mqtt_cb, 0)
while True:
  lan.mqtt_publish('m5stack/relay', 'ON', 0)
  wait(1.5)
  lan.mqtt_poll_loop()
  if False:
    print('ON')
  else:
    print('OFF')
  wait_ms(2)

API


  • Configure a LAN TCP or UDP connection, specifying the socket type (TCP or UDP), port number, and device type (server or client).

  • Retrieve data from the server by specifying a topic and token.

  • uiflow_block_module_lan_ezdata_async_get_value

  • uiflow_block_module_lan_ezdata_remove

  • uiflow_block_module_lan_ezdata_save

  • uiflow_block_module_lan_get_data

  • uiflow_block_module_lan_get_if_config

  • uiflow_block_module_lan_get_status_code

  • uiflow_block_module_lan_http_request

  • uiflow_block_module_lan_init

  • uiflow_block_module_lan_local_ip

  • uiflow_block_module_lan_mqtt_check_connection

  • uiflow_block_module_lan_mqtt_connect

  • uiflow_block_module_lan_mqtt_disconnect

  • uiflow_block_module_lan_mqtt_init

  • uiflow_block_module_lan_mqtt_poll

  • uiflow_block_module_lan_mqtt_publish

  • uiflow_block_module_lan_mqtt_sub

  • uiflow_block_module_lan_mqtt_sub_cb

  • uiflow_block_module_lan_remote_ip

  • uiflow_block_module_lan_set_ifconfig

  • uiflow_block_module_lan_socket_close

  • uiflow_block_module_lan_tcp_receive_packet

  • uiflow_block_module_lan_tcp_send_packet

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

/uiflow_block_module_lan_udp_receive_packet.svg">


  • uiflow_block_module_lan_udp_receive_packet

  • uiflow_block_module_lan_udp_send_packet
On This Page