02-10-2023 04:17 PM
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();*/
}
/** ************************************************************************* */
02-10-2023 09:58 PM
Hello, and thank you for contacting us,
This product is no longer owned by Bosch. Please contact Legic:
Thank you