WiFiMCU Reference Book

Only one uart is supported in WiFiMCU so far. The GPIO pin is D8(RX1), D9(TX1).

Function list

Function Definition
uart.setup() Setup uart parameters: buadrate, databits, parity, stopbits.
uart.on() Register the callback functions for uart events
uart.send() Send data via uart

uart.setup()

Description

Setup uart parameters: buadrate, databits, parity, stopbits.

Syntax

uart.setup(id, baud, parity, databits, stopbits)

Parameters

id: uart ID, always 1 at present.

baud: baudrate, such as: 4800, 9600, 115200.

parity: 'n': no parity, 'o': odd parity, 'e': even parity.

databits: data bits, '5', '6', '7', '8', '9'.

stopbits: stop bits, '1', '2'

Returns

nil

Examples

-uart.setup(1,9600,'n','8','1')

uart.on()

Description

Register the callback functions for uart events.

Syntax

uart.on(id, event ,func_cb)

Parameters

id: uart ID, always 1 at present.

event: always "data".

func_cb: Callback function for the event. When data arrived, the function will be called. Function prototype is: func_cb(data). “data” is the data received.

Returns

nil

Examples

-uart.on(1, 'data',function(t) len=string.len(t) print(len.." "..t) uart.send(1,t) end)

uart.send()

Description

Send data via uart.

Syntax

uart.send(1, string1,[number],...[stringn])

Parameters

id: uart ID, always 1 at present.

string1: string ready to send.

[number]: Optional, number ready to send.

[stringn]: Optional, The nth string ready to be send.

Returns

nil

Examples

-uart.send(1,'hello wifimcu')

-uart.send(1,'hello wifimcu','hi',string.char(0x32,0x35))

-uart.send(1,string.char(0x01,0x02,0x03))