Bosch XDK to Bosch IoT Cloud
Answer
9/3/18 10:06 AM

I am trying to connect Bosch XDK toBosch IoT Cloud. I am following the instruction of a tutorial on bosch iot suite website. It is mentioned there to copy the config.txt file to SD card and place the SD card in the sd card slot of XDK but the problem is that I don't have any SD card in my XDK. What should I do? Can I use the XDK without SD card to connect it with Bosch IoT Cloud or not?

Thank you.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/3/18 2:58 PM as a reply to Sajid Baloch.
Hello Sajid,

currently, the connection to the Bosch IoT cloud can only get established with the BoschXDKCloudConnectivity example, using a configuration file on the XDK's plugged SD card.

Since the settings get directly loaded from the config.txt file into the XDKs Wi-Fi chip, there is no workaround without the need of a SD card.

To the SD card requirements:

The XDK supports micro SD cards up to a capacity of 32 GB.
The required filesystem is FAT32.
The filesystems NTFS and SDXC are NOT supported!
To guarantee a smooth performance, class 4 cards and above are highly recommended.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/3/18 3:35 PM as a reply to Franjo Stjepandic.

Thanks for your response. I installed a class 10 SD Card (32-GB) having the config file in root directory and now I am trying to send the data to Bosch IoT cloud. 

- I have created a Thing and set the API Token but still not being able to get the live data. 

Is it due to the authorization/permission? 

How can I get the live data?

Can you please help me and guide me step by step?

I am trying to send the temperature and humidity data to Cloud and get it on any device. Please suggest me the easiest way to do it. Thanks.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/3/18 3:41 PM as a reply to Sajid Baloch.
I also want to ask that I am not being able to create a new subscription. It says "Failed (Quota)". Can you help me in this as well?
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/4/18 3:25 PM as a reply to Sajid Baloch.

Hello Sajid,

first, I require more informations about your use case scenario, before I can conclude about the root of your issue.

Did you follow all instructions at to configure your account settings, in order to receive data from the XDK?

Regarding the live data:
There exists a slider Live Data, which can be found within the same menu as the slider My Things. Using this, you can take a look at the data one of your XDK's streaming over the BoschXDKCloudConnectivity example.

Could you please provide an outline of your XDK-Workbench console, while running the BoschXDKCloudConnectivity example? Yesterday occured an issue, located in the backend, so your problem could be already solved.


This thread here provides further informations.

Also, there exists a slider called API, which you can use to obtain the data for your own application (e.g. requesting to any device with a complementary app).

In regards to the subscription, could you please provide more detail about the subscription itself, you try to generate and also about the location, at which step the process exactly fails?

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/5/18 10:13 AM as a reply to Franjo Stjepandic.

Thanks for your response.


--Did you follow all instructions at to configure your account settings, in order to receive data from the XDK?
                 YES, I did follow all the instructions of the tutorial. I don't know whether I need to do some changes in the BoschXDKCloudConnectivity or not. I haven't changed anything, just flashed the code as it is in th XDK. 


Regarding the live data:
There exists a slider Live Data, which can be found within the same menu as the slider My Things. Using this, you can take a look at the data one of your XDK's streaming over the BoschXDKCloudConnectivity example.

Yes, I am getting the Live Data now. I wasn't getting it before.

 

Can I save the data over Bosch IoT Cloud? I haven't used the IoT Hub, IoT Analytics or any other service but still I am getting the data. Are these services for subscribing or publishing? 

I want to ask, How can I setup my own application to get the value?

What are the options to get the data on a device or app? Can you guide me the easiest way to get the data on any other device? There are no preferences for the device/app.


 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/5/18 2:20 PM as a reply to Sajid Baloch.
Hello Sajid,

thank you for answering the questions.

Good, you followed the tutorial. If your config file, which is stored on the SD card, includes username and password, like in the tutorial explained, there is no need to change the example code at all.

Glad to hear, you are able to receive the live data now.

For storing your data on the Bosch IoT Cloud server, Bosch IoT Things is a good way to go and works with a free account.
A detailed information about this service, you can find at the Bosch IoT Things website . Your questions regarding the wish to share data from the cloud to other devices or applications will probably clear itself when you step into the topic IoT Things. Bosch IoT Things offers huge possibilities, including your imagined scenario.

I deeply advise you to not rush into this topic by the thought of finishing your project as fast as possible.
Better take your time and enjoy all the incoming knowledge for an even better output.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/5/18 3:28 PM as a reply to Franjo Stjepandic.

Thanks for your kind suggestions.

For storing your data on the Bosch IoT Cloud server, Bosch IoT Things is a good way to go and works with a free account.

I am already using Bosch IoT Things. I did registered my XDK as a Thing and that's why being able to get the live data. 

 

A detailed information about this service, you can find at the Bosch IoT Things website . Your questions regarding the wish to share data from the cloud to other devices or applications will probably clear itself when you step into the topic IoT Things. Bosch IoT Things offers huge possibilities, including your imagined scenario.
Okay, I will look into it.


I am still not being able to add new subscription on Bosch IoT Suite. The screenshot is attached.

 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
9/6/18 3:18 PM as a reply to Sajid Baloch.
Hello Sajid,

thank you for your attached screenshot.
Okay, obviously there is an issue with your current IoT Hub subscription, so I suggest you to remove it first.

I reconstructed the scenario with two different subscriptions and had no issues as you can see in the attached screenshot.

Here my proceeded steps you can follow:
 
  1. I went to My Account, then to Service Subscriptions.
    You also can enter the site by clicking this link, if you are logged in as user.
  2. When I clicked the + New Subscription button, a pop up menu appears.
    For the first subscription, I choose Bosch IoT Things.
  3. On the directed service configuration page, I named the instance and created a namespace.
    Followed with the click on Subscribe, the first IoT Things Subscription was done.
    It took a few minutes, then this service was activated.
  4. Back to the Service Subscription page, I repeated steps 2 and 3, except for choosing a IoT Hub subscription this time.
I hope it will work with your next try.
If you still struggle to subscribe to IoT Things, please provide detailed informations about the failure itself.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/16/18 9:40 AM as a reply to Franjo Stjepandic.

Thank you for your support. 

Recently, I tried connecting the XDk witht th Bosch IoT Cloud using the Bosch XDK Cluid connectivity example but it doesn't work accordingly. The example seems to be changed. Has it changed with the updated version of Workbench? If yes, then how can we connect it now? BEcause the tutorial is still the old one.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/16/18 3:00 PM as a reply to Sajid Baloch.

Thank you for your continuous help.

