microchip_qstripSource TTN Uno

#include <TheThingsNetwork.h>
#include <Wire.h>
#include <SeeedOLED.h>
int sensorPin = A0; ///Sensor for Q-Strip measurement
int sensorValue = 0; ///Default value to reset
int telling; ///Count in secconds to repeat sending data over Lora
String q; ///The Q-Strip value in a string
char buffer[256];
// Set your DevAddr, NwkSKey, AppSKey and the frequency plan
const char *devAddr = “XXXXXXXX”;
const char *nwkSKey = “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
const char *appSKey = “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”;
#define loraSerial Serial1
#define debugSerial SerialUSB
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_EU868
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
void setup()
{
loraSerial.begin(57600);
debugSerial.begin(9600);
Wire.begin();
SeeedOled.init(); //initialze SEEED OLED display
// SerialUSB.begin(115200);
SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
SeeedOled.setPageMode(); //Set addressing mode to Page Mode
SeeedOled.setTextXY(0, 0); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“Starting Up..”); //Print the String
SeeedOled.setTextXY(6, 0); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“Q-Strip Demo”); //Print the String
// Wait a maximum of 10s for Serial Monitor
while (!debugSerial && millis() < 10000)
;
debugSerial.println(“– PERSONALIZE”);
ttn.personalize(devAddr, nwkSKey, appSKey);
debugSerial.println(“– STATUS”);
ttn.showStatus();
}
void loop()
{
debugSerial.println(“– LOOP –“);
// Prepare payload of 1 byte to indicate LED status
byte payload[1];
//payload[0] = (digitalRead(LED_BUILTIN) == HIGH) ? 1 : 0;
payload[0] = analogRead(sensorPin);
sensorValue = 0;
sensorValue = analogRead(sensorPin);
debugSerial.println(sensorValue);
q = String(analogRead(sensorPin));
telling = telling + 1;
String qstripString = String(q);
int length = qstripString.length()+1;
char qlevel[length];
qstripString.toCharArray(qlevel, sizeof(qlevel));
debugSerial.println(telling);
// SeeedOled.init(); //initialze SEEED OLED display
SeeedOled.setTextXY(0, 0); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“TTN UNO NODE 1”); //Print the String
//
SeeedOled.setTextXY(3, 0); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“VALUE”); //Print the String
//
SeeedOled.setTextXY(3, 12); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(” “); //clear the String
//
SeeedOled.setTextXY(3, 12); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(qlevel); //Print the Q-Strip value
//
// //SeeedOled.setTextXY(4,0); //Set the cursor to Xth Page, Yth Column
// //SeeedOled.putString(“LoRa active”); //Print the String
//
SeeedOled.setTextXY(6, 0); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“www.q-strip.com”); //Print the String
// Send it off
if (telling == 120){
ttn.sendBytes(payload, sizeof(payload));
telling =0;
}
delay(1000);
}