Hi Tomalex,
i’m facing the same problem with eraydeniz, i have a client ,which when i use to send “this is a test data” to www.yahoo.com , has given me the result :
"inside WIP_CEV_OPEN
Client is COnnected
[WIPEV] WIP_CEV_WRITE @ TCPCLIENT 0x180c6938 (0 bytes)
Inside the TCP Handler
inside the WIP_CEV_WRITE
19"
but for some reason i couldn’t send the data to my other modem which i’m using as a server.
do you have some clue about what problem i might face right now?
this is my source code with a brief explanation.
#include "adl_global.h"
#include "wip.h"
/***************************************************************************/
/* prototypes */
/***************************************************************************/
static bool adl_errorHandler( u16 type, ascii * info);
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
#if __OAT_API_VERSION__ >= 400 //this is where the version of the fastrack memory
const u16 wm_apmCustomStackSize = 4096; //is configurated
#else //the configuration is different between Fastrack and Fastrack supreme
u32 wm_apmCustomStack[1024];
wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
/***************************************************************************/
/* Initialization-related event handlers */
/***************************************************************************/
void Timer_Handler (void);
void CekIpHandler (void);
void ClientEventHandler (wip_event_t *Event, void *ctx);
void PingHandler (wip_channel_t Ping,wip_event_t *event, void *ctx);
void ServerEventHandler (wip_event_t *Event, void *ctx);
/***************************************************************************/
ascii GPRS_APN[] = "indosatgprs"; // APN
ascii GPRS_LOGIN[] = ""; // User Name
ascii GPRS_PASSWORD[] = ""; // Password
u16 port = 80; // port of the server which we trying to connect
ascii IP[]= "12.15.7.214" ; // the server address which the TCP CLient trying to connect
wip_bearer_t b; // the bearer profile name
wip_channel_t Channel; // Variable allocated for the TCP socket server
wip_channel_t Ping; // channel allocated to make a ping service
wip_channel_t ClientChannel; // Channel allocated to make a spawned TCP CLient Socket
/***************************************************************************/
//The Common Handler used for the Custom AT Command
static bool adl_errorHandler( u16 type, ascii * info) //Handler if there is an error when the error subscribe is failed
{
return TRUE;
}
void OpenPingHandler (ascii *IP)
{
Ping = wip_pingCreateOpts (IP, PingHandler, NULL, WIP_COPT_REPEAT, 4, WIP_COPT_END);// Handler to the ping function
}
void CloseBearerHandler (void) //Handler to the AT+END (to stop the bearer connection)
{
s8 ret;
ret = wip_bearerStop (b);
adl_atSendResponse (ADL_AT_UNS, "inside Close Bearer handler");
}
void OpenBearerHandler (void) //Handler to AT+OPEN (To start the GPRS bearer connection)
{
s8 ret;
ret = wip_bearerStart (b);
adl_atSendResponse (ADL_AT_UNS, "inside Open Bearer handler");
}
void ReconnectHandler (void) //Handler to do the auto Reconnect GPRS system
{
s8 ret;
ret = wip_bearerStart (b);
adl_atSendResponse (ADL_AT_UNS, "inside reconnect handler");
}
void cobaHandler (adl_atCmdPreParser_t *paras) //Handler to the AT+PING command.
{ //this handler save the number of the destination IP
switch (paras->Type) //and opened the Ping Socket to the destination
{
case ADL_CMD_TYPE_PARA :
{
ascii *alamatIP = ADL_GET_PARAM(paras,0); //to get the first parameter of AT+PING command
OpenPingHandler(alamatIP); //run the ping function
break;
}
}
}
void openClientHandler (void) //Handler to open the new TCP CLient socket
{
Channel = wip_TCPClientCreate(IP,port, ClientEventHandler,NULL);
}
/***************************************************************************/
//Handler to managed all the event occured when the bearer is opened, configured, and started
void EventHandler_Bearer(wip_bearer_t b, s8 event, void *ctx)
{
wip_in_addr_t appIpAddr;
ascii IpAddr[15];
s8 sRet;
int i;
switch (event)
{
case WIP_BEV_CONN_FAILED:
{
wip_bearerStart(b);
adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_CONN_FAILED \r\n" ); // send the Event to the Hyper Terminal
break;
}
case WIP_BEV_IP_CONNECTED:
{
CekIpHandler (); // To Check the IP when the first time connected to the internet
Channel = wip_TCPServerCreate(3000, ServerEventHandler,NULL); // To Create the Client Socket immediately after the GPRS s connected
adl_tmrSubscribe (TRUE,300,ADL_TMR_TYPE_100MS, CekIpHandler); // To periodically (30s) check the modem's IP
break;
}
case WIP_BEV_IP_DISCONNECTED:
{
ReconnectHandler (); // calling the Reconnect function when the IP
adl_atSendResponse( ADL_AT_UNS, "\r\n WIP_BEV_IP_DISCONNECTED \r\n" ); // is disconnected
break;
}
case WIP_BEV_STOPPED: // triggered when the bearer was stopped on purpose
{
adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_STOPPED \r\n" );
break;
}
}
}
/****************************************************************************/
//this is the function to managed the AT+CEKIP function
void CekIpHandler (void)
{
wip_in_addr_t appIpAddr;
ascii IpAddr[15];
s8 sRet;
ascii Buffer[50];
sRet = wip_bearerGetOpts(b,WIP_BOPT_IP_ADDR,&appIpAddr,WIP_BOPT_END); // Get your IP address
wip_inet_ntoa(appIpAddr, IpAddr,15); // Convert the IP Address into ASCII
wm_sprintf(Buffer, "IP address -> %s\r\n",IpAddr); // copy the ascii IP address into the buffer
adl_atSendResponse (ADL_AT_UNS, Buffer); // Display your IP address over UART1
}
/************************************************************************/
//This is to capture the call back of SIM initialization event
void EventHandler_Sim(u8 event)
{
int r;
switch (event)
{
case ADL_SIM_EVENT_FULL_INIT:
r = wip_bearerOpen(&b, "GPRS", EventHandler_Bearer, NULL);
r = wip_bearerSetOpts(b, WIP_BOPT_GPRS_APN, GPRS_APN, WIP_BOPT_LOGIN,GPRS_LOGIN, WIP_BOPT_PASSWORD, GPRS_PASSWORD, WIP_BOPT_END);
r = wip_bearerStart(b);
adl_atSendResponse( ADL_AT_RSP, "\r\n ADL_SIM_EVENT_FULL_INIT \r\n" );
adl_atCmdSubscribe("AT+CEKIP", CekIpHandler, ADL_CMD_TYPE_READ); //make the custom AT+CEKIP command
adl_atCmdSubscribe("AT+END", CloseBearerHandler, ADL_CMD_TYPE_ACT); //make the custom AT+END command
adl_atCmdSubscribe("AT+OPEN", OpenBearerHandler, ADL_CMD_TYPE_ACT); //make the custom AT+OPEN command
adl_atCmdSubscribe("AT+PING", cobaHandler, ADL_CMD_TYPE_PARA|0x0011); //make the custom AT+PING command
adl_atCmdSubscribe("AT+TCPCLIENT",openClientHandler, ADL_CMD_TYPE_ACT); //make the custom AT+TCPCLIENT command
break;
}
}
//***************************************************************************
//This is the function to managed the event related to the CLient Sockets
void ClientEventHandler (wip_event_t *Event, void *ctx)
{
u32 Read;
u32 Write;
ascii *DataBuffer;
ascii writeBuffer[30];
adl_atSendResponse (ADL_AT_UNS, "\r\nInside the TCP Handler\r\n");
switch (Event->kind)
{
case WIP_CEV_READ: //Triggered when the data received by the remote
adl_atSendResponse (ADL_AT_UNS, "\r\nInside the WIP_CEV_READ\r\n"); //server is ready to read
DataBuffer = adl_memGet ((u16) (Event->content.read.readable+1)); //Preparing the memory needed for the incoming data
wm_memset (DataBuffer,0x00,Event->content.read.readable); //Set all the memory into 0
Read = wip_read (Channel, DataBuffer, Event->content.read.readable); //Read the data send by the remote server
*(DataBuffer+Read) = '\0';
if (Read >0)
{
adl_atSendResponse (ADL_AT_UNS, DataBuffer); //send the data read to the external application
adl_atSendResponse (ADL_AT_UNS,"\r\n");
}
else
{
adl_atSendResponse (ADL_AT_UNS,"ReadError"); //triggered when the reading process failed
}
break;
case WIP_CEV_OPEN: //triggered when the the Client Socket is connected
adl_atSendResponse (ADL_AT_UNS,"\r\ninside WIP_CEV_OPEN\r\n"); //to the remote server
adl_atSendResponse (ADL_AT_UNS,"\r\nClient is COnnected\r\n");
break;
case WIP_CEV_WRITE: //Triggered when the writing process to the
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_WRITE\r\n"); //channel is completed
Write = wip_write(Channel, "this is a test data",19); //Saving the data into the Write buffer
wm_itoa (Write,writeBuffer); //Convert the return value of the writing process into ascii
adl_atSendResponse (ADL_AT_UNS,writeBuffer); //Send the return value into Hyper Terminal
adl_atSendResponse (ADL_AT_UNS,"\r\n");
break;
case WIP_CEV_ERROR : //Triggered when the connecting to remote server
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_ERROR\r\n"); //is failed
break;
case WIP_CEV_PEER_CLOSE : //Triggered when the CLient Socket is closed
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_PEER_CLOSE\r\n");
break;
}
}
/*this is the function to handle the ClientSpawned Socket from the server Socket
/***************************************************************************/
void ServerEventHandler (wip_event_t *Event, void *ctx)
{
u32 Read;
u32 Write;
ascii *DataBuffer;
ascii writeBuffer[30];
adl_atSendResponse (ADL_AT_UNS, "\r\nInside the TCP Handler\r\n");
ClientChannel = Event->channel;
switch (Event->kind)
{
case WIP_CEV_READ: //Triggered when the data received by the remote
adl_atSendResponse (ADL_AT_UNS, "\r\nInside the WIP_CEV_READ\r\n"); //server is ready to read
DataBuffer = adl_memGet ((u16) (Event->content.read.readable+1)); //Preparing the memory needed for the incoming data
wm_memset (DataBuffer,0x00,Event->content.read.readable); //Set all the memory into 0
Read = wip_read (ClientChannel, DataBuffer, Event->content.read.readable); //Read the data send by the remote server
*(DataBuffer+Read) = '\0';
if (Read >0)
{
adl_atSendResponse (ADL_AT_UNS, DataBuffer); //send the data read to the external application
adl_atSendResponse (ADL_AT_UNS,"\r\n");
}
else
{
adl_atSendResponse (ADL_AT_UNS,"ReadError"); //triggered when the reading process failed
}
adl_memRelease (DataBuffer);
break;
case WIP_CEV_OPEN: //triggered when the the Client Socket is connected
adl_atSendResponse (ADL_AT_UNS,"\r\ninside WIP_CEV_OPEN\r\n"); //to the remote server
adl_atSendResponse (ADL_AT_UNS,"\r\nClient is COnnected\r\n");
Write = wip_write(Channel, "this is a test data",19); //Saving the data into the Write buffer
wm_itoa (Write,writeBuffer); //Convert the return value of the writing process into ascii
adl_atSendResponse (ADL_AT_UNS,writeBuffer); //Send the return value into Hyper Terminal
adl_atSendResponse (ADL_AT_UNS,"\r\n");
break;
case WIP_CEV_WRITE: //Triggered when the writing process to the
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_WRITE\r\n"); //channel is completed
break;
case WIP_CEV_ERROR : //Triggered when the connecting to remote server
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_ERROR\r\n"); //is failed
break;
case WIP_CEV_PEER_CLOSE : //Triggered when the CLient Socket is closed
adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_PEER_CLOSE\r\n");
break;
}
}
//This is the function to handle the Ping Command
/***************************************************************************/
void PingHandler (wip_channel_t Ping, wip_event_t *event, void *ctx)
{
adl_atSendResponse (ADL_AT_UNS, "\r\nthis is inside the PingHandler\r\n");
switch (event->kind)
{
case WIP_CEV_PING : //triggered when there is a reply from the
adl_atSendResponse(ADL_AT_RSP,"\r\nthis is the ping answered\r\n"); //destination IP Address
break;
case WIP_CEV_ERROR : //Triggered when the sending of ICMP is failed
adl_atSendResponse (ADL_AT_UNS,"\r\nthe ping is failed\r\n");
break;
}
}
//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
s8 Retval;
s32 Result = -1;
Result = adl_errSubscribe( adl_errorHandler );
if ( OK != Result )
{
TRACE (( 1, "adl_errSubscribe failed" )); //should not happen. Nevermind test it and return here if not available
return;
}
Result = wip_ATCmdSubscribe();
if ( OK == Result )
{
/************************this is the main program start*******************************/
Retval = wip_netInitOpts(WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1,WIP_NET_OPT_LOG_EVENTS, TRUE,WIP_NET_OPT_END);
adl_simSubscribe(EventHandler_Sim, NULL);
adl_atSendResponse( ADL_AT_RSP, "\r\n Main OK \r\n" );
adl_atUnSoSubscribe("WIP_BEV_IP_DISCONNECTED",ReconnectHandler);
/*****************************End of the main program*********************************/
}
else
{
TRACE (( 1, "+WIP AT Commmands subscribtion failed." )); //error : memory lack within Open AT application
}
}