Using POST Method
答复
19-5-20 下午1:53

Hi,

I'm currently trying to send data to an online database with the POST method. In order to do that, I did a PHP page that sends different values to my database. This page is hosted on a server so I have the URL.

Just to show you how I want to use the POST method, here is my PHP page :

<?php

require "mariadbtestconn.php";

$AccelerometerX = $_POST["AccelerometerX"];
$AccelerometerY = $_POST["AccelerometerY"];
$AccelerometerZ = $_POST["AccelerometerZ"];
$Acoustic = $_POST["Acoustic"];
$Digital_light = $_POST["Digital_light"];
$GyroscopeX = $_POST["GyroscopeX"];
$GyroscopeY = $_POST["GyroscopeY"];
$GyroscopeZ = $_POST["GyroscopeZ"];
$Humidity = $_POST["Humidity"];
$MagnetometerX = $_POST["MagnetometerX"];
$MagnetometerY = $_POST["MagnetometerY"];
$MagnetometerZ = $_POST["MagnetometerZ"];
$Pressure = $_POST["Pressure"];
$Temperature = $_POST["Temperature"];

$sql = "INSERT INTO XDK110_Sensors_Data (
AccelerometerX, AccelerometerY, AccelerometerZ, 
Acoustic,
Digital_light,
GyroscopeX, GyroscopeY, GyroscopeZ, 
Humidity, 
MagnetometerX, MagnetometerY, MagnetometerZ,
Pressure,
Temperature
) VALUES (
    '$AccelerometerX', '$AccelerometerY', '$AccelerometerZ',
    '$Acoustic',
    '$Digital_light',
    '$GyroscopeX', '$GyroscopeY', '$GyroscopeZ',
    '$Humidity',
    '$MagnetometerX', '$MagnetometerY', '$MagnetometerZ',
    '$Pressure',
    '$Temperature'
)";

