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!!!