This is the code as below
#include <LowPower.h>
#include <WaziDev.h>
#include <xlpp.h>
#include <Base64.h>
//#include <i2c_sI7021.h>
//////////////
#include <DHT.h>
#define DHTPIN 2 // what pin on the arduino is the DHT22 data line connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal Arduino
///////////////
// NwkSKey (Network Session Key) and Appkey (AppKey) are used for securing LoRaWAN transmissions.
// You need to copy them from/to your LoRaWAN server or gateway.
// You need to configure also the devAddr. DevAddr need to be different for each devices!!
// Copy'n'paste the DevAddr (Device Address): 26011D00
unsigned char devAddr[4] = {0x26, 0x01, 0x1D, 0x00};
// Copy'n'paste the key to your Wazigate: 23158D3BBC31E6AF670D195B5AED5525
unsigned char appSkey[16] = {0x23, 0x15, 0x8D, 0x3B, 0xBC, 0x31, 0xE6, 0xAF, 0x67, 0x0D, 0x19, 0x5B, 0x5A, 0xED, 0x55, 0x25};
// Copy'n'paste the key to your Wazigate: 23158D3BBC31E6AF670D195B5AED5525
unsigned char nwkSkey[16] = {0x23, 0x15, 0x8D, 0x3B, 0xBC, 0x31, 0xE6, 0xAF, 0x67, 0x0D, 0x19, 0x5B, 0x5A, 0xED, 0x55, 0x25};
int transm = 1;
int counter =0;
//SI7021 si7021;
WaziDev wazidev;
//int pwr = 6;
int readBase64(const void buf, int len);
//char h = (char*) malloc(encLen);
//base64_decode(h, buf, len);
//Serial.print(h);
//free(h);
//return encLen
void setup()
{
Serial.begin(38400);
wazidev.setupLoRaWAN(devAddr, appSkey, nwkSkey);
}
XLPP xlpp(120);
void loop(void)
{
//////////////////
float temp = dht.readTemperature();
float hum = dht.readHumidity();
/////////////////
// 1
// Create xlpp payload.
Serial.println(temp);
Serial.println(hum);
delay(500);
xlpp.reset();
xlpp.addTemperature(1, temp); // °C
xlpp.addRelativeHumidity(1, hum); // %
xlpp.addTemperature(2, transm);
// xlpp.addGPS(1, -1.4, 0.234, 34);
// 2.
// Send paload with LoRaWAN.
serialPrintf("LoRaWAN send ... ");
uint8_t e = wazidev.sendLoRaWAN(xlpp.buf, xlpp.len);
if (e != 0)
{
serialPrintf("Err %d\n", e);
delay(60000);
return;
}
serialPrintf("OK\n");
// 3.
// Receive LoRaWAN message (waiting for 6 seconds only).
serialPrintf("LoRa receive ... ");
uint8_t offs = 0;
long startSend = millis();
e = wazidev.receiveLoRaWAN(xlpp.buf, &xlpp.offset, &xlpp.len, 6000);
long endSend = millis();
if (e != 0)
{
if (e == ERR_LORA_TIMEOUT){
serialPrintf("nothing received\n");
}
else
{
serialPrintf("Err %d\n", e);
}
delay(60000);
return;
}
serialPrintf("OK\n");
serialPrintf("Time On Air: %d ms\n", endSend-startSend);
serialPrintf("LoRa SNR: %d\n", wazidev.loRaSNR);
serialPrintf("LoRa RSSI: %d\n", wazidev.loRaRSSI);
serialPrintf("LoRaWAN frame size: %d\n", xlpp.offset+xlpp.len);
serialPrintf("LoRaWAN payload len: %d\n", xlpp.len);
serialPrintf("Payload: ");
char payload[100];
base64_decode(payload, xlpp.getBuffer(), xlpp.len);
serialPrintf(payload);
serialPrintf("\n");
delay(60000);
}