if(mysqli_query($conn, $sql)){
    echo "Records inserted successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}


mysqli_close($conn);

My problem is that I don't succeed to use the POST method with my XDK. I don't know what I have to put inside HTTPRestClientPostInfo and I'm not sure that my other settings are correct.


Here is my code with which I'm trying to send data :

/* 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 "XDK_WLAN.h"
#include "XDK_ServalPAL.h"
#include "XDK_HTTPRestClient.h"
#include "XDK_SNTP.h"
#include "BCDS_BSP_Board.h"

#include "BCDS_WlanNetworkConfig.h"
#include "BCDS_WlanNetworkConnect.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "XDK_Utils.h"
#include "FreeRTOS.h"
#include "task.h"

/* constant definitions ***************************************************** */

#if HTTP_SECURE_ENABLE
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT           UINT32_C(10000)/**< Timeout for SNTP server time sync */
#endif /* HTTP_SECURE_ENABLE */

#define APP_RESPONSE_FROM_HTTP_SERVER_POST_TIMEOUT      UINT32_C(25000)/**< Timeout for completion of HTTP rest client POST */

#define APP_RESPONSE_FROM_HTTP_SERVER_GET_TIMEOUT       UINT32_C(25000)/**< Timeout for completion of HTTP rest client GET */

/* local variables ********************************************************** */

static WLAN_Setup_T WLANSetupInfo =
        {
                .IsEnterprise = false,
                .IsHostPgmEnabled = false,
                .SSID = "my_wlan_ssid",
                .Password = "my_wlan_pwd",
        };/**< WLAN setup parameters */

static HTTPRestClient_Setup_T HTTPRestClientSetupInfo =
        {
                .IsSecure = UINT32_C(0),
        };/**< HTTP rest client setup parameters */

/*
 * @todo - Use only DEST_SERVER_PORT in the header for secure and non-secure.
 * And remove the below 6 lines of the macros
 */
static HTTPRestClient_Config_T HTTPRestClientConfigInfo =
        {
                .IsSecure = UINT32_C(0),
                .DestinationServerUrl = "my_php_page_url",
                .DestinationServerPort = 22,
                .RequestMaxDownloadSize = UINT32_C(512),
        }; /**< HTTP rest client configuration parameters */

static HTTPRestClient_Post_T HTTPRestClientPostInfo =
        {
                .Payload = ???,
                .PayloadLength = (sizeof(POST_REQUEST_BODY) - 1U),
                .Url = ???
        }; /**< HTTP rest client POST parameters */

/**
 * @brief   The HTTP GET request response callback.
 *
 * @param [in] responseContent
 * Pointer to the GET request response
 *
 * @param [in] responseContentLen
 * Length of the GET request response
 *
 * @param [in] isLastMessage
 * Boolean to represent if it is the last part of the ongoing message
 */
static void HTTPRestClientGetCB(const char* responseContent, uint32_t responseContentLen, bool isLastMessage);

static HTTPRestClient_Get_T HTTPRestClientGetInfo =
        {
                .Url = DEST_GET_PATH,
                .GetCB = HTTPRestClientGetCB,
                .GetOffset = 0UL,
        }; /**< HTTP rest client GET parameters */

static xTaskHandle AppControllerHandle = NULL; /**< OS thread handle for Application controller */

static CmdProcessor_T * AppCmdProcessor; /**< Handle to store the main Command processor handle to be reused by ServalPAL thread */

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/** Refer function definition for description */
static void HTTPRestClientGetCB(const char* responseContent, uint32_t responseContentLen, bool isLastMessage)
{
    BCDS_UNUSED(isLastMessage);

    if ((NULL != responseContent) && (0UL != responseContentLen))
    {
        printf("HTTPRestClientGetCB: HTTP GET response: %.*s\r\n", (int) responseContentLen, responseContent);
    }
}

/**
 * @brief This will validate the WLAN network connectivity
 *
 * If there is no connectivity then it will scan for the given network and try to reconnect
 *
 * @return  RETCODE_OK on success, or an error code otherwise.
 */
static Retcode_T AppControllerValidateWLANConnectivity(void)
{
    Retcode_T retcode = RETCODE_OK;
    WlanNetworkConnect_IpStatus_T nwStatus;
    nwStatus = WlanNetworkConnect_GetIpStatus();

    if (WLANNWCT_IPSTATUS_CT_AQRD != nwStatus)
    {
#if HTTP_SECURE_ENABLE
        static bool isSntpDisabled = false;
        if (false == isSntpDisabled)
        {
            retcode = SNTP_Disable();
        }
        if (RETCODE_OK == retcode)
        {
            isSntpDisabled = true;
            retcode = WLAN_Reconnect();
        }
        if (RETCODE_OK == retcode)
        {
            retcode = SNTP_Enable();
        }
#else
        retcode = WLAN_Reconnect();
#endif /* HTTP_SECURE_ENABLE */

    }
    return retcode;

}

/**
 * @brief Responsible for controlling the HTTP Example application control flow.
 *
 * - Synchronize the node with the SNTP server for time-stamp (if HTTPS)
 * - Check whether the WLAN network connection is available
 * - Do a HTTP rest client POST
 * - Wait for INTER_REQUEST_INTERVAL if POST was successful
 * - Do a HTTP rest client GET if POST was successful
 * - Wait for INTER_REQUEST_INTERVAL if GET was successful
 * - Redo the last 5 steps
 *
 * @param[in] pvParameters
 * Unused
 */
static void AppControllerFire(void* pvParameters)
{
    BCDS_UNUSED(pvParameters);

    Retcode_T retcode = RETCODE_OK;

#if HTTP_SECURE_ENABLE

    uint64_t sntpTimeStampFromServer = 0UL;

    /* We Synchronize the node with the SNTP server for time-stamp.
     * Since there is no point in doing a HTTPS communication without a valid time */
    do
    {
        retcode = SNTP_GetTimeFromServer(&sntpTimeStampFromServer, APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT);
        if ((RETCODE_OK != retcode) || (0UL == sntpTimeStampFromServer))
        {
            printf("AppControllerFire : SNTP server time was not synchronized. Retrying...\r\n");
        }
    } while (0UL == sntpTimeStampFromServer);

    BCDS_UNUSED(sntpTimeStampFromServer); /* Copy of sntpTimeStampFromServer will be used be HTTPS for TLS handshake */
#endif /* HTTP_SECURE_ENABLE */

    while (1)
    {
        /* Resetting / clearing the necessary buffers / variables for re-use */
        retcode = RETCODE_OK;

        /* Check whether the WLAN network connection is available */
        retcode = AppControllerValidateWLANConnectivity();

        /* Do a HTTP rest client POST */
        if (RETCODE_OK == retcode)
        {
            retcode = HTTPRestClient_Post(&HTTPRestClientConfigInfo, &HTTPRestClientPostInfo, APP_RESPONSE_FROM_HTTP_SERVER_POST_TIMEOUT);
        }
        if (RETCODE_OK == retcode)
        {
            /* Wait for INTER_REQUEST_INTERVAL */
            vTaskDelay(pdMS_TO_TICKS(INTER_REQUEST_INTERVAL));
            /* Do a HTTP rest client GET */
            retcode = HTTPRestClient_Get(&HTTPRestClientConfigInfo, &HTTPRestClientGetInfo, APP_RESPONSE_FROM_HTTP_SERVER_GET_TIMEOUT);
        }
        if (RETCODE_OK == retcode)
        {
            /* Wait for INTER_REQUEST_INTERVAL */
            vTaskDelay(pdMS_TO_TICKS(INTER_REQUEST_INTERVAL));
        }
        if (RETCODE_OK != retcode)
        {
            printf("Error in Post/get request: Will trigger another post/get after INTER_REQUEST_INTERVAL\r\n");
            vTaskDelay(pdMS_TO_TICKS(INTER_REQUEST_INTERVAL));
            /* Report error and continue */
            Retcode_RaiseError(retcode);
        }
    }
}

/**
 * @brief To enable the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if HTTPS)
 * - HTTP rest client
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Enable();
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Enable();
    }
#if HTTP_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Enable();
    }
#endif /* HTTP_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = HTTPRestClient_Enable();
    }
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }

    Utils_PrintResetCause();
}

/**
 * @brief To setup the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if HTTPS)
 * - HTTP rest client
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerSetup(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Setup(&WLANSetupInfo);
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Setup(AppCmdProcessor);
    }
#if HTTP_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Setup(&SNTPSetupInfo);
    }
#endif /* HTTP_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = HTTPRestClient_Setup(&HTTPRestClientSetupInfo);
    }
    if (RETCODE_OK == retcode)
    {
        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 */
    }
}

