Environmental Sensor
응답
17. 11. 3 오후 4:01

Good afternoon Franjo,

I've discoverd a XDK tutorial on my laptop called "Sensor Guide XDK 110". To make sure that we're looking at the same document I've sended you the pdf Version via Mail.

In this tutorial it is described how to initalize and later read the sensor data of different single sensor or for the environmental sensors.

I'm running a bit into trouble when I try to determine the correct place for implementing the code snippets in my current project.

E.g. chapter 6: 'Envrionmental Sensor'

In which Project folders i exactly need to copy the given codesnippets ( Code 19-24 in the pdf) ?

Furthermore, when I add a code snippet e.g. to my ApplicationTemplate.c i receive a error like:

'Invalid declaration of 'returnOverSamplingValue'.

However, the variable returnOverSamplingValue is given in that way within the training (see code e.g. snippet 21 within the pdf) ?

 

Thank you very much in advance & have a nice weekend

Best regards

Nils

 

 

 

0 (0 투표)
RE: Environmental Sensor
응답
17. 11. 6 오후 6:12 as a reply to Nils Hilser.

Hello Nils,

I have split your request in your old thread in a new one since the old initial issue is already solved. This will give other users with similar questions the benefit to find the thread more easily and to benefit from the proposed solutions as well.

I took a look a the guide as well and I will give you a short introduction about how to use the code.

The code should be used with a XdkApplicationTemplate for starters. All code needs to be pasted into XdkApplicationTemplate.c, here you can declare functions for initializing the sensor and reading it. As an example for initializing, declare:

void initializeSensor(void) {
  // paste code from guide here
}

Afterwards, you can use initializeSensor() in appInitSystem() after BCDS_UNUSED(param2)

Furthermore, Code 19 is used to display the sensor handle you which is neccessary to initialize the used sensor with the API of the environmental sensor. The code snippets 20 to 22 provde a simple implementation using the environmental sensor API Code 23 and 24 provide an overview on how the data can be read from the environmental sensor.

Additionally please note that Code 21 already makes an initialization of the environmental sensor with pre-settings. Code 22 also initializes the sensor (without changing the settings).

If you use Code 21, remove the call of Environmental_init(), and the following if-statement from Code 22.

Regarding your error, I have tried the tutorial to confirm that it works correctly, and it does. I assume that this error will be solved if you follow my instructions.

Please let me know if that was helpful and do not hesitate to ask if you have further questions.

Kind regards,
Franjo

0 (0 투표)
RE: Environmental Sensor
응답
17. 11. 20 오후 12:36 as a reply to Franjo Stjepandic.

Hello Franjo,

