Hello, I am usingarduino MKRWAN to send temperature and flow data to TTN. before, I checked the example code of mkrwan library and it was fine. But when I want to send my temperature readings the code runs but does not send any data to TTN. Even it does not print "Data sent" or "error" as expected in the code. Following is my code. You can test it without any sensor. I guess the problem is with sending float number. I do not know how should I convert it to a format which the modem.print function requires. In additio, for future I am going to send also the flow data , any ideas about it?
#include <MKRWAN.h>
#include <NTC_Thermistor.h>
//NTC temperature sensor initialiyation
#define Temperaure_pin A1
#define REFERENCE_RESISTANCE 10 //The resistance of external resistance used in the circuit
#define NOMINAL_RESISTANCE 50
#define NOMINAL_TEMPERATURE 25
#define B_VALUE 3950
NTC_Thermistor thermistor(Temperaure_pin, REFERENCE_RESISTANCE,NOMINAL_RESISTANCE,NOMINAL_TEMPERATURE,B_VALUE);
//Flow sensor initialization
int Flow_pin = 2; //This is the input pin on the Arduino
double flowrate; //This is the value we intend to calculate.
volatile int count; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
LoRaModem modem;
// Uncomment if using the Murata chip as a module
// LoRaModem modem(Serial1);
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = "70B3D57ED0041301";
String appKey = "3FBCF01064225EE849C1B3EB69ACF6BE";
void setup() {
/////Sensors setup//////////////////////////////////////////////////////////////////////////////
pinMode(Flow_pin, INPUT); //Sets the pin as an input
pinMode(Temperaure_pin, INPUT);
attachInterrupt(digitalPinToInterrupt(Flow_pin), Flow, CHANGE); //Configures interrupt 0 (pin 2 on the Arduino Uno) to run the function "Flow"
/////Sensors setup//////////////////////////////////////////////////////////////////////////////
Serial.begin(115200);
while (!Serial);
// change this to your regional band (eg. US915, AS923, ...)
if (!modem.begin(EU868)) {
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() {
count = 0; // Reset the counter so we start counting from 0 again
interrupts(); //Enables interrupts on the Arduino
delay (1000); //Wait 1 second
noInterrupts(); //Disable the interrupts on the Arduino
//Start the math
Serial.print("Flow (L/min):");
flowrate=count/10;
Serial.println(flowrate); //Print the variable flowRate to Serial
//Temperature calculation
float temperature = thermistor.readCelsius();
Serial.print("Temperature (C): ");
Serial.print(temperature);
Serial.println();
Serial.print("Sending... ");
Serial.println();
int scaledValue = temperature / 3;
byte payload = scaledValue;
Serial.print("Sensor reading = " );
Serial.println(temperature);
Serial.print("Scaled value = " );
Serial.println(scaledValue);
delay(1000);
modem.beginPacket();
modem.write(payload);
int err = modem.endPacket(false);
if (err > 0) {
Serial.println("Data Sent");
} else {
Serial.println("Error");
}
delay(10000);
}
void Flow()
{
count++; //Every time this function is called, increment "count" by 1
}
type or paste code here