/* global functions ********************************************************** */

/** Refer interface header for description */
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 */
    }
}

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

If you could help me by telling me what I need to fill to just send a value in the acoustic column, for example, it would be perfect.


I thank you in advance.

Elie

0 (0 票)
RE: Using POST Method
答复
19-5-24 上午7:47 回复Elie BOURY。

Hi Elie

Could you go through the Application HttpExampleClient .

As per your implementation you have to pass the payload and the Php url.

Thanks

Priyashi

0 (0 票)
RE: Using POST Method
答复
19-5-28 上午8:48 回复Priyashi Yadav。

Thanks for your help.

In fact, I was already using HttpExampleClient. 

I am using the same template and, as a payload and in order to test it, I wrote "{ \"GyroscopeX\": \"10\", \"GyroscopeY\": \"20\", \"GyroscopeZ\": \"30\" }". Concerning the url of the HTTPRestClientPostInfo I put the default one "/post".

When I flash it, I have this error : 

WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: HTTPRestClient_Post : unable to resolve hostname error=167976961.
 INFO | XDK DEVICE 1: Error in Post/get request: Will trigger another post/get after INTER_REQUEST_INTERVAL
 INFO | XDK DEVICE 1: Error in WLAN package.
 INFO | XDK DEVICE 1: 	Package ID: 10
 INFO | XDK DEVICE 1: 	Module ID: 3
 INFO | XDK DEVICE 1: 	Severity code: 2
 INFO | XDK DEVICE 1: 	Error code: 1

 

0 (0 票)
RE: Using POST Method
答复
19-5-28 下午2:25 回复Elie BOURY。

I changed different settings and now here is where I am (I am using https):

/* 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 "XDK_WLAN.h"
#include "XDK_ServalPAL.h"
#include "XDK_HTTPRestClient.h"
#include "XDK_SNTP.h"
#include "BCDS_BSP_Board.h"

#include "BCDS_WlanNetworkConfig.h"
#include "BCDS_WlanNetworkConnect.h"
#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"
#include "XDK_Utils.h"
#include "FreeRTOS.h"
#include "task.h"

/* constant definitions ***************************************************** */

