How to encode a JSON packet like {"id":{"noData":True}} (Sigfox downlink type)

#1

I want to encode the downlink packet of a Sigfox device.
Two type of packets can be sent:

response={"21f400":{"noData":True}}
response={"21f400":{"downlinkData":"dadadadadadadada"}}

I have done it before in python this way, and it worked fine:

		response={device:{"noData":True}}
		response=json.dumps(response)

In node- red I have tried different options , the last:
msg.payload={deviceId:{"noData":true}}
But It doesn't work.

Any other ideas? Thanks!

0 Likes

#2

If you do that and return the message and send to a debug node what do you see?

0 Likes

#3

Hi Colin and thanks.

Debug node shows:
packetType : msg.payload : Object

object

deviceId: object

downlinkData: "0201020000000000"

I clarify that deviceId is defined in the node as:
var deviceId = flow.get('deviceId')

0 Likes

#4

I can't see how you get that from
msg.payload = {deviceId:{"noData":true"}}
I think I am missing something about what you are doing.
Explain again exactly what you are trying to get in the payload, with an example.

0 Likes

#5

Ah, I think I see a bit of what you are trying to do, if you want
msg.payload={"21f400":{"noData":True}}
where you already have something like
deviceID = "21f400"
Then you can say

msg.payload = {}
msg.payload[deviceID] = {noData: true}
0 Likes

#6

Thank you!!

That worked, finally!

0 Likes