HTTP 302 Found
Answer
3/12/19 9:35 PM
I have a problem regarding to the coding in https://developer.bosch.com/web/xdk/http. The GET and POST coding keep showing 302 Found. May I have know what is the possiblities of causing such problem?Thank you very much 

Best Wishes
Kent
0 (0 Votes)
RE: HTTP 302 Found
Answer
3/13/19 10:01 AM as a reply to l Kent.

Hi l Kent ,

Do you mean that HTTP page https://developer.bosch.com/web/xdk/http is not found ?

 -> If page is not found, kindly refresh and check now.

Or Do you mean that HTTP post/get response is error code 302 ?

-> What HTTP server is being used ? Can you check whether the server is active ?

 

 

 

0 (0 Votes)
RE: HTTP 302 Found
Answer
3/13/19 6:19 PM as a reply to Padmapriya Govindasamy.

I am using this code to perform the GET function. This code consist of website or IP adress to be received? Padmapriya Govindasamy can you please show me the statement or code when it is success?Thank you very much

 

/*----------------------------------------------------------------------------* /* --------------------------------------------------------------------------- | * INCLUDES & DEFINES ******************************************************** | * -------------------------------------------------------------------------- */

/* 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 "PIp.h"
#include "Serval_HttpClient.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 ******************************************************* | * -------------------------------------------------------------------------- */

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) "yourWifiNetworkSSID";
    WlanConnect_PassPhrase_T connectPassPhrase =
            (WlanConnect_PassPhrase_T) "yourWifiNetworkPW";
    WlanConnect_Init();
    NetworkConfig_SetIpDhcp(0);
    WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);

    ServalPalSetup();
}

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");
    }
    return(RC_OK);
}

void createAndSendGetMessage(void){
    // assemble the request message
    Ip_Address_T 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");

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

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

0 (0 Votes)
RE: HTTP 302 Found
Answer
3/15/19 8:58 AM as a reply to l Kent.

Hi I Kent,

The ip address 23.22.14.18 mentioned in the xdk developer page belong to amazonaws server and is not reachable. I will take care of updating the developer page. Kindly use the ip address 3.85.154.144 in createAndSendGetMessage  function as below,

 

void createAndSendGetMessage(void){
    // assemble the request message
    Ip_Address_T destAddr;
    Ip_convertOctetsToAddr(3, 85, 154, 144, &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");

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

If you are implementing HTTP post and get functionality itself, there is a template application HttpExampleClient in XDK workbench; which makes your work easier.

User manual for the HttpExampleClient template application can be found in https://developer.bosch.com/web/xdk/application-templates, where you can provide the domain name of the destination host(httpbin.org or postman-echo.com) in place of ip address. Get it a try and let me know, the feedback.

Thanks and Regards,

Padmpriya G.

 

0 (0 Votes)
RE: HTTP 302 Found
Answer
3/16/19 5:47 PM as a reply to Padmapriya Govindasamy.

My wifi consist of three component which is SSID, Username and Password. Can I write the code in this way? If no can you show me how should I write the code Padmapriya Govindasamy? Thank you

 

void networkSetup(void) {

 

WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) "......";

WlanConnect_Username_T connectUsername =

(WlanConnect_Username_T) ".............";

WlanConnect_PassPhrase_T connectPassPhrase =

(WlanConnect_PassPhrase_T) "...............";

WlanConnect_Init();

NetworkConfig_SetIpDhcp(0);

WlanConnect_WPA(connectSSID, connectUsername, connectPassPhrase, NULL);

0 (0 Votes)
RE: HTTP 302 Found
Answer
3/16/19 8:29 PM as a reply to l Kent.
I have found out the problem is the IP address and also the wifi. The wifi should be set to 5GHz. May I know that if I wish to post to URL instead of IP address, how should I create the code. Thank you 
0 (0 Votes)