IOT - Bosch
  • Introduction
  • Devices
    • Bosch XDK 110
      • Introduction
      • Operating System
      • Hardware
        • Sensors
          • Accelerometer
            • C
          • Gyroscope
            • C
            • Mita
          • Magnetometer
            • C
          • Environmental
            • C
            • Mita
          • Ambient Light
            • C
            • Mita
          • Acoustic
            • C
      • Software
        • XDK WorkSpace
          • Structure
          • Debug
          • Supported languages
            • C
              • Static Library (.a)
            • XDK Live - Mita
            • MicroFlo
      • Connectivity
        • Bluetooth Low Energy (BLE)
          • Overview
          • General Info
          • Implementation
            • C
            • XDK Live
        • WI-FI
          • OverView
          • Implementation
            • C
            • XDK Live
        • WI-FI Enterprise
      • Protocols
        • CoAP
          • Overview
          • Implementation -TBD
        • HTTP
          • Overview
          • Structure and Methods
          • Implementation
            • C - Rest
            • C - Post
            • XDK Live
        • HTTPS
          • Overview
          • Implementation TBD
        • LWM2M
          • Overview
          • Implementation TBD
        • MQTT
          • Overview
          • Implementation
            • C
            • XDK Live
        • USB
          • Overview
          • Implementation TBD
      • Data Storage
      • XDK Extension Bus
      • Community
      • Applications
        • Language C
          • HomeAssitant - MQTT
            • Prerequisites
            • Server
            • Device
          • IOTA-MQTT-XDK
            • Prerequisites
            • XDK110
            • Mqtt JSON to MAM
            • SensorHub
            • Demo
        • Language XDK Live
          • MQTT
            • Hello World
            • HomeAssistant
              • Prerequisites
              • Server
              • Device
            • Docker-HomeAssistant
          • HTTP
            • Roku Remote Control
              • Roku API
              • MITA
                • Example
    • Bosch AMRA
    • Bosch GLM 100C
    • Bosch FLEXIDOME IP panoramic
    • Bosch GLM 100C
    • Bosch Rexroth Nexo
    • Bosch Rexroth PRC 7000
    • Bosch RRC / CT100
    • Bosch Rexroth IoT Gateway
  • Bosch IOT Solutions
    • Bosch IOT Projects
      • Smart Home
      • Industry 4.0
      • Smart Cities
      • Connected-mobility
    • Bosch IOT Suite
      • Bosch Analytics
      • Bosch IOT Hub
      • Bosch Iot Permission
      • IoT Remote Manager
      • IoT Rollouts
      • IoT Things
      • Demo TBD **
    • BPM and BRM
  • IOTA
    • Introduction
      • Tangle
      • Glossary
      • Differences with other tech
      • How does iota work
      • Developers
    • Qubic
      • What is Qubic?
      • Target
      • Qubic Protocol
    • Ecosystem
    • Applications
      • Python
      • XDK110
        • Prerequisites
        • XDK110
        • Mqtt JSON to MAM
        • SensorHub
    • Bosch/IOTA
  • ByteBall
    • SmartContract
    • Use Case
      • BoshCoins
Powered by GitBook
On this page
  • Considerations
  • Compensating Temperature Data

Was this helpful?

  1. Devices
  2. Bosch XDK 110
  3. Hardware
  4. Sensors
  5. Environmental

C

This code base on language C have the propose to get information about this sensor and display it.

First part that we need to write on our code is the libraries that we are going to use. In this case we are going to use

XdkSensorHandle.h

/************************************************************
*   EnvironmentalSensor.c
************************************************************/

/* system header files */
#include "stdio.h"

/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"

#include "XdkSensorHandle.h"

/* own header files */

A storage struct data need to be declared. The data is then read by the sensor by the Environmental_readData() function and then stored in a passed reference of the storage struct.

The temperature, humidity and pressure measurements can also be read from the environmental sensor separately, if the only one or two of them are needed.

*Snipped/ not part of the code/

Temperature Reading

int32_t getTemperature = INT32_C(0);

Environmental_readTemperature(xdkEnvironmental_BME280_Handle,&getTemperature);

Environmental_readTemperatureLSB(xdkEnvironmental_BME280_Handle,&getTemperature);

Pressure Reading

uint32_t getPressure = INT32_C(0);

Environmental_readPressure(xdkEnvironmental_BME280_Handle,&getPressure);

