if im correct, the FREE examples (the one which is in the wip documentation and the one thats an example project in the dev studio) doesnt close the channels correctly
just got my own “Open At Tutorial” book and well, what shall i say… using the example which is in it, the polling works…
even if the error is hidden somewhere else, this example seems to work - or at least it did so for 1 hour now. You get a request every ~1.3 seconds, which should be even “fast” enough in systems where the user is waiting to see a result on his display - like the one im doing right now
#include "adl_global.h"
#include "generated.h"
#include "wip_net.h"
#include "wip_http.h"
#include "wip_bearer.h"
#include "wm_types.h"
const u16 wm_apmCustomStackSize = 4096;
#define GPRS_APN "web.vodafone.de"
#define GPRS_LOGIN ""
#define GPRS_PASSWORD ""
#define HTTP_PORT 80
ascii * HTTP_STR_HOSTNAME = "http://asdf.qwerty";
char smsTime[19];
int befehl = 0;
char identifikation[12];
wip_bearer_t bearerHandle = NULL;
wip_channel_t httpCnxCh = NULL;
wip_channel_t httpDataCh = NULL;
adl_tmr_t *timer_ptr;
u32 timeout_period = 5;
s32 GPIO_event_handle = 0;
s32 Polling_handle;
adl_ioDefs_t gpio_Input[1] = { ADL_IO_GPIO | 21| ADL_IO_DIR_IN };
int polling = 0;
void simHandler(u8 Event);
void evh_bearer(wip_bearer_t b, s8 event, void *ctx);
void Timer_Handler(u8 id, void * ctx);
void httpDataHandlerPolling(wip_event_t *ev, void *ctx);
void ausgeUmbruch(char* text);
void bearer_start();
void evh_bearer_polling(wip_bearer_t b, s8 event, void *ctx);
void httpFinalizerPolling(void *ctx);
void ausgabe(char* text){
adl_atSendResponse(ADL_AT_UNS, text);
}
void ausgabeUmbruch(char* text){
ausgabe(text);
ausgabe("\n");
}
void ausgabeZweiTexteUmbruch(char* eins, char* zwei){
ausgabe(eins);
ausgabe(zwei);
ausgabe("\n");
}
void ausgabeVariable(char* Name, char* value){
ausgabe(Name);
ausgabe(": ");
ausgabe(value);
ausgabe("\n");
}
void ausgabeZahl(char* vorText, int zahl){
char myBuf[20] ;
sprintf(myBuf, "%i", zahl);
ausgabeZweiTexteUmbruch(vorText, myBuf);
}
void restart_bearer(){
ausgabeUmbruch("restarting the bearer...");
int r = wip_bearerStop(bearerHandle);
if(r == 0)
ausgabeUmbruch("wip_bearerStop: ok");
else if(r == WIP_BERR_OK_INPROGRESS)
ausgabeUmbruch("wip_bearerStop: WIP_BERR_OK_INPROGRESS");
else if(r == WIP_BERR_BAD_HDL)
ausgabeUmbruch("wip_bearerStop: WIP_BERR_BAD_HDL");
}
void pollingWasntReady(u8 id, void *ctx){
httpFinalizerPolling(NULL);
}
void httpFinalizerPolling(void *ctx){
if(polling == 1)
evh_bearer_polling(NULL, WIP_BEV_IP_CONNECTED, NULL);
else{
timer_ptr = (adl_tmr_t*)adl_tmrSubscribe(FALSE, timeout_period, ADL_TMR_TYPE_100MS, (adl_tmrHandler_t) pollingWasntReady);
if(timer_ptr < 0)
ausgabeUmbruch("adl_tmrSubscribe failed");
}
}
void httpDataHandlerPolling(wip_event_t *ev, void *ctx){
char tmpbuf[256];
int len, tmplen, r;
switch(ev->kind){
case WIP_CEV_PING:
ausgabeUmbruch("PONG :)");
break;
case WIP_CEV_DONE:
break;
case WIP_CEV_OPEN:
break;
case WIP_CEV_READ:
tmplen = 0;
while( (len = wip_read( ev->channel, tmpbuf, sizeof(tmpbuf)-1)) > 0) {
tmpbuf[len] = 0;
ausgabeUmbruch(tmpbuf);
tmplen += len;
}
break;
case WIP_CEV_WRITE:
break;
case WIP_CEV_PEER_CLOSE:
r = wip_close(httpDataCh);
if(r == 0){
//ausgabeUmbruch("wip_close(httpDataCh): ok");
}else if(r == WIP_CERR_MEMORY){
ausgabeUmbruch("wip_close(httpDataCh): WIP_CERR_MEMORY");
}else if(r == WIP_CERR_INVALID ){
ausgabeUmbruch("wip_close(httpDataCh): WIP_CERR_INVALID ");
}
r = wip_close(httpCnxCh);
if(r == 0){
//ausgabeUmbruch("wip_close(httpCnxCh): ok");
}else if(r == WIP_CERR_MEMORY){
ausgabeUmbruch("wip_close(httpCnxCh): WIP_CERR_MEMORY");
}else if(r == WIP_CERR_INVALID ){
ausgabeUmbruch("wip_close(httpCnxCh): WIP_CERR_INVALID ");
}
break;
case WIP_CEV_ERROR:
ausgabeUmbruch("WIP_CEV_ERROR - RESTART OF THE BEARER");
restart_bearer();
break;
}
}
void createDataChannelPolling(u8 id, void *ctx){
httpDataCh = wip_getFileOpts(httpCnxCh, HTTP_STR_HOSTNAME, httpDataHandlerPolling,
NULL,
WIP_COPT_FINALIZER, httpFinalizerPolling,
WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_GET,
WIP_COPT_END);
if(httpDataCh == NULL)
ausgabeUmbruch("wip_getFileOpts: Failure");
}
void evh_bearer_polling(wip_bearer_t b, s8 event, void *ctx){
//ausgabeZahl("evh_bearer_polling: ", event);
switch(event){
case WIP_BEV_IP_CONNECTED:
/* Start the HTTP Session */
httpCnxCh = wip_HTTPClientCreateOpts(NULL, NULL,
WIP_COPT_HTTP_HEADER, "User-Agent", "WIPHTTP/1.0",
WIP_COPT_END);
if(httpCnxCh == NULL)
ausgabeUmbruch("evh_bearer_polling: wip_HTTPClientCreateOpts failed!");
timer_ptr = (adl_tmr_t*)adl_tmrSubscribe(FALSE, timeout_period, ADL_TMR_TYPE_100MS, (adl_tmrHandler_t) createDataChannelPolling);
if(timer_ptr < 0)
ausgabeUmbruch("adl_tmrSubscribe failed");
break;
case WIP_BEV_CONN_FAILED: //havent seen this event yet -> untested
ausgabeUmbruch("WIP_BEV_CONN_FAILED");
restart_bearer();
break;
case WIP_BEV_STOPPED:
ausgabeUmbruch("##WIP_BEV_STOPPED##");
int r = wip_bearerClose(bearerHandle);
if(r == 0)
ausgabeUmbruch("wip_bearerClose: ok");
else if(r == WIP_BERR_BAD_HDL )
ausgabeUmbruch("wip_bearerClose: Invalid handle\n");
else if(r == WIP_BERR_BAD_STATE )
ausgabeUmbruch("wip_bearerClose: Bearer was not stopped before closing\n");
r = wip_netExit();
if(r == 0)
ausgabeUmbruch("wip_netExit: okay (allways returns 0)");
else
ausgabeZahl("wip_netExit: ", r);
bearer_start(evh_bearer_polling);
break;
case WIP_BEV_IP_DISCONNECTED:
ausgabeUmbruch("evh_bearer_polling: IP Communication got terminated!");
break;
default:
ausgabeUmbruch("evh_bearer: other event");
break;
}
}
void bearer_start(wip_bearerHandler_f eventHandler_Bearer){
//ausgabeUmbruch("starting the bearer");
s8 ret;
/*Open the GPRS bearer*/
ret = wip_netInit();
if(ret == 0){
//ausgabeUmbruch("wip_netInit: ok");
}else
ausgabeZahl("wip_netInit: ", ret);
ret = wip_bearerOpen(&bearerHandle, "GPRS", eventHandler_Bearer, NULL);
if(ret == 0){
//ausgabeUmbruch("wip_bearerOpen: ok");
}else if(ret == WIP_BERR_NO_DEV )
ausgabeUmbruch("wip_bearerOpen: The device does not exist \n");
else if(ret == WIP_BERR_ALREADY )
ausgabeUmbruch("wip_bearerOpen: The device is already opened \n");
else if(ret == WIP_BERR_NO_IF )
ausgabeUmbruch("wip_bearerOpen: The network interface is not available \n");
else if(ret == WIP_BERR_NO_HDL )
ausgabeUmbruch("wip_bearerOpen: No free handle\n");
else{
char myBuf[20] ;
sprintf(myBuf, "%i", ret);
ausgabeZweiTexteUmbruch("wip_bearerOpen: ", myBuf);
}
ret = wip_bearerSetOpts(bearerHandle,
WIP_BOPT_GPRS_APN, GPRS_APN,
WIP_BOPT_LOGIN, GPRS_LOGIN,
WIP_BOPT_PASSWORD, GPRS_PASSWORD,
WIP_BOPT_END
);
if(ret == 0){
//ausgabeUmbruch("wip_bearerSetOpts: ok");
}else if(ret == WIP_BERR_BAD_HDL )
ausgabeUmbruch("wip_bearerSetOpts: Invalid handle \n");
else if(ret == WIP_BERR_OPTION)
ausgabeUmbruch("wip_bearerSetOpts: Invalid option \n");
else if(ret == WIP_BERR_PARAM)
ausgabeUmbruch("wip_bearerSetOpts: Invalid option value \n");
else{
char myBuf[20] ;
sprintf(myBuf, "%i", ret);
ausgabeZweiTexteUmbruch("wip_bearerOpen: ", myBuf);
}
ret = wip_bearerStart(bearerHandle);
if(ret == -27){
//ausgabeUmbruch("wip_bearerStart: ok");
}else if(ret == WIP_BERR_LINE_BUSY)
ausgabeUmbruch("wip_bearerStart: Line busy\n");
else if(ret == WIP_BERR_NO_ANSWER)
ausgabeUmbruch("wip_bearerStart: No answer\n");
else if(ret == WIP_BERR_NO_CARRIER)
ausgabeUmbruch("wip_bearerStart: No carrier\n");
else if(ret == WIP_BERR_NO_SIM)
ausgabeUmbruch("wip_bearerStart: No SIM card inserted\n");
else if(ret == WIP_BERR_PIN_NOT_READY)
ausgabeUmbruch("wip_bearerStart: PIN code not entered\n");
else if(ret == WIP_BERR_GPRS_FAILED)
ausgabeUmbruch("wip_bearerStart: GPRS setup failure\n");
else if(ret == WIP_BERR_PPP_LCP_FAILED)
ausgabeUmbruch("wip_bearerStart: LCP negotiation failure\n");
else if(ret == WIP_BERR_PPP_AUTH_FAILED)
ausgabeUmbruch("wip_bearerStart: PPP authentication failure\n");
else if(ret == WIP_BERR_PPP_IPCP_FAILED)
ausgabeUmbruch("wip_bearerStart: IPCP negotiation failure\n");
else if(ret == WIP_BERR_PPP_LINK_FAILED)
ausgabeUmbruch("wip_bearerStart: PPP peer not responding to echo requests\n");
else if(ret == WIP_BERR_PPP_TERM_REQ)
ausgabeUmbruch("wip_bearerStart: PPP session terminated by peer\n");
else if(ret == WIP_BERR_CALL_REFUSED)
ausgabeUmbruch("wip_bearerStart: Incoming call refused\n");
else if(ret == -29)
ausgabeUmbruch("wip_bearerStart: WIP_BERR_DEV");
else{
char myBuf[20] ;
sprintf(myBuf, "%i", ret);
ausgabeZweiTexteUmbruch("wip_bearerStart: ", myBuf);
}
}
int anz = 0;
void GPIO_event_Handler(s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void *Param)
{
//the handler gets called once after the start of the programm.... dont want to start it imedeatly
if(anz == 0){
anz++;
}else{
switch (Event)
{
case ADL_IO_EVENT_INPUT_CHANGED:
if (adl_ioReadSingle(Polling_handle, &gpio_Input[0]) == 1){
if(polling == 0){
ausgabeUmbruch("aktivierung des Polling");
polling = 1;
bearer_start(evh_bearer_polling);
}else{
ausgabeUmbruch("Pausiere polling");
polling = 0;
}
}else{
ausgabeUmbruch("Setze polling fort");
polling = 1;
}
break;
}
}
}
void main_task ( void )
{
polling = 0;
GPIO_event_handle = adl_ioEventSubscribe(GPIO_event_Handler);
//subscribe to GPIO service with polling every 100ms for GPIO
Polling_handle = adl_ioSubscribe(1, gpio_Input, ADL_TMR_TYPE_100MS, 1, GPIO_event_handle);
// If both subscriptions were ok, return OK
if ((GPIO_event_handle > 0) && (Polling_handle > 0)){
ausgabeUmbruch("Subscribed to GPIO Events: OK");
}else{
ausgabeUmbruch("Subscribed to GPIO Events: FAILED\n");
}
}
edit:
now with a working restart of the bearer
edit 2:
for the search function
wip_cev_error
wip_berr_dev -29