Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Esp8266 nodemcu receive data from rx0 pin UART

Goal: get data from UART0 rx0 pin.
code:load('api_config.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');
load('api_timer.js');
load('api_uart.js');
load('api_rpc.js');
load('api_aws.js');
load('api_net.js');

let deviceId = Cfg.get('device.id');

let pin = 0, topic = 'my/topic';

let uartNo = 0;

UART.setConfig(uartNo, {
baudRate: 115200
});

UART.setDispatcher(uartNo, function(uartNo, ud) {

let ra = UART.readAvail(uartNo);
if (ra > 0) {

let data = UART.read(uartNo);
print("Received UART data:", data);

}
}, null);
UART.setRxEnabled(uartNo, true);
// Enable Rx

GPIO.set_button_handler(pin, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
print("buttonPressed");
}, null);

Problem:This code is printing the data if button pressed but cant echo back the data I am sending to the rx0 pin! please help!

Comments

Sign In or Register to comment.