Developer Portal Community

    We are still working on migrating to the new Bosch Connected Industry Online Portal. Stay tuned! Click here for the latest updates.

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    XDK 110 - Connecting the WiFi and Sending a GET Request

    XDK 110 - Connecting the WiFi and Sending a GET Request

    GabrielHFer
    New Poster

    Hello, Everyone!

    I'm studying the Bosch XDK 110, and I'm having difficults in connecting to an Access Point.

    I've read some manuals (Wi-Fi and HTTP guides) and another forum (HTTP - LEGIC XDK) explaining the necessary codes to run the application, but I didn't get any success in aplying these instructions.

    Could you guys help me, please?

    Best Regards.

    Code:


    /* module includes ********************************************************** */

    /* 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

    /* own header files */
    #include "AppController.h"

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

    /* additional interface header files */
    #include "BCDS_Assert.h"
    #include "BCDS_CmdProcessor.h"
    #include "XDK_Utils.h"
    #include "FreeRTOS.h"
    #include "task.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 "PIp.h"
    #include "PAL_Initialize_ih.h"
    #include "PAL_socketMonitor_ih.h"

    /* --------------------------------------------------------------------------- |
    * HANDLES ******************************************************************* |
    * -------------------------------------------------------------------------- */

    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 ******************************************************* |
    * -------------------------------------------------------------------------- */


    //Configuring the PAL Modules
    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;
    }

    //Connecting to WiFi
    void networkSetup(void) {

    WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "iPhone";
    WlanConnect_PassPhrase_T connectPassPhrase =
    (WlanConnect_PassPhrase_T) "hobbit213";
    WlanConnect_Init();
    NetworkConfig_SetIpDhcp(0);
    WlanConnect_WPA(connectSSID, connectPassPhrase, 0);
    Retcode_T retStatusConnect;
    retStatusConnect = (Retcode_T) WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);

    if (retStatusConnect == RETCODE_OK){
    printf("Connected successfully.\n\r");
    }
    else {
    printf("Not Connected.\n\r");
    }
    ServalPalSetup();
    }

    //Reading the HTTP Response
    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);
    }

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

    //Creating and sending the message
    void createAndSendGetMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    //PAL_getIpaddress ((uint8_t*)"/ip", &destAddr);
    Ip_convertOctetsToAddr(23, 22, 14, 18, &destAddr);
    Ip_Port_T port = Ip_convertIntToPort(80);
    Msg_T* msg_ptr;
    HttpClient_initRequest(&destAddr, port, &msg_ptr);
    HttpMsg_setReqMethod(msg_ptr, Http_Method_Get);
    HttpMsg_setReqUrl(msg_ptr, "/ip");
    // HttpMsg_setHost(msg_ptr, "httpbin.org");

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

    /* --------------------------------------------------------------------------- |
    * 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 */
    createAndSendGetMessage();
    }

    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 */
    }
    /*PAL_initialize();
    PAL_socketMonitorInit();*/


    }

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

    1 REPLY 1

    pdo
    Community Manager
    Community Manager

    Hello, and thank you for contacting us,

    This product is no longer owned by Bosch. Please contact Legic:

    www.legic.com

    https://www.xdk.io/

    iot@legic.com

    Thank you

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist