Mount and attach the microcontroller to the motherboard
Mount and fix the sensor on the motherboard
LoRa antenna connects
1. Download the latest version of the Arduino IDE program from the official website and install it on your computer
2. Use the USB-C cable to connect the mode to your computer
3. In the Arduino IDE support for WisBlock is added:
The options called Build and Upload are activated, and the following link is inserted in the field called Additional URLs of the panel manager: https://raw.githubusercontent.com/RAKwireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless_index.json
4. If you choose WisBlock RAK4631 board:
1. Create an account on the https://www.thethingsnetwork.org/ website
2. Connect to TTN - https://eu1.cloud.thethings.network:
3. Create a new application: Click Applications and + Add application
After filling in the fields, click on Create application to complete the configuration.
4. To add a new device, follow these steps:
5. The manual recording method is chosen:
6. Configure the device to connect with TTN by following these steps:
- after verification and loading the code on the device, a check can be made in the TTN console where a "Hello" message in HEX format must be received:
m_lora_app_data_buffer[buffSize++] = 'H';
m_lora_app_data_buffer[buffSize++] = 'e';
m_lora_app_data_buffer[buffSize++] = 'the';
m_lora_app_data_buffer[buffSize++] = 'the';
m_lora_app_data_buffer[buffSize++] = 'o';Step 4: CodeTo connect the sensor RAK1906_Environment_BME690 the following steps are performed:
1. install the SX126x-Arduino library required for the RAK1906 sensor
2. check the environmental sensor in the Arduino IDE starting from an example for the sensor. For this it is accessed
File > Examples > RAK WisBlock Examples > RAK 11300 > Sensors > RAK1906_Environment_BME690
3. After compiling and loading the sample, the data is displayed in the serial monitor:
The following lines are inserted to display the data on the display:
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
Change the function as follows
blank bme680_get()
{char date[32]= {0};
u8g2.begin(); Display Initialization
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB14_tr); Larger, clearer font
Serial.print("Temperature = ");
Serial.print(bme.temperature);
Serial.println(" *C");
memset(data, 0, sizeof(data));
sprintf(data, "T=%.2f C", bme.temperature);
u8g2.drawStr(1,15, date);
Serial.print("Pressure = ");
Serial.print(bme.pressure / 100.0);
Serial.println("hPa");
memset(data, 0, sizeof(data));
sprintf(data, "P=%.2f hPa", bme.pressure/100.0);
u8g2.drawStr(1.30, date);
Serial.print("Humidity = ");
Serial.print(bme.humidity);
Serial.println(" %");
memset(data, 0, sizeof(data));
sprintf(data, "H=%.2f proc", bme.humidity);
u8g2.drawStr(1.45, data);
Serial.print("Gas = ");
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(" KOhms");
memset(data, 0, sizeof(data));
sprintf(data, "R=%.2f Kohm", bme.gas_resistance/1000.0);
u8g2.drawStr(1.60, data);
u8g2.sendBuffer();
Serial.println();
}After checking the sensor, the two examples, for the transmission of data in TTN and the sensor data, will be merged. For this, the file is modified as follows:
- The libraries for the environmental sensor are included:
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
and the following functions:
blank bme680_init()
blank bme680_get()
- The setup() function initializes the sensor by calling the bme680_init() function
- Change the loop() function to read data from the sensor:
if (! bme.performReading())
{
Serial.println("Failed to perform reading :(");
}
bme680_get();- update the sendLoRaFrame function as follows:
uint8_t buffSize = 0;
uint16_t temp = (temperature*100)+5000;
uint16_t press = pressure/100;
uint16_t hum = (humidity*100)+5000;
uint16_t gs = gas_resistence/1000;
m_lora_app_data_buffer[buffSize++] = 0x01;
m_lora_app_data_buffer[buffSize++] = (uint8_t)(temp / 256);
m_lora_app_data_buffer[buffSize++] = (uint8_t)(temp % 256);
m_lora_app_data_buffer[buffSize++] = 0x02;
m_lora_app_data_buffer[buffSize++] = (uint8_t)(press / 256);
m_lora_app_data_buffer[buffSize++] = (uint8_t)(press % 256);
m_lora_app_data_buffer[buffSize++] = 0x03;
m_lora_app_data_buffer[buffSize++] = (uint8_t)(hum / 256);
m_lora_app_data_buffer[buffSize++] = (uint8_t)(hum % 256);
m_lora_app_data_buffer[buffSize++] = 0x04;
m_lora_app_data_buffer[buffSize++] = (uint8_t)(gs / 256);
m_lora_app_data_buffer[buffSize++] = (uint8_t)(gs % 256);
m_lora_app_data.buffsize = buffSize;In the TTN application you go to Payload Formatter at the Uplink option where you choose Custom JavaScript Formatter. Write a function that decodes the data in HEX format like this:
function decodeUplink(input) {
var data = {};
if(input.fPort === 2){
if (input.bytes[0] === 0x01){
Temperature
date. Temp = parseFloat(((((input.bytes[1] * 256.0) + input.bytes[2])-5000) / 100.0).toFixed(2));
}
if (input.bytes[3] === 0x02){
humidity
date. Hum = parseFloat(((((input.bytes[4] * 256.0) + input.bytes[5])-5000) / 100.0).toFixed(2));
}
if (input.bytes[6] === 0x03){
humidity
date. Press = parseFloat(((((input.bytes[7] * 65536.0) + (input.bytes[8]*256)+input.bytes[9]))/100).toFixed(2));
}
if (input.bytes[10] === 0x04){
date. Gas = parseFloat(((((input.bytes[11] * 65536.0) + (input.bytes[12]*256)+input.bytes[13])) / 100.0).toFixed(2));
}
}
return {
date: date,
warnings: [],
bugs: []
};After testing and loading the code into the TTN app, the values read by the RAK1906 sensor should be received.
Data received in the cloud can be sent via external webhooks such as Ubidots.
CodeThe code for the Arduino IDE can be found at the following link: https://s.go.ro/h19abtmh
Bercovici Manuel-Iosub






_M6kErcYJ84.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments