Hello, I am trying to read data from an Arduino Uno that is transmitting a JSON string every 50ms at 9600 baud. I have connected the Rx and Tx pins of Arduino to Tx and Rx pins of ESP respectively.
The code I am using is the following:
load("api_config.js");
load("api_mqtt.js");
load("api_sys.js");
load("api_timer.js");
load("api_uart.js");
let uartNo = 0; // Uart number used for this example
let rxAcc = ""; // Accumulated Rx data, will be echoed back to Tx
let value = false;
// Configure UART at 115200 baud
UART.setConfig(uartNo, {
baudRate: 9600
});
// Set dispatcher callback, it will be called whenver new Rx data or space in
// the Tx buffer becomes available
UART.setDispatcher(
uartNo,
function(uartNo) {
let ra = UART.readAvail(uartNo);
if (ra > 0) {
// Received new data: print it immediately to the console, and also
// accumulate in the "rxAcc" variable which will be echoed back to UART later
let data = UART.read(uartNo);
print("Received UART data:", data);
rxAcc += data;
}
},
null
);
// Enable Rx
UART.setRxEnabled(uartNo, true);
But on the console I see just empty lines instead of this {“type”:“response”,“distance”:419,“gas”:1024} which is what Arduino is transmitting.
Any ideas or suggestions??