We started this project with the following objective : design an autonomous device that follows the evolution of a green roof after the installation of solar panels.
With this we can study the evolution of biodiversity and the effect of heat island.
Detailed features
The monitoring consists in managing:
- Air/soil moisture
- Air/soil temperature
- Brightness (and even RGB rays)
using the microcontroller and the sensors
Prerequisites
Have knowledge in
- Microcontroller programming (C++)
- How to read a datasheet and extract the most important data
- I2C, SPI, UART, CRC Protocols
How to send data using Sigfox:
- How many message can be sent per day?
- How to build the message? (SQL Queries)
1. Carry out a mapping of all the pins used for the project, depending on the technologies used to interpret the data
2. Programming the microcontroller STM32 NUCLEO-L432KC in terms of
- Retrieving data from the sensors
- Converting the data to send using Sigfox
- Configuring the sleep mode of the microcontroller when the Sigfox module does not send message
3. Setup the IoT Azure Cloud platform following this tutorial : https://github.com/aureleq/sigfox-azure-iothub
4. Configure the dashboard where all the retrieved data will be displayed
- Create charts
- Save data in database
Code Explanation :
Libraries used
#include "mbed.h"
#include "main.h"
#include "DHT.h"
#include "DS1820.h"
#include "TSL2591.h"
#include "TCS3472_I2C.h"
#include "WakeUp.h"
Connections:
#define DHT_INT_PIN D6 //Humidity and temperature
#define DHT_EXT_PIN D9
#define I2C_INT_SDA D0 //I2C1
#define I2C_INT_SCL D1
#define I2C_EXT_SDA D12 //I2C3
#define I2C_EXT_SCL A6
#define SOIL_TEMP_INT_PIN A2 //Soil Temperature
#define SOIL_TEMP_EXT_PIN A4
#define SOIL_MOISTURE_INT_PIN A1 //Ground Humidity
#define SOIL_MOISTURE_EXT_PIN A3
#define SIGFOX_TX D5
#define SIGFOX_RX D4
#define INT_MEASURE 0
#define EXT_MEASURE 1
#define DELAY_SLEEP 60 // 1 min x 20 min
DHT dht_int(DHT_INT_PIN, DHT::DHT22); // D6
DHT dht_ext(DHT_EXT_PIN, DHT::DHT22); // D9
I2C i2c_int(I2C_INT_SDA,I2C_INT_SCL); // SDA_1, SCL_1
I2C i2c_ext(I2C_EXT_SDA,I2C_EXT_SCL); // SDA_3, SCL_3
TCS3472_I2C rgb_int(I2C_INT_SDA,I2C_INT_SCL); // bus I2C 1
TCS3472_I2C rgb_ext(I2C_EXT_SDA,I2C_EXT_SCL); // bus I2C 3
TSL2591 lum_int(i2c_int, TSL2591_ADDR);
TSL2591 lum_ext(i2c_ext, TSL2591_ADDR);
DS1820 soil_temp_int(SOIL_TEMP_INT_PIN); // A2
DS1820 soil_temp_ext(SOIL_TEMP_EXT_PIN); // A4
DigitalOut drive_sigfox(DRIVE_SIGFOX);
//DigitalOut drive_ext(DRIVE_EXT);
//DigitalOut drive_int_1(DRIVE_INT_1); // DHT and 2 I2C int
//DigitalOut drive_int_2(DRIVE_INT_2); // 2 temp sol et hum du sol
AnalogIn soil_hum_int(SOIL_MOISTURE_INT_PIN); // SEN0193 - A1
AnalogIn soil_hum_ext(SOIL_MOISTURE_EXT_PIN); // SEN0193 - A3
Serial sigfox(SIGFOX_TX, SIGFOX_RX);
Serial pc(USBTX, USBRX); // UART
Variables used :
int err_int = 0; // verify DHT_int sample
int err_ext = 0; // verify DHT_ext sample
int x = 0; // used in air_temperature processing
int y = 0; // used in soil_temperature processing
int lum = 0; // used in ReducedLuminosity
uint32_t dataSigfox1_int = 0; // 32 bit
uint32_t dataSigfox2_int = 0;
uint32_t dataSigfox1_ext = 0; // 32 bit
uint32_t dataSigfox2_ext = 0;
uint8_t air_temp_int_reduced = 0; // 8 bit (0.5°C step)
uint8_t air_temp_ext_reduced = 0; // 8 bit (0.5°C step)
uint8_t soil_temp_int_reduced = 0; // 8 bit (0.5 °C step)
uint8_t soil_temp_ext_reduced = 0; // 8 bit (0.5 °C step)
uint8_t air_hum_int_reduced = 0; // 8 bit (0 to 50% - 1% step)
uint8_t air_hum_ext_reduced = 0; // 8 bit (0 to 50% - 1% step)
uint8_t soil_hum_int_reduced = 0; // 8 bit (0 to 50% - 1% step)
uint8_t soil_hum_ext_reduced = 0;
uint8_t lum_int_reduced = 0; // 8 bit (0 to 255)
uint8_t lum_ext_reduced = 0;
uint8_t rgb_int_red = 0; // 8 bit (0 to 255)
uint8_t rgb_int_blue = 0;
uint8_t rgb_ext_red = 0;
uint8_t rgb_ext_blue = 0;
Functions used :
These functions allow to read the values from the sensors and to convert their value in order to make sure it can be stored in a 8 bit variable. The parametre type
tells the function whether is an internal measurement or not.
uint8_t GetAirHumidityReduced(int type)
uint8_t GetAirTempReduced(int type)
uint8_t GetSoilTempReduced(int type)
uint8_t GetSoilHumidityReduced(int type)
uint8_t GetLuminosityReduced(int type)
void printSensorValue_int()
void printSensorValue_ext()
How to build and send the Sigfox message :
Once the measurement is done, the payload is built from all the values and sent to Sigfox network :
// Build Sigfox Payload Frame
dataSigfox1_int = ((uint32_t)(air_temp_int_reduced) << 24) |
((uint32_t)(soil_temp_int_reduced) << 16) |
((uint32_t)(air_hum_int_reduced) << 8) |
((uint32_t)(soil_hum_int_reduced));
dataSigfox2_int = ((uint32_t)(lum_int_reduced) << 24) |
((uint32_t)(rgb_int_red) << 16) |
((uint32_t)(rgb_int_blue) << 8) |
((uint32_t)(INT_MEASURE));
dataSigfox1_ext = ((uint32_t)(air_temp_ext_reduced) << 24) |
((uint32_t)(soil_temp_ext_reduced) << 16) |
((uint32_t)(air_hum_ext_reduced) << 8) |
((uint32_t)(soil_hum_ext_reduced));
dataSigfox2_ext = ((uint32_t)(lum_ext_reduced) << 24) |
((uint32_t)(rgb_ext_red) << 16) |
((uint32_t)(rgb_ext_blue) << 8) |
((uint32_t)(EXT_MEASURE));
// Send Payload Frame
sigfox.printf("AT$SF=%08x%08x\r\n", dataSigfox1_int, dataSigfox2_int);
pc.printf("AT$SF=%08x%08x\r\n", dataSigfox1_int, dataSigfox2_int);
wait(10);
sigfox.printf("AT$SF=%08x%08x\r\n", dataSigfox1_ext, dataSigfox2_ext);
pc.printf("AT$SF=%08x%08x\r\n", dataSigfox1_ext, dataSigfox2_ext);
Comments
Please log in or sign up to comment.