How to attach my lambda function to IoT Analytics pipeline

0

Hello,

I created my lambda function that converts string data to temperature. I use IoT analytics for data collection and visualization in QuickSight. I also add permission ([https://docs.aws.amazon.com/iotanalytics/latest/userguide/pipeline-activities-lambda.html]) to my lambda function for IoT Analytics but when I want to use my lambda function in lambda pipeline activity there is no outgoing message. So my question is How to attach lambda function to IoT Analytics pipeline.

This is my function:

export const handler = async (event) => {
  // TODO implement
  var json = event;  // Pokud event je již objekt, není potřeba JSON.parse
  var stringMessage = event.data.rsp.rData;
  var splitMessage = stringMessage.split(".");
  var lengthString = splitMessage.length;
  //calculate
  var firstNumber = splitMessage[lengthString - 2];
  var secondNumber =  splitMessage[lengthString - 1];
  var hexNumber = secondNumber + firstNumber;
  var decimalNumber = parseFloat(hexNumber, 16);
  if (hexNumber[0] == "1") {
    hexNumber = hexNumber.slice(1);
    decimalNumber = parseFloat(hexNumber, 16) * (-1);
  }
  var temperature = decimalNumber * 0.0625;
  // Přidání hodnoty teploty k původnímu objektu JSON
  event.data.rsp.temperature = temperature;

  const response = {
    
    body: JSON.stringify(event),
  };
  return response;
};

And this is my JSON message: { "mType": "iqrfRaw", "data": { "msgId": "6e93f877-df24-4461-960d-fc172dbf2d9d", "rsp": { "rData": "03.00.20.80.0f.00.00.4e.62.01" }, "raw": [ { "request": "03.00.20.00.ff.ff", "requestTs": "2023-11-15T18:01:55.300+01:00", "confirmation": "03.00.20.00.ff.ff.ff.4f.03.08.03", "confirmationTs": "2023-11-15T18:01:55.318+01:00", "response": "03.00.20.80.0f.00.00.4e.62.01", "responseTs": "2023-11-15T18:01:56.095+01:00" } ], "insId": "iqrfgd2-default", "statusStr": "ok", "status": 0 } }

MikMar
已提問 5 個月前檢視次數 96 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南