#if HTTP_SECURE_ENABLE
#define APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT           UINT32_C(10000)/**< Timeout for SNTP server time sync */
#endif /* HTTP_SECURE_ENABLE */

#define APP_RESPONSE_FROM_HTTP_SERVER_POST_TIMEOUT      UINT32_C(25000)/**< Timeout for completion of HTTP rest client POST */

#define APP_RESPONSE_FROM_HTTP_SERVER_GET_TIMEOUT       UINT32_C(25000)/**< Timeout for completion of HTTP rest client GET */

/* local variables ********************************************************** */

static WLAN_Setup_T WLANSetupInfo =
        {
                .IsEnterprise = false,
                .IsHostPgmEnabled = false,
                .SSID = "my_ssid",
                .Password = "my_pwd",
        };/**< WLAN setup parameters */

#if HTTP_SECURE_ENABLE 
static SNTP_Setup_T SNTPSetupInfo =
        {
                .ServerUrl = "my_server_url",
                .ServerPort = "my_server_port",
        };/**< SNTP setup parameters */
#endif /* HTTP_SECURE_ENABLE */

static HTTPRestClient_Setup_T HTTPRestClientSetupInfo =
        {
                .IsSecure = 1,
        };/**< HTTP rest client setup parameters */

/*
 * @todo - Use only DEST_SERVER_PORT in the header for secure and non-secure.
 * And remove the below 6 lines of the macros
 */
#if HTTP_SECURE_ENABLE
#ifdef DEST_SERVER_PORT
#undef DEST_SERVER_PORT
#endif /* #ifdef DEST_SERVER_PORT */
#define DEST_SERVER_PORT        22
#endif /* if HTTP_SECURE_ENABLE */

static HTTPRestClient_Config_T HTTPRestClientConfigInfo =
        {
                .IsSecure = 1,
                .DestinationServerUrl = "my_server_url",
                .DestinationServerPort = 22,
                .RequestMaxDownloadSize = REQUEST_MAX_DOWNLOAD_SIZE,
        }; /**< HTTP rest client configuration parameters */

static HTTPRestClient_Post_T HTTPRestClientPostInfo =
        {
                .Payload = "{ \"Acoustic\": \"3\"}",
                .PayloadLength = (sizeof("{ \"Acoustic\": \"3\"}") - 1U),
                .Url = "my_path_relative_to_my_server"
        }; /**< HTTP rest client POST parameters */


static xTaskHandle AppControllerHandle = NULL; /**< OS thread handle for Application controller */

static CmdProcessor_T * AppCmdProcessor; /**< Handle to store the main Command processor handle to be reused by ServalPAL thread */

/* global variables ********************************************************* */

/* inline functions ********************************************************* */

/* local functions ********************************************************** */

/**
 * @brief This will validate the WLAN network connectivity
 *
 * If there is no connectivity then it will scan for the given network and try to reconnect
 *
 * @return  RETCODE_OK on success, or an error code otherwise.
 */
static Retcode_T AppControllerValidateWLANConnectivity(void)
{
    Retcode_T retcode = RETCODE_OK;
    WlanNetworkConnect_IpStatus_T nwStatus;
    nwStatus = WlanNetworkConnect_GetIpStatus();

    if (WLANNWCT_IPSTATUS_CT_AQRD != nwStatus)
    {
#if HTTP_SECURE_ENABLE
        static bool isSntpDisabled = false;
        if (false == isSntpDisabled)
        {
            retcode = SNTP_Disable();
        }
        if (RETCODE_OK == retcode)
        {
            isSntpDisabled = true;
            retcode = WLAN_Reconnect();
        }
        if (RETCODE_OK == retcode)
        {
            retcode = SNTP_Enable();
        }
#else
        retcode = WLAN_Reconnect();
#endif /* HTTP_SECURE_ENABLE */

    }
    return retcode;

}

/**
 * @brief Responsible for controlling the HTTP Example application control flow.
 *
 * - Synchronize the node with the SNTP server for time-stamp (if HTTPS)
 * - Check whether the WLAN network connection is available
 * - Do a HTTP rest client POST
 * - Wait for INTER_REQUEST_INTERVAL if POST was successful
 * - Redo the last 4 steps
 *
 * @param[in] pvParameters
 * Unused
 */