I want to connect the XDK to Amazon DynamoDB and as I depicted from what I have searched, I came to know that I have to code a javascript file in order to publish and subscribe the data and save them to the database.

I don't know from where to start since I am not good in javascript. Can you please guide me in detail how to send the XDK sensor data to the DynamoDB?

 I already setup the XDk and getting the Live Data. But from the old code not with the new example code.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/16/18 4:01 PM as a reply to Sajid Baloch.
Hello Sajid,

the issue regarding the BoschXDKCloudConnectivity example in combination with the latest XDK Workbench 3.4.0 is an already known and reported bug.

Until this bug is fixed, I suggest to use the older BoschXDKCloudConnectivity example from the XDK Workbench 3.3.1. Keep in mind, this BoschXDKCloudConnectivity example needs to be used within the XDK Workbench 3.3.1 and should not be imported into the XDK Workbench 3.4.0.

To your latest post, I can recommend Amazon's JavaScript and DynamoDB developer guide .
To get an idea what it is supposed to look like finished, Amazon also published some DynamoDB Examples . Their site also links an article with API references, which could be helpful.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/17/18 10:39 AM as a reply to Franjo Stjepandic.

Thank you for your response. 

Can you tell me when the bug will be resolved? Is there any way to be notified once it solved?

 

The live data is being displayed on Bosch Iot Things with the help of IoT Things subscription. I want to know, how can I get the selected sensor data and send it to dynamoDB? Do I have to use XDKCloudConnectivity example or any other example code to flash on XDK? I can send the data using javascript but for that I need the data. And for data, I need to code something on XDK from Workbench. 

Thanks a lot for your kind support.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/17/18 11:56 AM as a reply to Sajid Baloch.

Do you think this will solve my problem?

https://xdk.bosch-connectivity.com/community/-/message_boards/message/294438

Because I also want to get the sensor data and save it somewhere in the cloud e.g. DynamoDB. 

Is there any Cloud Storage by Bosch? How can I save the data on Bosch Cloud if there is a service liek that?

So that I can subscribe it from wherever and whenever I want. 

A typical IoT Application.  

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/17/18 11:21 AM as a reply to Sajid Baloch.

What I really want is an IoT application. 

I want to access the XDK sensor values from the internet. 

For example, 

I want to get the value of temperature recorded by XDK in my computer at any time instance. Whenever I want to know the temperature, I should be getting it. 

Can you please explain me how it can be done efficiently and easily?

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/17/18 4:09 PM as a reply to Sajid Baloch.
Hello Sajid,

Unfortunately, I do not know the upcoming release date regarding the bugfix yet, but I will inform you in this thread here, when an update is available.

Regarding your project goals, I would prefer a simple HTTP connection to a HTTP server. With an HTTP POST-request you can transfer the temperature data to the server.
If you decide to show the temperature data on a local or a global website, depends on your interest.

A good HTTP article which includes a full code example for a HTTP POST-request can be found at the XDK knowledgebase , after a free registration and a click at the button getting started . To open the article, choose at the left sided menu the topic Protocols , then click on HTTP .

A second option would be the use of MQTT. MQTT is a much lighter internet protocol than HTTP and optimized for IoT. Instead a HTTP server, it requires a MQTT broker. Devices that want to receive the by the XDK published value need to subscribe to a broker's topic. The linked knowledgebase from above also offers a good MQTT article, which you could take a look at.

For an easy solution, I recommend you the HTTP POST-request. The professional, efficient IoT solution could be the use of MQTT.

To answer your questions from the other posts, when you are talking about DynamoDB, do you mean this in the context of an AWS service, or is any other cloud sufficient? Please note that my suggestions beforehand depend on this, since AWS requires a specific handling regarding establishing a connection to it.

Furthermore, you could also use the data from the BoschXDKCloudConnectivity example, which is provided in the Bosch IoT cloud and send it to your own web service with the integrated HTTP API from the backend of the BoschXDKCloudConnectivity example. Otherwise, I recommend a solution as mentioned in the beginning of this post.

In regards to the cloud storage by Bosch, it depends on the services, the Bosch IoT cloud is providing. I assume the Bosch IoT Insights service from the Bosch IoT cloud could be a service you are looking for.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/18/18 10:22 AM as a reply to Franjo Stjepandic.

Thanks a lot Franjo. 

I think Bosch IoT Insights is the right service for which I am looking for. Can you please explain how can I send and analyse the data from XDK to Bosch IoT Insights? 

I have one more question. Can you please explain the difference between Bosch IoT Analytics and Bosch IoT Insights?

Thank you. 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/18/18 2:56 PM as a reply to Sajid Baloch.
RE: Bosch XDK to Bosch IoT Cloud
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/18/18 3:27 PM as a reply to Sajid Baloch.

Hi. I have seen the knowledgebase and I want to use the MQTT protocol. 

I set up everything accordingly. 

Then, I am getting this compilation error:

