I‘m using the Arduino MKR WAN 1310 to send messages to The Things Stack. The examples of the MKRWAN.h library are referring only to sending strings. This works fine. I’d like to send a byte though, so I changed the code slightly.
// Define an array with a byte
uint8_t msg[1];
byte var = 143;
msg[0] = var;
// Send the message
int err;
modem.beginPacket();
modem.print(msg[0]);
err = modem.endPacket(true);
// Check if the message has been sent correctly
if (err > 0) {
Serial.println("Message sent correctly!");
} else {
Serial.println("Error sending message :(");
}
The message is being send correctly to the TTS, but as it seems as a string. In TTS the string formater gives me the correct result of “143”.
function Decoder(bytes, port) {
var result = "";
for (var i = 0; i < bytes.length; i++) {
result += String.fromCharCode(parseInt(bytes[i]));
}
return { payload: result, };
}
A formater for bytes gives me not the correct result of 143 but of 49.
function Decoder(bytes, port) {
var decoded_var = bytes[0];
return {
var: decoded_var
}
}
Is the MKRWAN.h designed only to send strings to the TTS?