How to add ( or append ) new variables to a payload

hello, i am new here and I am trying to add a variable devEui that will be eaul to a value received in payload

//  new variable  --           
var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
        //inject new variable to data sent with payload -- >>     **devEui: ??? ,**
    },
    headers: {
        "content-type": "application/json"
    }
}

return http_packet;

ADMIN Edit: Wrapped code in a code block (three backticks) for readability

Just set
payload.devEui = 'your content';

Thanks !
If.the Content is another variable coming from the telemetry what is the sintaxis ?

The variable that comes is
"Device_end_id" and the value ( deveui) has to be assigned to devEui
Which is the value recognized by the mqtt broker

If Device_end_id is already a javascript variable then all you need is
http_packet.payload.devEui = Device_end_id
However, I suspect that Device_end_id may not be a simple javascript variable of that name. If so then give us more information about what that variable is.

Add it like the data variable

var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
        devEui: devEui    // <<---- add devEui to payload
    },
    headers: {
        "content-type": "application/json"
    }
}

return http_packet;

alternatively...

var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
    },
    headers: {
        "content-type": "application/json"
    }
}

http_packet.payload.devEui = devEui    // <<---- add devEui to payload

return http_packet;

it should work ! :frowning:

the other TWO VARIABLES network and source come in at the end, but not devEui

replaced deEui with ": test" and it works
image

so the problem is in getting the telemetry value from end_device_id

You are using msg.end_device_id have you checked the msg BEFORE it goes in to the function?

Canned text...
There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

Just remember to prefix the copied path with msg.

hint

it's probably msg.payload.data.end_device_id

thank you ALL.. still working on the receiving end, since the dveui data finally was created, but it goes as header information , not part of the "telemetry" .. next to solve
solution

var devEui = msg.rx_data.end_device_id;

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.