![]() |
![]() |
---|---|
This is an example code for WisBlock GNSS tracker with RAK12500 GNSS module and RAK1906 environment sensor
The WisBlock Kit 2 comes with the RAK1910, the RAK1904 and without the RAK1906. To use this example it is suggested to buy
to build the system instead.
This example is using my WisBlock API which helps to create low power consumption application and taking the load to handle communications from your shoulder.
The application does switch off the GPS module and the MCU and LoRa transceiver go into sleep mode between measurement cycles to save power. I could measure a sleep current of 40uA of the whole system.
The libraries are all listed in the platformio.ini
and are automatically installed when
the project is compiled.
The LoRaWAN settings can be defined in three different ways.
Using the WisBlock Toolbox you can connect to the WisBlock over BLE and setup all LoRaWAN parameters like
More details can be found in the WisBlock Toolbox
The device is advertising over BLE only the first 30 seconds after power up and then again for 15 seconds after
wakeup for measurements. The device is advertising as RAK-GNSS-xx
where xx is the BLE
MAC address of the device.
Using the AT command interface the WisBlock can be setup over the USB port.
A detailed manual for the AT commands are in AT-Commands.md
Here is an example for the typical AT commands required to get the device ready (EUI's and Keys are examples):
// Setup AppEUI
AT+APPEUI=70b3d57ed00201e1
// Setup DevEUI
AT+DEVEUI=ac1f09fffe03efdc
// Setup AppKey
AT+APPKEY=2b84e0b09b68e5cb42176fe753dcee79
// Set automatic send frequency in seconds
AT+SENDFREQ=60
// Set data rate
AT+DR=3
// Set LoRaWAN region (here US915)
AT+BAND=8
// Reset node to save the new parameters
ATZ
// After reboot, start join request
AT+JOIN=1,0,8,10
The AT command format used here is NOT compatible with the RAK5205/RAK7205 AT commands.
void api_read_credentials(void);
void api_set_credentials(void);
If LoRaWAN
credentials need to be hardcoded (e.g. the region, the send repeat time, ...) this can be done in
setup_app()
.
First the saved credentials must be read from flash with api_read_credentials();
, then credentials can
be changed. After changing the credentials must be saved with api_set_credentials()
.
As the WisBlock API checks if any changes need to be saved, the changed values will be only saved on the first boot
after flashing the application.
Example:
// Read credentials from Flash
api_read_credentials();
// Make changes to the credentials
g_lorawan_settings.send_repeat_time = 240000; // Default is 2 minutes
g_lorawan_settings.subband_channels = 2; // Default is subband 1
g_lorawan_settings.app_port = 4; // Default is 2
g_lorawan_settings.confirmed_msg_enabled = LMH_CONFIRMED_MSG; // Default is UNCONFIRMED
g_lorawan_settings.lora_region = LORAMAC_REGION_EU868; // Default is AS923-3
// Save hard coded LoRaWAN settings
api_set_credentials();
REMARK 1
Hard coded credentials must be set in void setup_app(void)
!
REMARK 2
Keep in mind that parameters that are changed from with this method can be
changed over AT command or BLE BUT WILL BE RESET AFTER A REBOOT!
The packet data is made compatible with the RAK5205/RAK7205. A
detailed explanation and encoders for TTN and Chirpstack can be found in the RAK5205
Documentation.
Packet parser for Chirpstack and Datacake are in the repo ==> Chirpstack-decode.js and Datacake-decode.js
This application does not include the RAK1904 acceleration sensor, so the data packet does not include the accelerometer part.
The compiled files are located in the ./Generated folder. Each successful compiled version
is named asWisBlock_GNSS_Vx.y.z_YYYYMMddhhmmss
x.y.z is the version number. The
version number is setup in the ./platformio.ini file.
YYYYMMddhhmmss is the
timestamp of the compilation.
The generated .zip
file can be used as well to update the device over BLE using either
WisBlock Toolbox or Nordic nRF Toolbox or
nRF Connect
Debug output can be controlled by defines in the
platformio.ini
_LIB_DEBUG_ controls debug output of the
SX126x-Arduino LoRaWAN library
_MY_DEBUG_ controls debug output of the application itself
_CFG_DEBUG_ controls the debug output of the nRF52 BSP. It is recommended to keep it off
[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
build_flags =
; -DCFG_DEBUG=2
-DSW_VERSION_1=1 ; major version increase on API change / not backwards compatible
-DSW_VERSION_2=0 ; minor version increase on API change / backward compatible
-DSW_VERSION_3=0 ; patch version increase on bugfix, no affect on API
-DLIB_DEBUG=0 ; 0 Disable LoRaWAN debug output
-DMY_DEBUG=0 ; 0 Disable application debug output
-DNO_BLE_LED=1 ; 1 Disable blue LED as BLE notificator
lib_deps =
beegee-tokyo/SX126x-Arduino
sparkfun/SparkFun u-blox GNSS Arduino Library@2.0.13
adafruit/Adafruit BME680 Library
beegee-tokyo/WisBlock-API
extra_scripts = pre:rename.py