Newbie question - how do I use UMTSStickNetIf?

29 Apr 2012

I'm trying to write an application that uses a GPRS (UMTS?) USB stick to communicate and UMTSStickNetIf seems to be the solution I need.

I've put together the simple test program that should just open a connection and then close it again however I can't get it to compile.

I get error 153 (<<quote>>"expression must have class type"<</quote>>) for each of the four lines that use myGPRS. (e.g. myGPRS.setup() etc.)

Changing the "."s to "->"s causes error 131 (<<quote>>"expression must have pointer-to-class type"<</quote>>) instead.

My C++ is somewhat limited and I'm sure I've made a very basic error somewhere but if someone could point me in the right direction it would be greatly appreciated.

Edit: Further googling suggested that I should remove the brackets from the end of my definition of myGPRS. Doing this allows the program to compile but I then get loads of undefined symbol errors from the linker so I suspect I may be missing an include somewhere.

#include "mbed.h"
#include "UMTSStickNetIf.h"

Serial pc(USBTX, USBRX);
UMTSStickNetIf myGPRS(); 
 
int main() {
    pc.baud(115200);
    
    pc.printf("Attempting to initialise GPRS Stick\n\r");
    UMTSStickErr err_setup = myGPRS.setup();
    pc.printf("Result code: %d (%s)\n\n\r", err_setup, err_setup==0?"Success":"Failure");
    
    if(err_setup==0)
    {
        pc.printf("Attempting to establish a PPP connection\n\r");
        PPPErr err_connect = myGPRS.connect(NULL, NULL, NULL); //Connect using SIM card defaults
        pc.printf("Result code: %d (%s)\n\n\r", err_connect, err_connect==0?"Success":"Failure");
        
        if(err_connect==0)
        {
            IpAddr addr = myGPRS.getIp();
            pc.printf("Connection established, IP address = %d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
   
            pc.printf("Attempting to disconnect the PPP connection\n\r");
            PPPErr err_disconnect = myGPRS.disconnect(); 
            pc.printf("Result code: %d (%s)\n\n\r", err_disconnect, err_disconnect==0?"Success":"Failure");
        }
    }
}
29 Apr 2012

Solved it!

As I said in my edit the definition for myGPRS needed to be:

UMTSStickNetIf myGPRS; 

Having done that I needed to edit netCfg.h in the NetServices library to turn on all the USB options:

#ifndef NET_CFG_H
#define NET_GPRS 1
#define NET_PPP 1
#define NET_GPRS_MODULE 1
#define NET_ETH 1
#define NET_USB_SERIAL 1
#define NET_CFG_H 1
#define NET_UMTS 1
#define NET_USB 1
#define NET_LWIP_STACK 1
#endif

(Still fiddling with those options so don't know if I need them all on)

I also had to remove the getIp() references as they were causing an error about ambiguous references - possibly because I left one of the options on that should be off.