Showing localization data on Qubitro

What you need for this project

  • Board WisBlock Base RAK5005.
  • WisBlock Core RAK4630.
  • WisBlock Accelerometer Sensor RAK1904
  • WisBlock GPS Sensor RAK1910
  • USB Cable
  • Access to a LoRaWAN network, or your own LoRaWAN gateway.
  • The Arduino IDE https://www.arduino.cc/en/Main/Software
  • Some Arduino libraries — we will see them later.

Connecting and programming the hardware

Source: RAKWireless.

Preparing the Arduino IDE

Source: RAKWireless.
  • SparkFun LIS3DH Arduino library. This library implements the communication with the LIS3DH accelerometer.
  • SX126x-Arduino library. This library is used to communicate with the SX1262 LoRa transceiver.

The Code

bool doOTAA = true;   // OTAA is used by default. 
#define SCHED_MAX_EVENT_DATA_SIZE APP_TIMER_SCHED_EVENT_DATA_SIZE /**< Maximum size of scheduler events. */
#define SCHED_QUEUE_SIZE 60 /**< Maximum number of events in the scheduler queue. */
#define LORAWAN_DATERATE DR_5 /*LoRaMac datarates definition, from DR_0 to DR_5*/
#define LORAWAN_TX_POWER TX_POWER_15 /*LoRaMac tx power definition, from TX_POWER_0 to TX_POWER_15*/
#define JOINREQ_NBTRIALS 3 /**< Number of trials for the join request. */
DeviceClass_t gCurrentClass = CLASS_A; /* class definition*/
LoRaMacRegion_t gCurrentRegion = LORAMAC_REGION_AU915; /* Region:AU915*/
lmh_confirm gCurrentConfirm = LMH_UNCONFIRMED_MSG; /* confirm/unconfirm packet definition*/
uint8_t gAppPort = LORAWAN_APP_PORT; /* data port*/
//OTAA keys !!!! KEYS ARE MSB !!!!
uint8_t nodeDeviceEUI[8] = {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x33, 0x33};
uint8_t nodeAppEUI[8] = {0xB8, 0x27, 0xEB, 0xFF, 0xFE, 0x39, 0x00, 0x00};
uint8_t nodeAppKey[16] = {0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88};
// ABP keys
uint32_t nodeDevAddr = 0x260116F8;
uint8_t nodeNwsKey[16] = {0x7E, 0xAC, 0xE2, 0x55, 0xB8, 0xA5, 0xE2, 0x69, 0x91, 0x51, 0x96, 0x06, 0x47, 0x56, 0x9D, 0x23};
uint8_t nodeAppsKey[16] = {0xFB, 0xAC, 0xB6, 0x47, 0xF3, 0x58, 0x45, 0xC7, 0x50, 0x7D, 0xBF, 0x16, 0x8B, 0xA8, 0xC1, 0x7C};
unsigned long age;  
gps.f_get_position(&flat, &flon, &age);
flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat;
ilat = flat * 100000;
flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon;
ilon = flon * 100000;
memset(m_lora_app_data.buffer, 0, LORAWAN_APP_DATA_BUFF_SIZE);
m_lora_app_data.port = gAppPort;
m_lora_app_data.buffer[0] = 0x09;
//lat data
m_lora_app_data.buffer[1] = (ilat & 0xFF000000) >> 24;
m_lora_app_data.buffer[2] = (ilat & 0x00FF0000) >> 16;
m_lora_app_data.buffer[3] = (ilat & 0x0000FF00) >> 8;
m_lora_app_data.buffer[4] = ilat & 0x000000FF;
if(direction_S_N == 0)
{
m_lora_app_data.buffer[5] = 'S';
}
else
{
m_lora_app_data.buffer[5] = 'N';
}
//lon data
m_lora_app_data.buffer[6] = (ilon & 0xFF000000) >> 24;
m_lora_app_data.buffer[7] = (ilon & 0x00FF0000) >> 16;
m_lora_app_data.buffer[8] = (ilon & 0x0000FF00) >> 8;
m_lora_app_data.buffer[9] = ilon & 0x000000FF;
if(direction_E_W == 0)
{
m_lora_app_data.buffer[10] = 'E';
}
else
{
m_lora_app_data.buffer[10] = 'W';
}
m_lora_app_data.buffsize = 11;
send_lora_frame();

The Things Network configuration

  • AppEUI: This parameter is an ID that is used during the activation of the device.
  • DevEUI: This is a unique ID to identify the device.
  • AppKey: This is the key used to generate the NwkSKey and AppSKey during OTAA.
  • End device ID: It is a readable name that you can give to your device.
function Decoder(bytes, port) 
{
var longitude_int, latitude_int;
var decoded = {};

if (port === 2)
{
if(bytes[0]==9) // check if the header byte is 9.
{
latitude_int = (bytes[1] << 24) | (bytes[2] << 16) | (bytes[3] << 8) | (bytes[4]);
decoded.latitude = latitude_int / 100000;
decoded.direction_S_N = String.fromCharCode(bytes[5]);
longitude_int = (bytes[6] << 24) | (bytes[7] << 16) | (bytes[8] << 8) | (bytes[9]);
decoded.longitude = longitude_int / 100000;
decoded.direction_E_W = String.fromCharCode(bytes[10]);
return decoded;
}
}
}

Connecting to Qubitro

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store