Lost Data packets while sending Downlink

Hi,

I am facing problem in recieving downlink message to the end node. I am trying to do is like, From Grafana I want to send two parameters at the same time, which is sent to Node-Red via http request and from Node-Red I am sending to TTN Via MQTT to particular end device. I am using Class A device. Until here everything works perfectly. Now, I have connected RAK 3172-E lora module with Psoc5lp microcontroller using UART. Now, I have another UART from M/C to PC, So I can See what LoRa module sent and recieve. For Uplink everything is working fine, but when downlink is send, when I see in terminal the downlink messages breaks. Below, I have attached the photo what I see in Terminal When I send downlink. The red arrow is downlink message.

Capture

Can anyone help me with this?

Thanks in Advance!!!

Can you expand on your meaning of this - it looks like you have a hex string that you can process.

Two important points:

If it can be copied and pasted, please do so, screen shots are only when we can’t copy & paste.

Your payload is enormous, absolutely huge. You will be burning through battery life and be restricted on how often you can send and increase the chances of interference due to air time. How are you encoding your payload?

Hi @descartes ,
Thank you so much for response!

I have send two values at a time {desiredpH = 5 , volume = ‘250’} for example, from garafana to M/c, I have written custom JavaScript payload formatter in TTN for Downlink. Belowis the Downlink payload formatter:

function decodeDownlink(input) {
  var hexData = input.bytes.map(function(byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('');

  var jsonPayload = '';
  for (var i = 0; i < hexData.length; i += 2) {
    jsonPayload += String.fromCharCode(parseInt(hexData.substr(i, 2), 16));
  }

  var payloadObject;
  try {
    payloadObject = JSON.parse(jsonPayload);
  } catch (error) {
    return {
      errors: ["Invalid payload format"],
    };
  }

  var data = {};

  if (typeof payloadObject.desiredph !== 'undefined') {
     data.desiredph=payloadObject.desiredph;
  }
  if (typeof payloadObject.solution_volume !== 'undefined') {
     data.solution_volume=payloadObject.solution_volume;
  }

  return {
    data: data,
    warnings: [],
    errors: []
  };
}

So, In terminal I can’t see this whole data in hex form, instead I see bit by bit, so in between At+SEND comand it will come. But, If I send only {desiredpH = 5} then I can see on my terinal like +EVTRX2:15 and payload in hex. The problem is when I send big payload it is not coming fully instead it is breaking.

Thanks in advance!!!

I’ve formatted the code block with the </> tool on the tool bar, please do the same in future.

I’m not clear how this helps - decodeDownlink is to turn the bytes that are actually transmitted back in to something you want to use. The encodeDownlink function turns what you send via Node-RED in to the bytes to send to the device.

What are you sending from Node-RED?

Please look at this - you’ve circled a long hex string - what is exactly wrong with that - it doesn’t look broken but it does look rather large for two bytes of data.

When do you expect a downlink to arrive?

TRX2:15 looks like a one byte downlink - port 2, decimal 21 - what is the ‘payload in hex’ that you refer to?

Is this a different problem? Or are you saying a big uplink breaks a downlink? This may be related to the question I asked about your uplink:

Far more detail will be required - examples of every step - the downlink data you send to Node-RED, what is the JSON you are sending via MQTT, how you are encoding it on the application server if at all, what is actually sent (you can get this from the console), what is actually received on the serial console and what you expected to arrive.

Hi @descartes

So, In detail explanation would be:

Step1: From Grafana User will enter two values that is desiredph and solution_volume. This both values are sent to Node-red via http request.

Step2: In node-red, I have written javascript function to extract this values and send to TTN VIA MQTT. Below, is the JavaScript function in Node-Red.

// Access the desiredpH, and solution_volume from msg.payload
var desiredpH = msg.payload.ph_value;
var solution_volume = msg.payload.volume;

// Create the payload to send to the MQTT Output node
var payload_desiredpH = {
    desiredph: desiredpH,
    solution_volume: solution_volume
};

// Convert the payload to Base64
var base64Payload_desiredph = Buffer.from(JSON.stringify(payload_desiredpH)).toString('base64');

// Create a new message object to send to the MQTT OUT node
var setph = {
    payload: {
        downlinks: [{
            f_port: 15,
            frm_payload: base64Payload_desiredph,
            priority: "NORMAL"
        }]
    }
};

// Continue to the MQTT Output node
return setph;

Step3: To read the downlink message in TTN, I used the Custom Javascript function , as in TTN first payload will be in Bytes, So I converted it into Hex String, then I converted in Json object to seen actual values inTTN. Below is TTN payloader formatt at downlink side:

function decodeDownlink(input) {
  var hexData = input.bytes.map(function(byte) {
    return ('0' + (byte & 0xFF).toString(16)).slice(-2);
  }).join('');

  var jsonPayload = '';
  for (var i = 0; i < hexData.length; i += 2) {
    jsonPayload += String.fromCharCode(parseInt(hexData.substr(i, 2), 16));
  }

  var payloadObject;
  try {
    payloadObject = JSON.parse(jsonPayload);
  } catch (error) {
    return {
      errors: ["Invalid payload format"],
    };
  }

  var data = {};

  if (typeof payloadObject.desiredph !== 'undefined') {
     data.desiredph=payloadObject.desiredph;
  }
  if (typeof payloadObject.solution_volume !== 'undefined') {
     data.solution_volume=payloadObject.solution_volume;
  }

  if (typeof payloadObject.setOnTime !== 'undefined') {
    data.setOnTime = payloadObject.setOnTime;
  }

  if (typeof payloadObject.setOffTime !== 'undefined') {
    data.setOffTime = payloadObject.setOffTime;
  }

  return {
    data: data,
    warnings: [],
    errors: []
  };
}

Step4: Now, I want this two values i.e.desiredpH=5 and solution_Volume=250, togther to the Micro-Controller with which LoRa module is connected. Now, In micro-controller, I have written code to convert this hex value to Json format and then I am using this values for my purpose. Currently what I see in Terminal is not the whole hex value of both (desiredpH and solution_Volume) together, but instead hex values get break, like in photo 1) circle is hex value when I convert it into Ascii it is showing “ÇVÖR#¢##S” this, then in between uplink is send and again the remaing hex value i.e. 2) circle is hex value when I convert it into Ascii it is showing “:“250”}” this It getting corrupted. I want whole string (desiredpH =5 and solution_Volume =250) in hex format. Currently it is not comming like this So, because of this I cant put interrupt in program also, because I cant see “+EVT RX” so I cannot say that if in buffer “EVT RX” is there stop the uplink and do the downlink coversion. So, I want to make system approproate, like when ever there is downlink, it should stop uplink.

Thanks in Advance!!!

Please re-read my previous answer and address the other points that you have missed:

  1. When do you expect a downlink to arrive?
  2. What is the JSON you are sending via MQTT?
  3. What is actually sent (you can get this from the console)?
  4. What is actually received on the serial console?
  5. What you expected to arrive?

All of these answers should be text that can be copied and pasted.

As regards step 3, you’ve missed this observation:

Answer point 1 above, whilst this idea won’t stop things working, the theory is very wrong.

Hopefully you are aware that people answering on here are volunteers and so it’s up to you to provide the information requested first time.

Before anyone else chimes in, you should also be aware that sending JSON over LoRaWAN is hugely inefficient - I addressed this in my first reply but we’ll solve that problem once we’ve got the end to end bit working.

Hi,

  1. Anytime when the user enters the value from grafana, eventhough there is no uplink data to transfer.

  2. I have mentioned in above code in setp2. I want to send “{desierdpH=5, solution_volume=“250”}”, this is what I have send via MQTT.

  3. In TTN console I am seeing the same what I need to send (“{desierdpH=5, solution_volume=“250”}”).

  4. On serial montior, it is coming like this:
    `6f6c7574696f6e5f766f6c756d65223a22323430227d

    OK

    7574696f6e5f766f6c756d65223a22323430227d`

  5. In serial montior, I except +EVT RX: : <whole Hex value of {desierdpH=5,
    solution_volume=“250”} >

Sorry, I am new to this, So having confusions. I hope, I answered your questions Correctly?

Thanks in Advance!!!

That would only work if you’ve setup the device as Class B or C.

I was asking for clarity, if it’s not clear to those helping, do you want them to guess?

What are the hex values in the console? You should be comparing the hex in the console to the serial debug output.

And what is the “whole hex value” - what exact string of hex characters are you expecting?

And what is the hex that you are sending and receiving when you decode or convert it?

I have configure it as Class C.

In TTN console the hex value I am getting is this : 7B22646573697265647068223A362C22736F6C7574696F6E5F766F6C756D65223A22323430227D

and in serial monitor, it is coming like this:
6F6C7574696F6E5F766F6C756D65223A22323430227D
and also again it will show one time when again the uplink is send.

I am expecting in serial monitor : 7B22646573697265647068223A362C22736F6C7574696F6E5F766F6C756D65223A22323430227D
This what I am expecting.

I didn’t get this point.

Thanks in advance!!

OK, from what you describe the device isn’t behaving like Class C but no matter, it is receiving downlinks when it does an uplink.

If you decode or convert the hex string that you are receiving, what information does it supply? Does it correspond at all with what was sent?

Hi,

Yes Correct.

I just recieve the half HEX string, when I convert that half string, I am getting half information of what I have sent, For example, If I am sending {desierdpH=5, solution_volume=“250”}, What I recive is just me=“250” (when I convert the recieved HEX String).

Thanks in Advance!!!

Where in the world are you (which regional standard applies)? What is the maximum payload size you can transmit at the spreading factor used for the downlink? (Check the uplink to see what spreading factor it uses and tell us)

WHY are you sending json? Have you read about LoRaWAN limitations? (the first item applies in both directions, so for uplink as well as downlink)

So if the system is sending the whole payload (as there are no errors on the console), where may the problem lie on your device? Can you monitor the serial between the 3172 and your MCU.

And as I noted above, someone will tell you about sending text, but you still have an issue that will one day trip up your device, so changing over to a binary payload ASAP would be a good idea.

so you sending the entire “{desierdpH=5, solution_volume=“250”}” as a string and not 5 and 250 as hex values?

if you send just 5 and 250 you array will be a lot shorter than that string, you know the position of where you packed the values, so you don’t require the entire string

search for working with bytes on the forum