Creating .out C:/Users/HP/XDK-Workspace/XDKMQTT/debug/XDKMQTT.out
c:/xdk-workbench/xdk/armgcc/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7-m/crt0.o: In function `start':
(.text+0x4a): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
application.mk:391: recipe for target 'C:/Users/HP/XDK-Workspace/XDKMQTT/debug/XDKMQTT.out' failed
mingw32-make[1]: *** [C:/Users/HP/XDK-Workspace/XDKMQTT/debug/XDKMQTT.out] Error 1
mingw32-make[1]: Leaving directory 'C:/XDK-Workbench/XDK/SDK/xdk110/Common'
Makefile:31: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2

What I depicted is that, there should be a main function which calls the defined function. How can I do it? 

Tell me if I have understood it wrong.

Thank you.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/18/18 3:30 PM as a reply to Sajid Baloch.

/* own header files */
#include "XdkAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_APP_CONTROLLER

/* system header files */
#include <stdio.h>
#include "XdkSystemStartup.h"
/* additional interface header files */
#include "BCDS_CmdProcessor.h"
#include "FreeRTOS.h"
#include "BCDS_NetworkConfig.h"
#include "BCDS_WlanConnect.h"
#include "BCDS_ServalPal.h"
#include "BCDS_ServalPalWiFi.h"
#include "PAL_initialize_ih.h"
#include "AppController.h"
// MQTT API
#include "Serval_Mqtt.h"

/* --------------------------------------------------------------------------- |
 * HANDLES ******************************************************************* |
 * -------------------------------------------------------------------------- */
static CmdProcessor_T * AppCmdProcessor;
static CmdProcessor_T CmdProcessorHandleServalPAL;

/* --------------------------------------------------------------------------- |
 * VARIABLES ***************************************************************** |
 * -------------------------------------------------------------------------- */

#define TASK_PRIORITY_SERVALPAL_CMD_PROC            UINT32_C(3)
#define TASK_STACK_SIZE_SERVALPAL_CMD_PROC          UINT32_C(600)
#define TASK_QUEUE_LEN_SERVALPAL_CMD_PROC           UINT32_C(10)

#define MQTT_BROKER_HOST "broker.hivemq.com"
#define MQTT_BROKER_PORT 1883
static MqttSession_T session;
static MqttSession_T *session_ptr = &session;

/* --------------------------------------------------------------------------- |
 * EXECUTING FUNCTIONS ******************************************************* |
 * -------------------------------------------------------------------------- */

static Retcode_T ServalPalSetup(void)
{
    Retcode_T returnValue = RETCODE_OK;
    returnValue = CmdProcessor_Initialize(&CmdProcessorHandleServalPAL, (char *)"Serval PAL", TASK_PRIORITY_SERVALPAL_CMD_PROC, TASK_STACK_SIZE_SERVALPAL_CMD_PROC, TASK_QUEUE_LEN_SERVALPAL_CMD_PROC);
    /* serval pal common init */
    if (RETCODE_OK == returnValue)
    {
        returnValue = ServalPal_Initialize(&CmdProcessorHandleServalPAL);
    }
    if (RETCODE_OK == returnValue)
    {
        returnValue = ServalPalWiFi_Init();
    }
    if (RETCODE_OK == returnValue)
    {
        ServalPalWiFi_StateChangeInfo_T stateChangeInfo = { SERVALPALWIFI_OPEN, 0 };
        returnValue = ServalPalWiFi_NotifyWiFiEvent(SERVALPALWIFI_STATE_CHANGE, &stateChangeInfo);
    }
    return returnValue;
}

void networkSetup(void) {
    WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "HT16Pro";
    WlanConnect_PassPhrase_T connectPassPhrase = (WlanConnect_PassPhrase_T) "437185b2f716";
    WlanConnect_Init();
    NetworkConfig_SetIpDhcp(0);
    WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);

    ServalPalSetup();

    NetworkConfig_IpSettings_T myIp;
    NetworkConfig_GetIpSettings(&myIp);

    // insert a delay here, if the IP is not properly printed
    printf("The IP was retrieved: %u.%u.%u.%u \n\r",
        (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 3)),
        (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 2)),
        (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 1)),
        (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 0)));
}

retcode_t init(void) {
    retcode_t rc_initialize = Mqtt_initialize();
    if (rc_initialize == RC_OK) {
        session_ptr = &session;
        Mqtt_initializeInternalSession(session_ptr);
    }
    return rc_initialize;
}

static void subscribe(void) {
    static char *sub_topic = "your/publish/topic";
    static StringDescr_T subscription_topics[1];
    static Mqtt_qos_t qos[1];
    StringDescr_wrap(&(subscription_topics[0]), sub_topic);
    qos[0] = MQTT_QOS_AT_MOST_ONE;
    Mqtt_subscribe(session_ptr, 1, subscription_topics, qos);
}

static void publish(void) {
    static char *pub_message = "Hello World";
    static char *pub_topic = "your/publish/topic";
    static StringDescr_T pub_topic_descr;
    StringDescr_wrap(&pub_topic_descr, pub_topic);

    Mqtt_publish(session_ptr, pub_topic_descr, pub_message, strlen(pub_message),
            MQTT_QOS_AT_MOST_ONE, false);
}

static void handleIncomingPublish(MqttPublishData_T publishData) {
    int topic_length = publishData.topic.length + 1;
    int data_length = publishData.length + 1;
    char published_topic_buffer[topic_length];
    char published_data_buffer[data_length];
    snprintf(published_topic_buffer, topic_length, publishData.topic.start);
    snprintf(published_data_buffer, data_length, (char *) publishData.payload);
    printf("Incoming Published Message:\n\r"
            "\tTopic: %s\n\r"
            "\tPayload: %s\n\r", published_topic_buffer, published_data_buffer);
}

static void handleConnection(MqttConnectionEstablishedEvent_T connectionData) {
    int rc_connect = (int) connectionData.connectReturnCode;
    printf("Connection Event:\n\r"
            "\tServer Return Code: %d (0 for success)\n\r", (int) rc_connect);
}

retcode_t eventHandler(MqttSession_T* session, MqttEvent_t event,
        const MqttEventData_t* eventData) {
    BCDS_UNUSED(session);
    switch (event) {
    case MQTT_CONNECTION_ESTABLISHED:
        handleConnection(eventData->connect);
        // subscribing and publishing can now be done
        subscribe();
        //publish();
        break;
    case MQTT_CONNECTION_ERROR:
        handleConnection(eventData->connect);
        break;
    case MQTT_INCOMING_PUBLISH:
        handleIncomingPublish(eventData->publish);
        break;
    case MQTT_SUBSCRIPTION_ACKNOWLEDGED:
        printf("Subscription Successful\n\r");
        publish();
        break;
    case MQTT_PUBLISHED_DATA:
        printf("Publish Successful\n\r");
        break;
    default:
        printf("Unhandled MQTT Event: %d\n\r", event);
        break;
    }
    return RC_OK;
}

void configSetTarget(void) {
    static char mqtt_broker[64];
    const char *mqtt_broker_format = "mqtt://%s:%d";
    char server_ip_buffer[13];
    Ip_Address_T ip;

    PAL_getIpaddress((uint8_t *) MQTT_BROKER_HOST, &ip);
    Ip_convertAddrToString(&ip, server_ip_buffer);
    sprintf(mqtt_broker, mqtt_broker_format, server_ip_buffer,
            MQTT_BROKER_PORT);

    SupportedUrl_fromString(mqtt_broker, (uint16_t) strlen(mqtt_broker),
            &session_ptr->target);
}

void configSetConnectData(void) {
    static char *device_name = "XDK110_Guide_Device";
    session_ptr->MQTTVersion = 3;
    session_ptr->keepAliveInterval = 100;
    session_ptr->cleanSession = true;
    session_ptr->will.haveWill = false;

    StringDescr_T device_name_descr;
    StringDescr_wrap(&device_name_descr, device_name);
    session_ptr->clientID = device_name_descr;
}

void configSetEventHandler(void) {
    session_ptr->onMqttEvent = eventHandler;
}

retcode_t connectToBroker(void) {
    retcode_t rc = RC_INVALID_STATUS;
    rc = Mqtt_connect(session_ptr);
    if (rc != RC_OK) {
        printf("Could not connectToBroker, error 0x%04x\n", rc);
    }
    return rc;
}

int main(void)
{
    /* Mapping Default Error Handling function */
    Retcode_T retcode = Retcode_Initialize(DefaultErrorHandlingFunc);
    if (RETCODE_OK == retcode)
    {
        retcode = systemStartup();
    }
    if (RETCODE_OK == retcode)
    {
        retcode = CmdProcessor_Initialize(&AppCmdProcessor, (char *) "AppCmdProcessor", TASK_PRIO_MAIN_CMD_PROCESSOR, TASK_STACK_SIZE_MAIN_CMD_PROCESSOR, TASK_Q_LEN_MAIN_CMD_PROCESSOR);
    }
    if (RETCODE_OK == retcode)
    {
        /* Here we enqueue the application initialization into the command
         * processor, such that the initialization function will be invoked
         * once the RTOS scheduler is started below.
         */
        retcode = CmdProcessor_Enqueue(&AppCmdProcessor, AppController_Init, &AppCmdProcessor, UINT32_C(0));
    }
    if (RETCODE_OK == retcode)
    {
        /* start scheduler */
        vTaskStartScheduler();
        /* Code must not reach here since the OS must take control. If not, we will assert. */
    }
    else
    {
        Retcode_RaiseError(retcode);
        printf("main : XDK System Startup failed.\r\n");
    }
    assert(false);
}
/** ************************************************************************* */

This is my code with main function. There are no errors but when I flash it on XDK. The XDK isn't being connected to the WLAN. Do I need to use SD Card with config setttings or not?

I don't know where the problem is. It gets flashed and does nothing.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/19/18 2:04 PM as a reply to Sajid Baloch.
Hello Sajid,

Let me explain you the differences between Bosch IoT Analytics and Bosch IoT Insights first.

Bosch IoT Insights is about receiving and storing the data from IoT devices. It supports many connection protocols like HTTP, HTTPS, MQTT, etc. The incoming data can even be stored as database (NoSQL/MongoDB based) and visualized within dashboards.

Bosch IoT Analytics is a bit different.
It is optimized for already existing databases, to use intelligent algorithms in order to find out anomaly behavior with almost none delay.

For example, if the usual temperature value is like 30 degrees Celsius and it increases drastically to maybe 40 degrees Celsius, the Bosch IoT Analytics will detect this and will perform further handling regarding that anomaly.

To use Bosch IoT Insights, you first need to add a service subscription on Insights.
By adding the subscription, you need to name the instance with a unique name.

After adding the new subscription, you can click on Credentials of your listed Insights subscription. All information to connect to Insights like username, password, service URL, dashboard URL, data recorder URL and the project ID are listed there.

The detailed Insights user guide will answer all your questions to establish a connection to Insights and use the dashboard to view your data online.
On the side of the XDK, you could choose for example between HTTP and MQTT for the transport way to the Bosch IoT Insights server. Both previously mentioned knowledgebase articles (MQTT and HTTP), depending on your choice, are recommended to start from.

Before I answer your question about the way to call the coded source code functions, I would like to give you some basic advice about coding with the XDK.

In the general world of C-coding is the main function the start of the program.
Usually in C, for example with the Arduino, the common way to change the program, is to modify the code within the main file.
In the world of the Bosch XDK, the main file contains the function which is used for the startup of the device (RTOS scheduler start, enqueuing of applications and so on).

Therefore it is important to not change this file .
Rather than using the file main.c, always use the AppController.c file.

Regarding your current issue, there is no need to use an SD card for the settings.
All you need to do is to call the networkSetup() function, which is something you missed to do.

With the input I gave you above, use the AppControllerSetup() function within the AppController.c file for the necessary function call.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/27/18 2:33 PM as a reply to Franjo Stjepandic.

Hi,

Thanks for your help. I followed your instructions and now I can send teh data from XDK to server using MQTT and HTTP as well. 

I also followed teh Insight User Guide and displayed the sample data of Water Consumption. 

 

Now, I want to send the data from XDK directly to Insights to be displayed. 

In the tutorial, they are usign sample data (saved data), I want to send sensor recorded data directly from XDK. I think I have to use HTTP for that. 

Can you please explain how can I do it?

If I receive the data on Insights, then I can display it following the tutorial of Water Consumption example. That is clear. 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/29/18 4:06 PM as a reply to Sajid Baloch.
Hello Sajid,

according to the official insight user guide , you can use the HTTP Data Recorder Service for sending data from your XDK to the Cloud.

For testing purpose, you could use the JSON file provided with the watermeter example, store it to your SD card, read it and send it via HTTP. To send the data directly from the XDK, you would need to create an HTTP POST request and send your data in JSON format to the data recorder server with the following URL: https://bosch-iot-insights.com/data-recorder-service . Furthermore, I recommend especially taking a look at chapter 5.2 of the insight user guide, since it will give you more detailed information about this process and how to implement it correctly.

If that works without issues, you could add your own XDK sensor data in the same format into your application, remove the SD card parts and send the sensor data right away via HTTP to the HTTP Data Recorder Service .

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/30/18 1:17 PM as a reply to Franjo Stjepandic.

Hi,

 

I am using Htpp Post request example from knowledgebase and replacing the Ip address with the IP address of bosch IoT Suite and changing setREqURL. 

This the function after changes:

void createAndSendPostMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    Ip_convertOctetsToAddr(139, 15, 6, 103, &destAddr);
    Ip_Port_T port = Ip_convertIntToPort(80);

    Msg_T* msg_ptr;
    HttpClient_initRequest(&destAddr, port, &msg_ptr);
    HttpMsg_setReqMethod(msg_ptr, Http_Method_Post);
    HttpMsg_setReqUrl(msg_ptr, "/data-recorder-service/v2/zz0003883347229");

    Msg_prependPartFactory(msg_ptr, &writeNextPartToBuffer);

    // send the request
    static Callable_T sentCallable;
    Callable_assign(&sentCallable, &onHTTPRequestSent);
    HttpClient_pushRequest(msg_ptr, &sentCallable, &onHTTPResponseReceived);
}

 

Where and how can I do the authentication?

Which username and password should I use when doing the basic authorization of sending the data to data service recorder?

How can I use JSON format of sending the data?

Suppose, I am sending this message

{"data":

[ { "Name":"Sajid",  "Age": 27, "City":"Stuttgart" } ]

}

 

 

 

 

In the IoT insights user guide,

There are no C language code example to send the data to the Bosch IoT Insights backend. 

There are examples in other languages like Python, MATLAB, C#, C++, Java. 

And the HTTP post request in the knowledgebase is in Objective C.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/30/18 4:04 PM as a reply to Sajid Baloch.
Dear Sajid,

For inserting the authentification, basic authentication with a username and passphrase should suit best for your use case.

In that regard, you can insert the credentials via the HTTP header into the HTTP request. For that, I recommend taking a look at the subarticle Headers in the HTTP article of the XDK Knowledgebase.

Futhermore, you should use the username and passphrase provided by the service itself.

Regarding the JSON payload, this can simple inserted into the payload variable of the function writeNextBuffer() as shown below:

 

const char* payload = "{"data":
[
{ "Name":"Sajid", "Age": 27, "City":"Stuttgart" }
]
}";


Additionally, please note that the examples within the XDK knowledgebase are all based on the programming language C, not objective C. As such, you can consider using the C++ examples from the IoT Insight user guide, since C++ is only an extension of C with object orientation.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/30/18 4:51 PM as a reply to Franjo Stjepandic.
const char* payload = "{"data":
[
{ "Name":"Sajid", "Age": 27, "City":"Stuttgart" }
]
}";

this thing isn't working

I am getting errors.

SCreenshots are attached. 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/31/18 10:20 AM as a reply to Sajid Baloch.
Hello Sajid,

Unfortunately, I missed the fact, that the quotation marks require an additional backslash to be used in a string. Otherwise, these are recognized as string starting and ending element.

As such, I recommend adding a backslash before every quotation mark in your JSON string as shown below.
 
const char* payload = "{ \"data\" :[{ \"Name\":\"Sajid\" , \"Age\":27, \"City\":\"Stuttgart\" }]}";

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
+1 (1 Vote)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/31/18 10:37 AM as a reply to Franjo Stjepandic.

HI, Thank you. Now, the errors are gone. 

But still the connection is not successful. 

THis is the error:

 INFO | XDK DEVICE 1: Failed to receive HTTP response!
 

I think it is due to authentication. I have tried doing it like you said : In that regard, you can insert the credentials via the HTTP header into the HTTP request.

void createAndSendPostMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    Ip_convertOctetsToAddr(139, 15, 6, 103, &destAddr);
    Ip_Port_T port = Ip_convertIntToPort(80);

    Msg_T* msg_ptr;
    HttpClient_initRequest(&destAddr, port, &msg_ptr);
    HttpMsg_setReqMethod(msg_ptr, Http_Method_Post);
    HttpMsg_setHost(msg_ptr, "https://bosch-iot-insights.com/data-recorder-service/v2/zz0003883347229");
    HttpMsg_setReqUrl(msg_ptr, "/data-recorder-service/v2/zz0003883347229");

    Msg_prependPartFactory(msg_ptr, &writeNextPartToBuffer);

    // send the request
    static Callable_T sentCallable;
    Callable_assign(&sentCallable, &onHTTPRequestSent);
    HttpClient_pushRequest(msg_ptr, &sentCallable, &onHTTPResponseReceived);
}

 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/31/18 10:52 AM as a reply to Sajid Baloch.

I am also trying to make a template once I get the data. 

For that I am trying to follow the user guide. In Step 2 of user guide, Create a template,

Point 5 says that Copy the prefabricated text to the command line.

I don't get it. Which one is prefabricated text?

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
10/31/18 12:45 PM as a reply to Sajid Baloch.
How can I send the temperature sensor using the same code. Just to replace the JSON formatted text which I am trying to send right now with the sensor value and the current time.
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/2/18 1:09 PM as a reply to Sajid Baloch.
Dear Sajid,

The integration of the custom header would need to be done over the authentication header, not the host header.

An example for that would be as below:
 
"Authorization: Basic username\:passphrase\r\n"

This string would then need to be serialized as described in the subarticle Custom Header at the HTTP section in the XDK knowledgebase.

In regards of your template question, could you please provide the source were you got this from? Unfortunately, I am currently not able to follow.

In regards to adding temperature data and a time stamp into the JSON string, you can build this as follows:
 
char *jsonFormat = "{"timestamp":"%d", "temperature":"%d"}";

int length = snprintf(http_buffer, HTTP_BUFFER_SIZE, jsonFormat,
(int) timeStampValue,temperatureValue);

Please note, that the buffer jsonFormat holds your actual JSON format and that the temperature and timestamp data is then serialized over the function snprintf() into the buffer http_buffer , which should be send out via your POST requests. The variable HTTP_BUFFER_SIZE holds the fixed length of the http_buffer , while the variable length holds the actual elements within the buffer.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/2/18 2:48 PM as a reply to Sajid Baloch.

Thank you very much for your response.

I tried doing the authorization using custom header. I don't know whether I am doing the custom header right or not.

retcode_t serializeMyHeaders(OutMsgSerializationHandover_T* handover)
{
    handover->len = 0;
    static const char* header1 = "Authorization: Basic abCXYz\r\n";
    TcpMsg_copyStaticContent(handover, header1, strlen(header1));
    handover->position = 1;
    return RC_OK;
}

void createAndSendPostMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    Ip_convertOctetsToAddr(139, 15, 6, 103, &destAddr);
    Ip_Port_T port = Ip_convertIntToPort(80);

    Msg_T* msg_ptr;
    HttpClient_initRequest(&destAddr, port, &msg_ptr);
    HttpMsg_serializeCustomHeaders(msg_ptr, serializeMyHeaders);
    HttpMsg_setReqMethod(msg_ptr, Http_Method_Post);
    HttpMsg_setReqUrl(msg_ptr, "https://bosch-iot-insights.com/data-recorder-service/v2/zz0003883347229");

    Msg_prependPartFactory(msg_ptr, &writeNextPartToBuffer);

    // send the request
    static Callable_T sentCallable;
    Callable_assign(&sentCallable, &onHTTPRequestSent);
    HttpClient_pushRequest(msg_ptr, &sentCallable, &onHTTPResponseReceived);
}

I am still getting this error:

 INFO | XDK DEVICE 1: Failed to receive HTTP response!

I tried to implement the timestamp and temperature format using your piece of code. But there are some errors like timestamp not resolved, %d statement has no effect and many more. I done that in writeNextPartToBuffer function.

 

Additionally, I want to ask you, how can I deal with the incoming data on the template end?

Just as if I am sending the timestamp and temperature data, then How will I write the template code?

Either it's Aggregation or Distinct. I don't have any idea about how to write the queries in template designer. 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/5/18 5:18 PM as a reply to Sajid Baloch.
Hello Sajid,

Regarding the authorization header, did you use base64 to encode username and password?
I guess your header might have been overridden by the other header configurations, because the serialization of the custom header needs to be called exactly before the function Msg_prependPartFactory() gets called to serialize the HTTP payload.

Regarding the fifth point on your screenshot from the IoT Insights Guide , the template code below is meant to be pasted in terms to follow the specific example.
[{
"$unwind": "$payload.measurements"
},
{
"$match": {
"payload.measurements.timestamp": {
"$gte": {
"$date": "2018-06-30T22:00:00.000Z"
},
"$lte": {
"$date": "2018-07-30T22:00:00.000Z"
}
}
}
},
{
"$project": {
"_id": 0,
"metadata": -1,
"meter": "$payload.measurements.meter",
"value": "$payload.measurements.value",
"timestamp": "$payload.measurements.timestamp"
}
},
{
"$match": {
"meter": "Flat 1"
}
},
{
"$group": {
"_id": {
"meter": "$meter",
"day": {
"$dateToString": {
"format": "%Y-%m-%d",
"date": "$timestamp"
}
}
},
"value": {
"$sum": "$value"
}
}
},
{
"$project": {
"_id": 0,
"Flat No": "$_id.meter",
"Day": "$_id.day",
"Liter": {
"$trunc": "$value"
},
"Measurements": "$count"
}
},
{
"$sort": {
"Flat No": 1,
"Day": 1
}
}
]

To receive Insights sided the correct object values from your XDK, the example template code from above has to be adapted to your actual project objects, which are to receive.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/6/18 12:58 AM as a reply to Franjo Stjepandic.

Hi,

Thanks for the response. 

"Regarding the authorization header, did you use base64 to encode username and password?"

Yes, I did.

"I guess your header might have been overridden by the other header configurations, because the serialization of the custom header needs to be called exactly before the function Msg_prependPartFactory() gets called to serialize the HTTP payload."

Done that. Stil getting the same error :

 INFO | XDK DEVICE 1: Failed to receive HTTP response!

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/6/18 1:02 PM as a reply to Sajid Baloch.
/* own header files */
#include "XdkAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_APP_CONTROLLER

/* system header files */
#include <stdio.h>

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

#include "BCDS_WlanConnect.h"
#include "BCDS_NetworkConfig.h"
#include "BCDS_ServalPal.h"
#include "BCDS_ServalPalWiFi.h"
#include "Serval_HttpClient.h"
#include "Serval_Http.h"
#include "PIp.h"



static CmdProcessor_T * AppCmdProcessor;/**< Handle to store the main Command processor handle to be used by run-time event driven threads */
static CmdProcessor_T CmdProcessorHandleServalPAL;

/* --------------------------------------------------------------------------- |
 * VARIABLES ***************************************************************** |
 * -------------------------------------------------------------------------- */

#define TASK_PRIORITY_SERVALPAL_CMD_PROC            UINT32_C(3)
#define TASK_STACK_SIZE_SERVALPAL_CMD_PROC          UINT32_C(600)
#define TASK_QUEUE_LEN_SERVALPAL_CMD_PROC           UINT32_C(10)

/* --------------------------------------------------------------------------- |
 * EXECUTING FUNCTIONS ******************************************************* |
 * -------------------------------------------------------------------------- */

static Retcode_T ServalPalSetup(void)
{
    Retcode_T returnValue = RETCODE_OK;
    returnValue = CmdProcessor_Initialize(&CmdProcessorHandleServalPAL, (char *)"Serval PAL", TASK_PRIORITY_SERVALPAL_CMD_PROC, TASK_STACK_SIZE_SERVALPAL_CMD_PROC, TASK_QUEUE_LEN_SERVALPAL_CMD_PROC);
    /* serval pal common init */
    if (RETCODE_OK == returnValue)
    {
        returnValue = ServalPal_Initialize(&CmdProcessorHandleServalPAL);
    }
    if (RETCODE_OK == returnValue)
    {
        returnValue = ServalPalWiFi_Init();
    }
    if (RETCODE_OK == returnValue)
    {
        ServalPalWiFi_StateChangeInfo_T stateChangeInfo = { SERVALPALWIFI_OPEN, 0 };
        returnValue = ServalPalWiFi_NotifyWiFiEvent(SERVALPALWIFI_STATE_CHANGE, &stateChangeInfo);
    }
    return returnValue;
}

void networkSetup(void) {

    WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "DESKTOP-VVA3GB9 6887";
    WlanConnect_PassPhrase_T connectPassPhrase =
            (WlanConnect_PassPhrase_T) "password123";
    WlanConnect_Init();
    NetworkConfig_SetIpDhcp(0);
    WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);

    ServalPalSetup();
}

retcode_t writeNextPartToBuffer(OutMsgSerializationHandover_T* handover)
{
    const char* payload = "{ \"data\" :[{ \"Name\":\"Sajid\" , \"Age\":27, \"City\":\"Stuttgart\" }]}";
    uint16_t payloadLength = (uint16_t) strlen(payload);
    uint16_t alreadySerialized = handover->offset;
    uint16_t remainingLength = payloadLength - alreadySerialized;
    uint16_t bytesToCopy;
    retcode_t rc;

    if ( remainingLength <= handover->bufLen ) {
        bytesToCopy = remainingLength;
        rc = RC_OK;
    }
    else {
        bytesToCopy = handover->bufLen;
        rc = RC_MSG_FACTORY_INCOMPLETE;
    }

    memcpy(handover->buf_ptr, payload + alreadySerialized, bytesToCopy);
    handover->offset = alreadySerialized + bytesToCopy;
    handover->len = bytesToCopy;
    return rc;
}

static retcode_t onHTTPResponseReceived(HttpSession_T *httpSession, Msg_T *msg_ptr, retcode_t status)
{
    (void) (httpSession);
    if (status == RC_OK && msg_ptr != NULL) {

        Http_StatusCode_T statusCode = HttpMsg_getStatusCode(msg_ptr);
        char const *contentType = HttpMsg_getContentType(msg_ptr);
        char const *content_ptr;
        unsigned int contentLength = 0;

        HttpMsg_getContent(msg_ptr, &content_ptr, &contentLength);
        char content[contentLength+1];
        strncpy(content, content_ptr, contentLength);
        content[contentLength] = 0;
        printf("HTTP RESPONSE: %d [%s]\r\n", statusCode, contentType);
        printf("%s\r\n", content);
    }

    else {
        printf("Failed to receive HTTP response!\r\n");
    }

    return(RC_OK);
}

static retcode_t onHTTPRequestSent(Callable_T *callfunc, retcode_t status)
{
(void) (callfunc);
    if (status != RC_OK) {
        printf("Failed to send HTTP request!\r\n");
    }
    printf("HTTP request sent succesfully!\r\n");
    return(RC_OK);
}

retcode_t serializeMyHeaders(OutMsgSerializationHandover_T* handover)
{
    handover->len = 0;
    static const char* header1 = "Authorization: Basic enowMDAzODgzMzQ3MjI5LWJkNDhhNWRhLTcxOTgtNGRmYi1iYmQ4LTM1YmZjMTI2ODg1MDpMay03bU9BU1lhRU1ZakVz\r\n";
    TcpMsg_copyStaticContent(handover, header1, strlen(header1));
    handover->position = 1;
    return RC_OK;
}

void createAndSendPostMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    Ip_convertOctetsToAddr(139, 15, 6, 103, &destAddr);
    Ip_Port_T port = Ip_convertIntToPort(80);


    Msg_T* msg_ptr;
    HttpClient_initRequest(&destAddr, port, &msg_ptr);

    HttpMsg_setReqMethod(msg_ptr, Http_Method_Post);
    HttpMsg_setReqUrl(msg_ptr, "https://bosch-iot-insights.com/data-recorder-service/v2/zz0003883347229");
    HttpMsg_serializeCustomHeaders(msg_ptr, serializeMyHeaders);
    Msg_prependPartFactory(msg_ptr, &writeNextPartToBuffer);

    // send the request
    static Callable_T sentCallable;
    Callable_assign(&sentCallable, &onHTTPRequestSent);
    HttpClient_pushRequest(msg_ptr, &sentCallable, &onHTTPResponseReceived);
    printf("HTTP request sent!\r\n");
}

/* --------------------------------------------------------------------------- |
 * BOOTING- AND SETUP FUNCTIONS ********************************************** |
 * -------------------------------------------------------------------------- */

static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    /* Enable necessary modules for the application and check their return values */
    createAndSendPostMessage();

}

static void AppControllerSetup(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    /* Setup the necessary modules required for the application */
    networkSetup();
    HttpClient_initialize();

    retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerEnable, NULL, UINT32_C(0));
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerSetup : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

void AppController_Init(void * cmdProcessorHandle, uint32_t param2)
{
    BCDS_UNUSED(param2);

    Retcode_T retcode = RETCODE_OK;

    if (cmdProcessorHandle == NULL)
    {
        printf("AppController_Init : Command processor handle is NULL \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER);
    }
    else
    {
        AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle;
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerSetup, NULL, UINT32_C(0));
    }

    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }
}

/** ************************************************************************* */

This is my code for sending data. Can you please find out what am I doing wrong?

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/7/18 9:56 AM as a reply to Sajid Baloch.
Dear Sajid,

I will take a look at this in more detail. Therefore I would kindly ask you for patience.
I will give you an update on this until the end of the week.

If you have any questions, feel free to ask.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/8/18 12:38 PM as a reply to Franjo Stjepandic.

Thank you. I will look forward to it.

I also want to ask about the curl library. I just used the example from knowledgebase. 

Do I have to use the curl code to do the authorization?

The code below is the curl code. If I should use it then how can I integrate it with the HTTP implementation code ? In AppController.c?

//Include Libcurl as C third party library https://curl.haxx.se/libcurl/
#include "stdafx.h"
#include <curl\curl.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;
CURL *curl;
CURLcode res;
long responsecode;

string url = "https://www.bosch-sfde.com/data-recorder-service/v2/";
string project = "demo";
const char *headerAccept = "Accept: application/json";
const char *headerContentType = "Content-Type: application/json";
//Encode  username:password in Base64 and input the string after Basic
const char *headerAuthorization = "Authorization: Basic Zm9vOmJhcg==";

//Define a proxy connection if required. Otherwise set the option null;
const char *proxyUrl;
//input your proxy Authentification in following syntax:  username:password
const char *proxyAuth;
//set postFields to send a Post request otherwise libcurl send a get request
string postFields="";

void addHttpHeaders(CURL *curl) {
        struct curl_slist *headerlist = NULL;
        headerlist = curl_slist_append(headerlist, headerAccept);
        headerlist = curl_slist_append(headerlist, headerAuthorization);
        headerlist = curl_slist_append(headerlist, headerContentType);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
}

void proxySettings(CURL *curl) {

        curl_easy_setopt(curl, CURLOPT_PROXY, proxyUrl);
        curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxyAuth);
}

CURLcode request(CURL *curl, string postFields) {

string concartUrl = url + project;
        const char *completeUrl = concartUrl.c_str();
        curl_easy_setopt(curl, CURLOPT_URL, completeUrl);
        //This option disable the certifcate Check. It isn't recommended to use this option!
        //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

        //set postFields for post method otherwise libcurl is using http get by default
        if (!postFields.empty()) {
                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields);
        }
        return curl_easy_perform(curl);
}

 boolean checkProjectState() {
         curl = curl_easy_init();
         if (curl) {
                 addHttpHeaders(curl);

                 if ((proxyUrl != NULL) && (proxyUrl[0] == '\0')) {
                         proxySettings(curl);
                 }
                res= request(curl, postFields);

                 /* Check for errors */
                if (res != CURLE_OK) {
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                        curl_easy_strerror(res));
                        curl_easy_cleanup(curl);
                        return false;
                }
                else {
                        curl_easy_cleanup(curl);
                        return true;
                 }
         }
         return false;
}
 void sendData() {

         curl = curl_easy_init();

         if (curl) {

                 addHttpHeaders(curl);
                 if ((proxyUrl != NULL) && (proxyUrl[0] == '\0')) {
                         proxySettings(curl);
                 }
                 res = request(curl, postFields);

                 /* Check for errors */
                 if (res != CURLE_OK) {
                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
                                 curl_easy_strerror(res));
                 }else{
                         curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &responsecode);
                         if (responsecode == 201) {
                                 cout << "successful upload" << endl;
                         }
                         else if (responsecode == 304) {
                                 cout << "Uploaded data is marked as duplicate and wasn't proccessed" << endl;
                         }
                         else {
                                 cout << "something works wrong. Server answer with status code: " << responsecode << endl;
                         }
                 }


                 curl_easy_cleanup(curl);
         }
 }
          int main() {
                 curl_global_init(CURL_GLOBAL_ALL);
                 if (checkProjectState()) {

                 postFields = "{\"Hello\": \"World\"}";
                         sendData();

                         cout << "press any key to exit" << endl;
                         string wait;
                         getline(cin, wait);
                          curl_global_cleanup();
                        return 0;

                 }
                 else {
                          cout << "press any key to exit" << endl;
                         string wait;
                         getline(cin, wait);
                         curl_global_cleanup();
                         return 1;
                 }

         }

One more problem is that whenever I access Data Service Recorder, the Bosch IoT Insights dashboard doesn't work then. The screenshot of the errors are attached. 

Additionally, there are 2 urls for accessing Data Recorder Service.

1. www.bosch-iot-insights.com/data-recorder-service

2. www.bosch-sfde.com/data-recorder-service

Which one is the right one?

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/9/18 3:48 PM as a reply to Sajid Baloch.
Hello Sajid,

The curl code you posted should not be necessary for the authorization. As a general guideline, whenever you want to add or modify code, please use the AppController.c file.

Regarding the right Data Recorder Service, please use the first link:

www.bosch-iot-insights.com/data-recorder-service .

You can use the link here to test a POST request and check the input data in the Bosch IoT Insights Overview. For that, please make sure you are logged in at Bosch IoT Insights.

The Project Id is your id from the data_recorder_url . The payload could be something like this:

{"data": [{ "Name": "Test1", "X": 7, "Y": 6, "Z": 13, "City": "Berlin" }]}

As an improvement for your input data, I recommend adding a template for Bosch insights as following:

[{ "$unwind": "$payload.data" }, { "$project": { "Name": "$payload.data.Name", "Age": "$payload.data.Age", "City": "$payload.data.City" } } ]

This will automatically parse the incoming data for the fields you want to display specifically.

The issue with the Http failure has been solved for me, as soon as I reloaded the page. I assume that this is a kind of timeout issue.

In regards to your prior issue, I made some findings. Using the username\:password scheme in base64 should work as intended and you can stick to it. Regarding the path you inserted via the function HttpMsg_setReqUrl(msg_ptr, "https://bosch-iot-insights.com/data-recorder-service/v2/zz0003883347229"); . This includes in your case currently the host address , which can be excluded since it is already resolved into an IP address (139.15.6.103). As such, it should look as below:

HttpMsg_setReqUrl(msg_ptr, "/data-recorder-service/v2/zz0003883347229");

Furthermore, please note that the insights dashboard input data can only be posted over HTTPS, but not via HTTP. On that behalf, please note that if you are trying via HTTP instead of HTTPS you will not get an response on the XDK side, since the payload is to big to be handled by the XDK.

To make it works with the XDK you would have to switch to HTTPS instead of HTTP. Please note that you would need to set an accurate timestamp, for example, over the interface XDK_SNTP.h and you would need to store the certificate of Bosch IoT Insights before you open up the HTTPS connection.

For the HTTPS implementation, I recommend taking a look at the corresponding article in the XDK knowledgebase . Please note that you need beforehand an free registration before you can access the content of the XDK knowledgebase.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/14/18 3:22 PM as a reply to Franjo Stjepandic.

Hi Franjo,

Thanks a lot for your help but it is really confusing.  I can't get the implementation of HTTPS. There are so many points whichare not clearly explained in the tutorials as well. 

If I want to send a payload to Insights using HTTPS what shold I do? 

The knowledgebase tutorial is for GET request and not for POST. 

While implementing the HTTPS tutorial I used the complete code and pasted it in XDKApplciationTemplate AppController.c file.

There is an error, the screenshot is attached. 

 

I think there should be a simple and easy guide to implement the connection of Bosch XDK with Bosch IoT Insights like the live data connection on Bosch IoT Things. Thanks.

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/15/18 11:11 PM as a reply to Sajid Baloch.
Hello Sajid,

thank you for following my advice and also to post the screenshot, which helped a lot at reconstructing your current compiling issue.
Before you start with the missing HTTPS POST request implementation, it might help to solve the compiling issue from your screenshot.
This issue occurred due to multiple references of two almost similar device.h files which both include the struct SlDateTime_t .

By default, the wrong SlDateTime_t struct, which instead of sl_tm_day , sl_tm_mon , etcetera, lists tm_day , tm_mon and so on, is chosen.

The cleanest solution I found, is to exclude this specific device.h file, which is located following path:
/SDK/xdk110/Libraries/FreeRTOS/3rd-party/third_party/mcu_vendor/ti/SimpleLink_CC32xx/v1_40_01_00/source/ti/drivers/net/wifi/device.h

To cleanly exclude this file, a few steps are required:
  1. Open the path within the XDK-Workbench's Project Explorer and rightclick on the file device.h.
  2. Click on Preferences.
  3. Within the new popup window, uncheck Archive and click on the menu tab C/C++.
  4. Check Exclude Resource from Build and exit the Preferences window by clicking on Apply and Close.
    Note: These preferences only occur to the selected project and do not touch the global SDK settings.
  5. Rightclick on your project folder within the Project Explorer and choose Clean Project
  6. After cleaning your project, rightclick again on your project folder, followed by Index and a final click on Freshen all Files.
    All six undefined reference errors should disappear, as now only one of the previous two structs SlDateTime_t is included into this project.
Regarding the HTTPS POST request implementation, I agree with you.
The HTTPS article within the XDK-Knowledgebase has been released recently, so it is only a matter of time, until the requested HTTPS POST request will be added, too.

In the meantime, you are free to hit the challenge, implementing it by yourself. You could start by editing the published HTTPS GET request's source code.
As reference, you could use the HTTP GET request full code example and the HTTP POST request full code example out of the XDK-Knowledgebase and use the additional code from the HTTP POST request full code example to edit the HTTPS GET request full code example to a HTTPS POST request example.

Your idea to write an article for posting data to Bosch IoT Insights is actually something which could be done in future.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/19/18 5:29 PM as a reply to Franjo Stjepandic.
Thank you, Franjo and Sajid. An article should be written to post the XDK data to Bosch IoT Insights to be able to store the sensor data easily in the cloud and analyse it - instead of only be able to see live data via BoschXDKCloudConnectivity.
0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/20/18 4:31 PM as a reply to Stefan Maier.

Where do I have to navigate to open the path with the XDK-Workbench's Project Explorer? It seems I can't find it.

 

"The cleanest solution I found, is to exclude this specific device.h file, which is located following path:
/SDK/xdk110/Libraries/FreeRTOS/3rd-party/third_party/mcu_vendor/ti/SimpleLink_CC32xx/v1_40_01_00/source/ti/drivers/net/wifi/device.h

To cleanly exclude this file, a few steps are required:
Open the path within the XDK-Workbench's Project Explorer and rightclick on the file device.h."

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/20/18 5:01 PM as a reply to Stefan Maier.

I only found this

 

0 (0 Votes)
RE: Bosch XDK to Bosch IoT Cloud
Answer
11/20/18 8:14 PM as a reply to Stefan Maier.
Okay, problem solved. I found it.
0 (0 Votes)