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

#1

Hi,
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.
edit:
I tried this code but output is showing null

load('api_timer.js');
load('api_uart.js');
load('api_sys.js');


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 = UART.read(uartNo);
    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;
  UART.write(
    uartNo,
    'Hello UART! '
      + (value ? 'Tick' : 'Tock')
      + ' uptime: ' + JSON.stringify(Sys.uptime())
      + ' RAM: ' + JSON.stringify(Sys.free_ram())
      + (rxAcc.length > 0 ? (' Rx: ' + rxAcc) : '')
      + '\n'
  );
  rxAcc = '';
}, null);
0 Likes

#2

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

#3

[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.

0 Likes

#4

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

#5

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.

0 Likes

#6

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.

0 Likes

#7

Okay, I will follow you suggestion. Thanks.

0 Likes