初始化一个TCP服务器,通过指定的IP和端口建立连接,并在循环中随机生成数据包发送,同时监控是否有可用的数据包接收,并打印接收的数据包大小
from m5stack import *
from m5ui import *
from uiflow import *
import module
import time
setScreenColor(0x222222)
counter = None
lan = module.get(module.LANBASE)
import random
counter = 0
print('Start the TCP Server')
print((str('Local IP address:') + str((lan.local_ip()))))
lan.tcp_udp_config('192.168.1.97', 55005, 1, 1)
print('TCP Connected')
print((str('Remote IP address:') + str((lan.remote_ip()))))
while True:
counter = random.randint(100000, 999999)
lan.tcp_send_packet(str(counter))
wait(1)
if lan.is_available_packet(1):
print((str('TCP receive packet size') + str((lan.tcp_receive_packet(0)))))
wait(1)
wait_ms(2)
lan.is_available_packet(1)
lan.get_ezdata(ezdata_get_fOkSZcb, 'GCJ3Ic5h2eXnzV3rT3bBXvrncCaJnART', '')
lan.remove_ezdata('GCJ3Ic5h2eXnzV3rT3bBXvrncCaJnART', '')
lan.set_ezdata('GCJ3Ic5h2eXnzV3rT3bBXvrncCaJnART', '', '', 0)
req.text
lan.get_if_config()
req.status_code
try:
req = lan.http_request(method='GET', url='', headers={})
gc.collect()
req.close()
except:
pass
lan.tcp_udp_config('', 0, 1, 1)
lan.local_ip()
lan.modbus_init(15, 5, 115200, 1, 1)
modbus.read_coils(1, 1, 0)
modbus.read_discrete_inputs(1, 1, 0)
modbus.read_holding_registers(1, 1, 0, True)
modbus.read_input_registers(1, 1, 0, True)
modbus.write_multiple_coils(1, 1, 0)
modbus.write_multiple_registers(1, 1, 0, True)
modbus.write_single_coil(1, 1, 0)
modbus.write_single_register(1, 1, 0, True)
lan.modbus_init(15, 5, 115200, 1, 1)
modbus.find_address
modbus.find_function
modbus.find_quantity
modbus.function_init(1, 0, 0)
modbus.receive_req_create_pdu()
modbus.create_slave_response(1)
modbus.update_process(1, 0, 0, [0, 0, 0])
lan.mqtt_is_connect()
lan.mqtt_connect()
lan.mqtt_disconnect()
lan.mqtt_config('mqtt.m5stack.com', 1883, '', '', '', 120)
lan.mqtt_poll_loop()
lan.mqtt_publish('', '', 0)
lan.mqtt_subscribe('', lan_base_mqtt_cb, 0)
def lan_base_mqtt_cb(lan_mq_topic, lan_mq_payload):
global ezdata_value1, lan_topic, lan_msg
lan_topic = lan_mq_topic
lan_msg = lan_mq_payload
pass
lan.remote_ip()
lan.set_if_config('192.168.1.100', '255.255.255.0', '192.168.1.1', '8.8.8.8')
lan.socket_close()
lan.tcp_receive_packet(0)
lan.tcp_send_packet('1234')
modbus._mdbus_uart.any()
modbus._mdbus_uart.read()
modbus._mdbus_uart.readline()
modbus._mdbus_uart.read(10)
modbus._mdbus_uart.write('')
modbus._mdbus_uart.write(''+"\r\n")
modbus._mdbus_uart.write(bytes([0, 0, 0]))
lan.udp_receive_packet(0)
lan.udp_send_packet('', 0, '')