Connect to the specified CoAP server with IP address 120.77.157.90 and port 5683 via NB-IoT module, then sequentially send a GET request, a POST request with post-test data, and a PUT request with put-test data, all using plain text format.
from m5stack import *
from m5ui import *
from uiflow import *
from comx.nbiot import NBIoT
setScreenColor(0x222222)
nb = NBIoT(tx=13, rx=5)
if nb.coap_connect('120.77.157.90', 5683):
print(nb.coap_get('/m5stack-get'))
print(nb.coap_post('/m5stack-post', 'post-test', content_format=0))
print(nb.coap_put('/m5stack-put', 'put-test', content_format=0)) nb.get_gprs_network_registration() nb.get_network_registration() nb.get_single_quality() nb.check_status() nb.coap_connect('', 5683) nb.coap_destroy() nb.coap_get('') nb.coap_post('', '', content_format=0) nb.coap_put('', '', content_format=0) NBIoT(tx=13, rx=5) nb.mqtt_check_connection() nb.mqtt_connect('', 1883, '', '', '', 0) nb.mqtt_disconnect() nb.mqtt_poll() nb.mqtt_publish('', '', 0) nb.mqtt_subscribe('', nbiot_mqtt_cb, 0) def nbiot_mqtt_cb(nb_mq_topic, nb_mq_payload):
global nb_topic, nb_msg, nb
nb_topic = nb_mq_topic
nb_msg = nb_mq_payload
pass nb_topic is the topic variable, and nb_msg is the message variable. The corresponding action will be executed when a message is received on the subscribed topic.nb.mqtt_unsubscribe('') nb.poweroff() nb.reset() nb.set_command_echo_mode(0)