Environmental_readPressureLSB(xdkEnvironmental_BME280_Handle,&getPressure);

Humidity Reading

uint32_t getHumidity = INT32_C(0);

Environmental_readHumidity(xdkEnvironmental_BME280_Handle,&getHumidity);

Environmental_readHumidityLSB(xdkEnvironmental_BME280_Handle,&getHumidity);

*Continue

// Function that read and print the sensor data of the BME280 to the console of the XDK-Workbench
static void readEnvironmental(xTimerHandle xTimer)
{
    (void) xTimer;

    Retcode_T returnValue = RETCODE_FAILURE;

    /* read and print BME280 environmental sensor data */

    Environmental_Data_T bme280 = { INT32_C(0), UINT32_C(0), UINT32_C(0) };

    returnValue = Environmental_readData(xdkEnvironmental_BME280_Handle, &bme280);

    if ( RETCODE_OK == returnValue) {
        printf("BME280 Environmental Data : p =%ld Pa T =%ld mDeg h =%ld %%rh\n\r",
        (long int) bme280.pressure, (long int) bme280.temperature, (long int) bme280.humidity);
    }
}

Then we declared the function to initialized the sensor and variable. We need to use the function of Environmental_init(xdkEnvironmental_BME280_Handle);

// Function that initializes the Environmental sensor with the BME280 handler and with additional presettings
static void initEnvironmental(void)
{
    Retcode_T returnValue = RETCODE_FAILURE;
    Retcode_T returnOverSamplingValue = RETCODE_FAILURE;
    Retcode_T returnFilterValue = RETCODE_FAILURE;

    /* initialize environmental sensor */

    returnValue = Environmental_init(xdkEnvironmental_BME280_Handle);
    if ( RETCODE_OK != returnValue) {
        printf("BME280 Environmental Sensor initialization failed\n\r");
    }

    returnOverSamplingValue = Environmental_setOverSamplingPressure(xdkEnvironmental_BME280_Handle,ENVIRONMENTAL_BME280_OVERSAMP_2X);
    if (RETCODE_OK != returnOverSamplingValue) {
        printf("Configuring pressure oversampling failed \n\r");
    }

    returnFilterValue = Environmental_setFilterCoefficient(xdkEnvironmental_BME280_Handle,ENVIRONMENTAL_BME280_FILTER_COEFF_2);
    if (RETCODE_OK != returnFilterValue) {
        printf("Configuring pressure filter coefficient failed \n\r");
    }
}

Finally we declared the main part of the program where we need to call all the function that we previously defined. Also define the timers.

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);

    uint32_t timerBlockTime = UINT32_MAX;
    uint32_t oneSecondDelay = UINT32_C(1000);
    uint32_t timerAutoReloadOn = UINT32_C(1);

    xTimerHandle environmentalHandle = NULL;

    initEnvironmental();

    environmentalHandle = xTimerCreate((const char *) "readEnvironmental", oneSecondDelay,timerAutoReloadOn, NULL, readEnvironmental);

    xTimerStart(environmentalHandle,timerBlockTime);
}

Considerations

Compensating Temperature Data

Due to the fact that the environment sensor is attached to the board inside the XDK housing, it measures the temperature inside the housing. This leads to temperatures that deviate from the actual environment temperature, because the XDK’s housing temperature increased on runtime. This also affects the relative humidity, since it depends on the output of the environment sensor’s temperature sensor.

To get more usable temperature values, it is recommended to configure an offset that is applied to the temperature after reading. The following code snippet configures an offset of -5000 to compensate the temperature data by reducing it statically by 5 Kelvin.

int32_t offset =-5000;
// -5000 milliKelvin / -5 Kelvin / -5 Degree Celsius
Environmental_setTemperatureOffset(xdkEnvironmental_BME280_Handle, offset);

If temperature has to be added instead, then the offset has to be configured as a positive integer.

Now that the offset is configured, data can be compensated as follows:

Environmental_readData(xdkEnvironmental_BME280_Handle,&bme280);
Environmental_compensateData(xdkEnvironmental_BME280_Handle,&bme280);

This way, the original data can be stored in another variable if neccessary, before it is compensated. Note that the function for compensation requires the entire BME Data struct, as the relative humidity will be adjusted as well.

The following code will immediately return the compensated data:

Environmental_readCompensatedData(xdkEnvironmental_BME280_Handle, &bme280)
PreviousEnvironmentalNextMita

Last updated 5 years ago

Was this helpful?