beegee-tokyo / RAK4631-Kit-4-RAK1906

Example code for WisBlock Environment Sensor with RAK1906 environment sensor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool



WORK IN PROGRESS



RAK4631-Kit-4-RAK1906

Modules RAKstar
This is an example code for WisBlock Environment sensor (WisBlock Kit 4) with RAK1906 environment sensor

REMARK

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.


Hardware used

REMARK

All of these modules can be bought together with a matching enclosure as WisBlock Kit 4

Power consumption

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.


Software used

REMARK

The libraries are all listed in the platformio.ini and are automatically installed when the project is compiled.


Setting up LoRaWAN credentials

The LoRaWAN settings can be defined in three different ways.

1) Setup over BLE

Using the WisBlock Toolbox you can connect to the WisBlock over BLE and setup all LoRaWAN parameters like

  • Region
  • OTAA/ABP
  • Confirmed/Unconfirmed message
  • ...

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-ENVS-xx where xx is the BLE MAC address of the device.

2) Setup over USB port

Using the AT command interface the WisBlock can be setup over the USB port.

A detailed manual for the AT commands are in the AT-Command-Manual ↗️

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 interval in seconds
AT+SENDINT=60
// Set data rate
AT+DR=3
// Set LoRaWAN region (here US915)
AT+BAND=5
// Reset node to save the new parameters
ATZ
// After reboot, start join request
AT+JOIN=1,0,8,10

REMARK

The AT command format used here is NOT compatible with the RAK5205/RAK7205 AT commands.

3) Hardcoded LoRaWAN settings

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_AS923_3;		// LoRa region
// 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!

REMARK 3
The data encoding is based on Cayenne LPP sensor ID's. This makes it very easy to visualize the sensor data in myDevices Cayenne.


Compiled output

The compiled files are located in the ./Generated folder. Each successful compiled version is named as
WisBlock_ENV_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 options

Debug output can be controlled by defines in the platformio.ini
LIB_DEBUG controls debug output of the SX126x-Arduino LoRaWAN library

  • 0 -> No debug outpuy
  • 1 -> Library debug output (not recommended, can have influence on timing)

MY_DEBUG controls debug output of the application itself

  • 0 -> No debug outpuy
  • 1 -> Application debug output

CFG_DEBUG controls the debug output of the nRF52 BSP. It is recommended to keep it off

Example for no debug output and maximum power savings:

[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
	-DAPI_DEBUG=0    ; 0 Disable WisBlock API 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
	adafruit/Adafruit BME680 Library
	beegee-tokyo/WisBlock-API
extra_scripts = pre:rename.py

Payload decoder for Chirpstack and TTN

The payload is encoded in the same format as the RAKwireless WisNode devices. A payload decoder for Chirpstack, TTN and Datacake can be found in the RAKwireless_Standardized_Payload Github repo.

Visualization on DataCake

Real time data

Snapshot

About

Example code for WisBlock Environment Sensor with RAK1906 environment sensor

License:The Unlicense


Languages

Language:C++ 60.6%Language:Python 27.8%Language:C 11.6%