static void AppControllerFire(void* pvParameters)
{
    BCDS_UNUSED(pvParameters);

    Retcode_T retcode = RETCODE_OK;

#if HTTP_SECURE_ENABLE

    uint64_t sntpTimeStampFromServer = 0UL;

    /* We Synchronize the node with the SNTP server for time-stamp.
     * Since there is no point in doing a HTTPS communication without a valid time */
    do
    {
        retcode = SNTP_GetTimeFromServer(&sntpTimeStampFromServer, APP_RESPONSE_FROM_SNTP_SERVER_TIMEOUT);
        if ((RETCODE_OK != retcode) || (0UL == sntpTimeStampFromServer))
        {
            printf("AppControllerFire : SNTP server time was not synchronized. Retrying...\r\n");
        }
    } while (0UL == sntpTimeStampFromServer);

    BCDS_UNUSED(sntpTimeStampFromServer); /* Copy of sntpTimeStampFromServer will be used be HTTPS for TLS handshake */
#endif /* HTTP_SECURE_ENABLE */

    while (1)
    {
        /* Resetting / clearing the necessary buffers / variables for re-use */
        retcode = RETCODE_OK;

        /* Check whether the WLAN network connection is available */
        retcode = AppControllerValidateWLANConnectivity();

        /* Do a HTTP rest client POST */
        if (RETCODE_OK == retcode)
        {
            retcode = HTTPRestClient_Post(&HTTPRestClientConfigInfo, &HTTPRestClientPostInfo, APP_RESPONSE_FROM_HTTP_SERVER_POST_TIMEOUT);
        }
        if (RETCODE_OK == retcode)
        {
            /* Wait for INTER_REQUEST_INTERVAL */
            vTaskDelay(pdMS_TO_TICKS(INTER_REQUEST_INTERVAL));
        }
        if (RETCODE_OK != retcode)
        {
            printf("Error in Post/get request: Will trigger another post/get after INTER_REQUEST_INTERVAL\r\n");
            vTaskDelay(pdMS_TO_TICKS(INTER_REQUEST_INTERVAL));
            /* Report error and continue */
            Retcode_RaiseError(retcode);
        }
    }
}

/**
 * @brief To enable the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if HTTPS)
 * - HTTP rest client
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerEnable(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Enable();
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Enable();
    }
#if HTTP_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Enable();
    }
#endif /* HTTP_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = HTTPRestClient_Enable();
    }
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0); /* To provide LED indication for the user */
    }

    Utils_PrintResetCause();
}

/**
 * @brief To setup the necessary modules for the application
 * - WLAN
 * - ServalPAL
 * - SNTP (if HTTPS)
 * - HTTP rest client
 *
 * @param[in] param1
 * Unused
 *
 * @param[in] param2
 * Unused
 */
static void AppControllerSetup(void * param1, uint32_t param2)
{
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);

    Retcode_T retcode = WLAN_Setup(&WLANSetupInfo);
    if (RETCODE_OK == retcode)
    {
        retcode = ServalPAL_Setup(AppCmdProcessor);
    }
#if HTTP_SECURE_ENABLE
    if (RETCODE_OK == retcode)
    {
        retcode = SNTP_Setup(&SNTPSetupInfo);
    }
#endif /* HTTP_SECURE_ENABLE */
    if (RETCODE_OK == retcode)
    {
        retcode = HTTPRestClient_Setup(&HTTPRestClientSetupInfo);
    }
    if (RETCODE_OK == retcode)
    {
        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 */
    }
}

/* global functions ********************************************************** */

/** Refer interface header for description */
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 */
    }
}

/**@} */

And now I have this kind of problem :

INFO | XDK DEVICE 1: WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: SntpSentCallback : Success
 INFO | XDK DEVICE 1: AppControllerFire : SNTP server time was not synchronized. Retrying...

 I really don't understand what I did wrong.

Thanks for your help.

0 (0 票)
RE: Using POST Method
答复
19-5-29 上午5:17 回复Elie BOURY。

Hi Elie

What sntp url you are using ?

