pdf-icon

UIFlow Guide

UiFlow1 Blockly

Event

Unit

UiFlow1 Project

Unit NbIoT2

Example

Connect to MQTT to send subscription messages

from m5stack import *
from m5stack_ui import *
from uiflow import *
import unit

screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)
nbiot2_0 = unit.get(unit.NBIOT2, unit.PORTC)

nbiot2_0.mqtt_service_config('mqtt.m5stack.com', 1883, '', '', '', 120)
while True:
  if True & (nbiot2_0.mqtt_server_is_connect()):
    nbiot2_0.mqtt_publish_topic('nbiot001', 'test', 0)
  wait_ms(2)

API

print((str('card status:') + str((nbiot2_0.check_SIM_card()))))
  • Check Modem SIM Card Status (returns bool)
nbiot2_0.debug = True
  • Enable AT Command Debug Logging
print((str('network status:') + str((nbiot2_0.get_gprs_status()))))
  • Get GPRS Network Status (returns int)
print((str('model identification:') + str((nbiot2_0.get_identification()))))
  • Get Model Identifier (returns string)
print((str('identification number:') + str((nbiot2_0.get_IMEI()))))
  • Get Device ID (returns string)
print((str('cid:') + str((nbiot2_0.get_PDP_context_ip(0)))))
  • Get IP Address for PDP Context 0 (returns string)
print((str('signal strength:') + str((nbiot2_0.get_single_quality()))))
  • Get Signal Strength (returns int)
print((str('data content:') + str((nbiot2_0.http_data))))
  • Retrieve HTTP Response Body (returns string)
nbiot2_0.http_request(0, '', {}, {})
  • Send HTTP Network Request
print((str('response status:') + str((nbiot2_0.http_status_code))))
  • Send HTTP GET Request and Retrieve Headers
nbiot2_0.http_terminate()
  • Check HTTP Server Termination Status
nbiot2_0.mqtt_poll()
  • MQTT Polling Loop
nbiot2_0.mqtt_publish_topic('', '', 0)
  • Publish MQTT Message with Topic, Payload, and QoS Level
nbiot2_0.mqtt_server_disconnect()
  • Disconnect from MQTT Server
print((str('server status:') + str((nbiot2_0.mqtt_server_is_connect()))))
  • Check MQTT Server Connection Status (returns bool)
nbiot2_0.mqtt_service_config('mqtt.m5stack.com', 1883, '', '', '', 120)
  • Configure MQTT Parameters
nbiot2_0.mqtt_server_connect(0)
  • Connect to MQTT Server with Clean Session Disabled
nbiot2_0.mqtt_subscribe_topic('', nbiot2_0_mqtt_cb_func, 0)
  • Subscribe to MQTT Topic with QoS Level
def nbiot2_0_mqtt_cb_func(mq_topic, mq_payload):
  global nbiot_topic, nbiot_msg
  nbiot_topic = mq_topic
  nbiot_msg =  mq_payload
  pass
  • Receive Subscribed MQTT Messages
nbiot2_0.mqtt_unsubscribe_topic('')
  • Unsubscribe from MQTT Topic
nbiot2_0.set_enable_PDP_context('cmnbiot')
  • Configure PDP Context APN
nbiot2_0.uart_port_id(1)
  • Set Core UART Interface ID
On This Page