Hi guys!
I am really stuck on this project, I'm pretty noob at all this so apologies in advance :D. I am trying to use the MKR WAN 1300 to send LDR sensor and Sharp sensor data to the TTN. So far, here is my following code which I used.
/*
Lora Send And Receive
This sketch demonstrates how to send and receive data with the MKR WAN 1300 LoRa module.
This example code is in the public domain.
*/
#define LDRpin A0 // pin where we connected the LDR and the resistor
int LDRValue = 0; // result of reading the analog pin
#include <MKRWAN.h>
LoRaModem modem;
// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = SECRET_APP_EUI;
String appKey = SECRET_APP_KEY;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);
// change this to your regional band (eg. US915, AS923, ...)
if (!modem.begin(AS923)) {
Serial.println("Failed to start module");
while (1) {}
};
Serial.print("Your module version is: ");
Serial.println(modem.version());
Serial.print("Your device EUI is: ");
Serial.println(modem.deviceEUI());
int connected = modem.joinOTAA(appEui, appKey);
if (!connected) {
Serial.println("Something went wrong; are you indoor? Move near a window and retry");
while (1) {}
}
// Set poll interval to 60 secs.
modem.minPollInterval(60);
// NOTE: independently by this setting the modem will
// not allow to send more than one message every 2 minutes,
// this is enforced by firmware and can not be changed.
}
void loop() {
LDRValue = analogRead(LDRpin); // read the value from the LDR
//Serial.println(LDRValue); // print the value to the serial port
delay(10); // wait a little
Serial.println();
Serial.println("Enter a message to send to network");
Serial.println("(make sure that end-of-line 'NL' is enabled)");
while (!Serial.available());
String msg = Serial.readStringUntil('\n');
Serial.println();
Serial.print("Sending: " + msg + " - ");
Serial.print("Sending: " + LDRValue + " - ");
for (unsigned int i = 0; i < msg.length(); i++) {
Serial.print(msg[i] >> 4, HEX);
Serial.print(msg[i] & 0xF, HEX);
Serial.print(" ");
}
for (unsigned int i = 0; i < LDRValue.length(); i++) {
Serial.print(LDRValue[i] >> 4, HEX);
Serial.print(LDRValue[i] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
int err;
modem.beginPacket();
modem.print(msg);
modem.print(LDRValue);
err = modem.endPacket(true);
if (err > 0) {
Serial.println("Message sent correctly!");
} else {
Serial.println("Error sending message :(");
Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
}
delay(1000);
if (!modem.available()) {
Serial.println("No downlink message received at this time.");
return;
}
char rcv[64];
int i = 0;
while (modem.available()) {
rcv[i++] = (char)modem.read();
}
Serial.print("Received: ");
for (unsigned int j = 0; j < i; j++) {
Serial.print(rcv[j] >> 4, HEX);
Serial.print(rcv[j] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
}
I am getting an error message that :
Arduino: 1.8.5 (Windows 10), Board: "Arduino MKR WAN 1300"
C:\Users\Admin\AppData\Local\Temp\arduino_modified_sketch_912980\LoraSendAndReceive.ino: In function 'void loop()':
LoraSendAndReceive:63: error: invalid operands of types 'const char*' and 'const char [4]' to binary 'operator+'
Serial.print("Sending: " + LDRValue + " - ");
^
LoraSendAndReceive:69: error: request for member 'length' in 'LDRValue', which is of non-class type 'int'
for (unsigned int i = 0; i < LDRValue.length(); i++) {
^
LoraSendAndReceive:70: error: invalid types 'int[unsigned int]' for array subscript
Serial.print(LDRValue >> 4, HEX);
- ^*
LoraSendAndReceive:71: error: invalid types 'int[unsigned int]' for array subscript
_ Serial.print(LDRValue & 0xF, HEX);_
* ^*
exit status 1
invalid operands of types 'const char*' and 'const char [4]' to binary 'operator+'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
PLEASE HELP!