Try using time.nist.gov and have a good internet connection.

Until the sntp time is synchronised the post and get will not work for security features.

 

WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: HTTPRestClient_Post : unable to resolve hostname error=167976961.
 INFO | XDK DEVICE 1: Error in Post/get request: Will trigger another post/get after INTER_REQUEST_INTERVAL
 INFO | XDK DEVICE 1: Error in WLAN package.
 INFO | XDK DEVICE 1: 	Package ID: 10
 INFO | XDK DEVICE 1: 	Module ID: 3
 INFO | XDK DEVICE 1: 	Severity code: 2
 INFO | XDK DEVICE 1: 	Error code: 1

 

The above error is because it is not able to get the IP address of the url you are providing.

 

Thanks

Priyashi

0 (0 票)
RE: Using POST Method
答复
19-5-29 上午10:06 回复Priyashi Yadav。

Hi and thank you, 

I was already using this sntp url.

To give you all the details, here is my header (of course now I am using these variable names in AppController.c) :

/**
 *  @file
 *
 *  @brief Configuration header for the AppController.c file.
 *
 */

/* header definition ******************************************************** */
#ifndef APPCONTROLLER_H_
#define APPCONTROLLER_H_

/* local interface declaration ********************************************** */
#include "XDK_Utils.h"

/* local type and macro definitions */

/* local module global variable declarations */

/* local inline function definitions */

/* WLAN configurations ****************************************************** */

#warning Please configure your WLAN below and remove this line.

/**
 * WLAN_SSID is the WIFI network name where user wants connect the XDK device.
 * Make sure to update the WLAN_PSK constant according to your required WIFI network.
 */
#define WLAN_SSID                           "XDK_Hotspot"

/**
 * WLAN_PSK is the WIFI router WPA/WPA2 password used at the Wifi network connection.
 * Make sure to update the WLAN_PSK constant according to your router password.
 */
#define WLAN_PSK                            "FreeWifi"

/**
 * WLAN_STATIC_IP is a boolean. If "true" then static IP will be assigned and if "false" then DHCP is used.
 */
#define WLAN_STATIC_IP                      false

/**
 * WLAN_IP_ADDR is the WIFI router WPA/WPA2 static IPv4 IP address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_IP_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_IP_ADDR                        XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_GW_ADDR is the WIFI router WPA/WPA2 static IPv4 gateway address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_GW_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_GW_ADDR                        XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_DNS_ADDR is the WIFI router WPA/WPA2 static IPv4 DNS address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_DNS_ADDR constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_DNS_ADDR                       XDK_NETWORK_IPV4(0, 0, 0, 0)

/**
 * WLAN_MASK is the WIFI router WPA/WPA2 static IPv4 mask address (unused if WLAN_STATIC_IP is false)
 * Make sure to update the WLAN_MASK constant according to your required WIFI network,
 * if WLAN_STATIC_IP is "true".
 */
#define WLAN_MASK                           XDK_NETWORK_IPV4(0, 0, 0, 0)

/* Server configurations ***************************************************** */

/**
 * DEST_SERVER_HOST is the host name of the web server we will send HTTP requests to.
 * If you want to test this example without setting up your own server, you can use publicly available services.
 */
#define DEST_SERVER_HOST                "fas-webteach.sunderland.ac.uk"

/**
 * DEST_SERVER_PORT is the TCP port to which we will send HTTP requests to.
 * The default of 80 should be fine for most applications.
 */
#define DEST_SERVER_PORT                UINT16_C(22)

/**
 * DEST_SERVER_PORT_SECURE is the TCP port to which we will send HTTPS requests to.
 * The default of 443 should be fine for most applications.
 */
#define DEST_SERVER_PORT_SECURE         UINT16_C(22)

/**
 * DEST_POST_PATH is the path relative to the DEST_SERVER_HOST that we will send
 * the HTTP POST request to.
 *
 * Change this value if you use your own web server.
 */
#define DEST_POST_PATH                  "/~ex0eby/sendValuesToDatabase.php"

/**
 * POST_REQUEST_CUSTOM_HEADER_0 is a custom header which is sent along with the
 * POST request. It's meant to demonstrate how to use custom header.
 */