i apated my Application template from the previous post (https://xdk.bosch-connectivity.com/community/-/message_boards/message/306413). But still I'm running in some uncertainities.

As you advised I opened a new function called 

void initializeSensor(void) {}

Later in my Application Template within the void appInitSystem(void * CmdProcessorHandle, uint32_t param2) function I 'recalled' the function below the command BCDS_UNUSED(param2).

The only code snippet from the guide I was able to use without receiving an error was code 22.

So I copied the code snippet of code 22 to my application Template. I assume that this script is capable to read my environmental sensor data. 

Within the function static void clientTask(void*pvParameters) I removed/uncommented the msg.payload = "Hello" and replaced it with msg.payloadlen= sizeof(str(returnValue)). In my thinking returnValue is the variable which carries the desired sensor data ?! So the str() function will give me the string of it and sizeof() the required length. Am I correct with this assumption?

However, I do not really understand the difference between code snippet 22 and 23 and 24. Is it correct that code 21 (I'm not able to add this snippet without an error to my application template)and 22 (this one I can copy without a problem to my application template) are basically doing exactly the same thing?

In regard to snippet 23 and 24.. what is the difference to code 21 and 22. I'm asking this because from my understanding all 4 codes have a common denominator --> they read sensor data. Could please explain me more detailed the difference and between the four snippets, as well in regard to their field of application?

In the following you can find my most recent application template. The rest of the files within the project were not changed. They remained the same as in the previous post (see link above).

/* system header files */
#include <stdio.h>
#include "BCDS_Basics.h"
#include "BCDS_WlanConnect.h"
#include "BCDS_NetworkConfig.h"
#include "MQTTClient.h"
#include "MQTTConnect.h"
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

/* own header files */
#include "MQTT_3.1_new.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"

/* Interface for the Gyroscope */
//#include "BCDS_Environmental.h" SETTING FROM GUIDE
#include "EnvironmentalSensor.h"
/* Interface for all sensors on the XDK */
#include "XdkSensorHandle.h"

/* constant definitions ***************************************************** */
#define CLIENT_BUFF_SIZE 1000
/* local variables ********************************************************** */
#define CLIENT_TASK_STACK_SIZE 1024
#define CLIENT_TASK_PRIORITY 1
#define CLIENT_YIELD_TIMEOUT 10
#define SECONDS(x) ((portTickType) (x * 1000) / portTICK_RATE_MS)

Network n;
Client c;


returnValue = Environmental_init(xdkEnvironmental_BME280_Handle);


static unsigned char buf[CLIENT_BUFF_SIZE];
static unsigned char readbuf[CLIENT_BUFF_SIZE];

// PUBLISH TASK IMPLEMENTATION

static uint32_t clientMessageId = 0;

void initializeSensor(void){
    /* Sensor Handler for the BME280 Sensor */

    extern Environmental_HandlePtr_T xdkEnvironmental_BME280_Handle;

    /* initialize environmental sensor */
    if (RETCODE_OK != returnValue) {
    // do something
    }
    /* 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 Conversion Data :\n\rp =%ld Pa\n\rt =%ld mDeg\n\rh =%ld %%rh\n\r", (long int) bme280.pressure, (long int)
    bme280.temperature, (long int) bme280.humidity);

    }
}


static void clientTask(void*pvParameters)
{MQTTMessage msg;
for(;;)
{
vTaskDelay(SECONDS(1));
msg.id = clientMessageId++;
msg.qos = 2;
msg.payload = str(returnValue);
msg.payloadlen= sizeof(str(returnValue));
//msg.payload = "Hello";
//msg.payloadlen = sizeof("Hello")-1;
MQTTPublish(&c, "xdk, &msg); //--> I changed the topic to only "xdk" only
MQTTYield(&c, CLIENT_YIELD_TIMEOUT);
}
}
//VOID APPINITSYSTEM (xTimerHandle xTimer) ! PUBLISH TASK CREATION

void appInitSystem(void * CmdProcessorHandle, uint32_t param2)
{
    if (CmdProcessorHandle == NULL)
    {
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);
    initializeSensor();
    WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "xxxx";
    WlanConnect_PassPhrase_T connectPassPhrase = (WlanConnect_PassPhrase_T)
    "1234";
    WlanConnect_Init();
    NetworkConfig_SetIpDhcp(0);
    Retcode_T rc_wlan=WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);
    printf("rc_wlan: %d\n\r", (int) Retcode_getCode(rc_wlan));
    NewNetwork(&n);
    int rc_connect=ConnectNetwork(&n,"10.4.1.151", 1883); //1883
    printf("rc_connect: %d\n\r", rc_connect);
    MQTTClient(&c, &n, 1000, buf, CLIENT_BUFF_SIZE, readbuf,
    CLIENT_BUFF_SIZE);

    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.willFlag = 0;
    data.MQTTVersion = 3;
    data.clientID.cstring = "xdk123";
    data.keepAliveInterval = 100;
    data.cleansession = 1;
    MQTTConnect(&c, &data);

       xTaskCreate(clientTask, (const char * const) "Mqtt Client App",
       CLIENT_TASK_STACK_SIZE, NULL, CLIENT_TASK_PRIORITY, null);
}


/**@} */
/** ************************************************************************* */
 

I would be very glad for any further help. My aim is to receive sensor data via mqtt on my broker. 

Currently i do not receive any string or as desired sensor data on my broker.

 

 I will send you the entire project as well via mail.

Kind regards

Nils

 

 

 

 

 

 

0 (0 투표)
RE: Environmental Sensor
응답
17. 11. 20 오후 12:41 as a reply to Nils Hilser.

Hello Franjo,

small adaption:

//#include "BCDS_Environmental.h" SETTING FROM GUIDE
#include "EnvironmentalSensor.h"

should be the other way around:

include "BCDS_Environmental.h" SETTING FROM GUIDE
//#include "EnvironmentalSensor.h"

However, this seems not to be the issue.  Btw. what is the differenve between both statements ?

 

Thank you very much in advance

Looking forward to hear from you

 

Kind regards

 

Nils

 

0 (0 투표)
RE: Environmental Sensor
응답
17. 11. 20 오후 3:45 as a reply to Nils Hilser.

Good evening Franjo,

 

while I was working on my piece of code I stumbeld upon the MQTT paho guide. For some reason I forgot the existence of this training... I think this one is exactly doing what i would like to do (sending sensor data via Mqtt). However I was following the instructions of a relatively new version of this Mqtt training. So far the newest I was able to find:
(XDK110: Getting Started Guide with MQTT (Paho Demo)
Document revision 1.5
Document release date July 17, 2017

However, it seems that the paho files are not adapted to the need of applying it under the latest workbench version (3.0) ? 

I adapted the paho Mqtt files with files from a folder eclispse paho folder I still had on my harddrive. Name of this file is org.eclipse.paho.mqtt.embedded-c-1.0.0. The adaption of the MQTT paho files with files of the eclipse paho folder is as well described within the guide. But I was not able to the paho eclispe file which was stored on my harddrive within the internet.

My questions would be the following:

- Is there a complete MQTT paho training for the latest version of the workbench available?
Cause there are many functions delievering an error while creating the project. I was only able to find the new name for a few functions (from workbench 2 to workbench 3) within the XDK forum..

- What makes more sense ? to continue with the reconstruction of my Hello string approach or to 
   spend the time into the MQTT paho training ?

 

Would be glad for any help

 

Thank you in advance

 

Best regards and have a nice evening

 

Nils

 

 

0 (0 투표)