How to publish data of HPMA115S0 sensor on aws by esp32?


I just moved on mongoose OS from traditional Arduino IDE. And, I tried to understand how to publish data of a HPMA115S0 sensor by serial com.(16,17 pin of esp32) to aws. I tried a templete from github.

but it is not helpful for me as i cant get any data on shadow editor or consol. also in this template there is a output device present which i dont need.
can anyone help me to understand and complete this project.
I tried this code but output is showing null


let uartNo = 1;   // 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: 115200,
  esp32: {
    gpio: {
      rx: 16,
      tx: 17,

// 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 =;
    print('Received UART data:', data);
    rxAcc += data;
}, null);

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

// Send UART data every second
Timer.set(1000 /* milliseconds */, Timer.REPEAT, function() {
  value = !value;
    'Hello UART! '
      + (value ? 'Tick' : 'Tock')
      + ' uptime: ' + JSON.stringify(Sys.uptime())
      + ' RAM: ' + JSON.stringify(Sys.free_ram())
      + (rxAcc.length > 0 ? (' Rx: ' + rxAcc) : '')
      + '\n'
  rxAcc = '';
}, null);


The example code waits some data coming from UART1 and echoes it.
As far as I understand, your sensor will send data if you ask it to.

1 Like


[Apr 12 16:56:28.220] Received UART data: \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
[Apr 12 16:56:29.214] Received UART data: \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
[Apr 12 16:56:33.206] Received UART data: \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
[Apr 12 16:56:34.200] Received UART data: \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00

this is what i get on serial output.
can you suggest some changes.



You should write a “driver” for your device, i.e. send command, process and validate response, etc.

Reading the datasheet is always usefull.

1 Like


okay,Thanks for reply I understand my mistake. However,As I am new to this environment and js, I am trying but getting no result.Can you give me some idea so i can do it.



If you are more familiar with C take example-uart-c as an example.

And read the docs.
And have a look at the existing libraries.



Okay, I will follow you suggestion. Thanks.