#define POST_REQUEST_CUSTOM_HEADER_0    "X-AuthToken: InsertCrypticAuthenticationToken\r\n"

/**
 * POST_REQUEST_CUSTOM_HEADER_1 is a custom header which is sent along with the
 * POST request. It's meant to demonstrate how to use custom header.
 */
#define POST_REQUEST_CUSTOM_HEADER_1    "X-Foobar: AnotherCustomHeader\r\n"

/**
 * POST_REQUEST_BODY is sent as body with the HTTP POST request
 */
#define POST_REQUEST_BODY               "{ \"Acoustic\": \"3\"}"

/**
 * The time we wait (in milliseconds) between sending HTTP requests.
 */
#define INTER_REQUEST_INTERVAL          UINT32_C(10000)

#warning Configure HTTP_SECURE_ENABLE to 1 to enable the HTTPS based Communication otherwise Communication will happen through HTTP.

/**
 * HTTP_SECURE_ENABLE is Set to Use HTTP With Security
 */
#define HTTP_SECURE_ENABLE              UINT32_C(1)

#if HTTP_SECURE_ENABLE /* Below are SNTP related macros which are only valid for HTTPS */

/**
 * SNTP_SERVER_URL is the SNTP server URL.
 */
#define SNTP_SERVER_URL                 "time.nist.gov"

/**
 * SNTP_SERVER_PORT is the SNTP server port number
 */
#define SNTP_SERVER_PORT                UINT16_C(123)

#endif /* #if HTTP_SECURE_ENABLE */

/**
 * The maximum amount of data we download in a single request (in bytes). This number is
 * limited by the platform abstraction layer implementation that ships with the
 * XDK. The maximum value that will work here is 512 bytes.
 */
#define REQUEST_MAX_DOWNLOAD_SIZE       UINT32_C(512)

/**
 * @brief Gives control to the Application controller.
 *
 * @param[in] cmdProcessorHandle
 * Handle of the main command processor which shall be used based on the application needs
 *
 * @param[in] param2
 * Unused
 */
void AppController_Init(void * cmdProcessorHandle, uint32_t param2);

#endif /* APPCONTROLLER_H_ */

If you can help me it could be really nice because it only remains me to fix this problem and I'm done with my project.

Thanks a lot.

Elie

0 (0 票)
RE: Using POST Method
答复
19-5-29 上午10:22 回复Elie BOURY。

Hi Elie

Did you try the HttpExampleClient application ?

And I am not very clear with what would you want to fix.

Try using 0.de.pool.ntp.org

Hope this works

Thanks

Priyashi

0 (0 票)
RE: Using POST Method
答复
19-5-29 上午11:40 回复Priyashi Yadav。

I am currently using the HttpExampleClient application.

I tried this new URL and it works!

But now I have this error : 

 INFO | XDK DEVICE 1: WLANPersonalWPA2Connect : Connected to WPA network successfully. 
 INFO | XDK DEVICE 1: SntpSentCallback : Success
 INFO | XDK DEVICE 1: SntpTimeCallback : received
 INFO | XDK DEVICE 1: HttpRestClientRequestSentCallback: HTTP request failed to send. error=1357 (Note : RC_HTTP_CLIENT_NO_RESPONSE-1387 , RC_HTTP_SEND_ERROR-1357) 
 INFO | XDK DEVICE 1: Error in XDK110 Application package.
 INFO | XDK DEVICE 1:     Package ID: 153
 INFO | XDK DEVICE 1:     Module ID: 11
 INFO | XDK DEVICE 1:     Severity code: 2
 INFO | XDK DEVICE 1:     Error code: 98
 INFO | XDK DEVICE 1: HTTPRestClient_Post : Failed since Post CB was not received 

Just to remind you, I am trying to send data to my online database, I did a PHP page (the same as the one in the first post) and I'm currently trying to call the URL of this PHP page with the different values in the POST payload. Unfortunately, I have a lot of errors that I don't understand ...

 Thanks

Elie

0 (0 票)
RE: Using POST Method
答复
19-5-30 上午5:38 回复Elie BOURY。

Hi Elie

Will you try using some other url and check if that works to confirm the issue.

As it is not getting response from the server so i suspect that might be the issue

 

Thanks

Priyashi

0 (0 票)