IOException: Profile could not be activated

1,331 views
Skip to first unread message

Thomas Hermansson

unread,
Apr 9, 2010, 10:52:34 AM4/9/10
to Cinterion Java enabled chips support
Hi all!

I repeatedly get a strange error with my application.

After a restart it tells me IOException:Profile could not be activated
when I start the application the next time. (I´m using Florentines apn
detection algorithm). And it doesn´t matter how many restarts I make,
I always get this.

Then I removed the SIM card, inserted it into a new phone and dialed
to a friend, just to check that the sim was working, and it was :-)

So I put the SIM back into the TC65, runs the same application as
before, and now it works just fine :-(

Any idea of what might be causing this? Are there any regulations that
I need to make a call once in a while or so? Or do I need to
disconnect a longer period of time when it restarts?

br
Thomas Hermansson

Florent Clairambault

unread,
Apr 9, 2010, 11:00:58 AM4/9/10
to java...@googlegroups.com
Hi Thomas,

    My APN detection code just checks a list of APN. If your APN isn't in this list, it just won't find it. Maybe you didn't set the AT^SJNET at next startup.

    There is not requirement to call someone to make the GPRS connection work again, on all my chips and GSM providers, I never do any calls.

    Maybe you should copy/paste code and a log of what ATCommands were actually executed by your code.

Best regards,
--
Florent Clairambault

Cell : +33 6 86 95 54 05
Phone : +33 1 45 58 38 10
Fax : +33 9 57 60 38 10
MSN : Flo...@clairambault.fr
Jabber/Gtalk: sup...@gmail.com
Skype: florent.clairambault



--
You received this message because you are subscribed to the Google Groups "Cinterion Java enabled chips support" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javacint+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javacint?hl=en.


Thomas Hermansson

unread,
Apr 10, 2010, 7:31:47 AM4/10/10
to java...@googlegroups.com
Hi Florent!

This is the function I call at startup, where I have added the APN:s for the three most common operators in Sweden.
For this unit on which I have seen this problem there is a Telenor - SIM (so the second APN is the correct one).

When running this code in 99% of the cases the function returns the second APN (internet.telenor.se) and everything works fine, but when I get the problem then it fails for all three APN:s. (And the System.out.println( "Failed : " + ex.getClass() + " : " + ex.getMessage() ); statement is printed for all three attempts (and the output is "IOException:Profile could not be activated")

Two questions:
a) I seem to have removed the Synchronized call from "your", would this somehow cause this problem?
b) If the webpage I am testing with for somereason is not working properly (www.surfvind.se - webhotel not working or webpage not responding), would this then affect this?

greatful to all help I can get :-)

br
Thomas Hermansson 

public ATCommand b
 public void ReadAndSendData() {
try
{  
   b = new ATCommand(false);
   b.addListener(this);
   SetupHttpCommunication();
.....
    }
}

 void SetupHttpCommunication()
    {
try
{
Result = b.send("AT+CMEE=2\r\n");
Result = b.send("AT^SJNET="+AutoDetectApn(b)+"\r\n");
}
catch(Exception e)
{
System.out.println("Error in setup communication.");
System.out.println(e.getMessage());
Reboot();
}
    }
public void Reboot()
    {
     try{
     ATCommand bb = new ATCommand(false);

     bb.addListener(this);
     System.out.println("Exiting OK");

     Result = bb.send("AT+CFUN=1,1\r\n");
     Thread.sleep(60000);
     }
     catch(Exception e)
     {

     }
    }
    public String AutoDetectApn( ATCommand atc ) {
    
        String[] apnList = {
            "\"gprs\",\"internet.tele2.se\",\"\",\"\"",   //Tele2
            "\"gprs\",\"internet.telenor.se\",\"\",\"\"",  //Telenor
            "\"gprs\",\"online.telia.se\",\"\",\"\"" //Telia
        };
     
       //synchronized (atc) {
            System.out.println( "Waiting 30s..." );
            try {
                Thread.sleep( 30000 );
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
     
            for (int i = 0; i < apnList.length; ++i) {
                try {
                    String apn = apnList[i];
                    System.out.println( "Trying apn " + apn + "..." );
                    atc.send( "AT^SJNET=" + apn + "\r" );
     
                    http = (HttpConnection) Connector.open( "http://www.surfvind.se" );
                    http.setRequestMethod("GET");
             rc = http.getResponseCode();
             if (rc != HttpConnection.HTTP_OK) 
             {
              http.close();
              continue;
             }
                    http.close();
                    return apn;
                } catch (Exception ex) {
                    System.out.println( "Failed : " + ex.getClass() + " : " + ex.getMessage() );
                }
            }
       // }
     
     
        // We couldn't find any APN
        return null;
--
vänligen
Thomas Hermansson
TNA Software AB
Jakthornsgränden 22
226 52  Lund
http://www.tna.se
Mobil:0702-313255

Florent Clairambault

unread,
Apr 10, 2010, 2:20:07 PM4/10/10
to java...@googlegroups.com
Hi,

   "Profile could not be activated" is related to the misconfiguration of the GPRS network. But you have to remember to wait 30s before trying this because it requires the GSM to log into the network.

   By the way, you should save the APN once it is detected (using a Settings management class) and only re-detect it when the IMSI (the SIM card identifier) changes.

   Testing with HttpConnection is alright. My test was just to open the http port on a server to check if it didn't throw an exception.

Best regards,
--
Florent Clairambault

Thomas Hermansson

unread,
Apr 10, 2010, 7:31:39 PM4/10/10
to java...@googlegroups.com
Hi again!

But I do wait 30s (but I missed to include that in the code I sent.

So the same code is run, and one time it works, and the next time it doesn´t. And the only thing I have been noticing is that it starts working again after a longer period of  turning of the device or switching the SIM card to another unit.

But if you say that there are no regulations that I might violate then I guess I need to find another solution....maby turning of the radio for a 30min period when this happens would be a solution. To bad it takes ages to retest only :-)

br
Thomas

Florent Clairambault

unread,
Apr 10, 2010, 8:53:15 PM4/10/10
to java...@googlegroups.com
    You should also try not to autodetect the APN at each startup but to save it once you have it. There might be a network protection against some sort "APN guessing" attacks. This is just a wild guess as I haven't heard anything like that.

    I can't help you much as I don't have any (even rare) problem with this code. And I have tested it with a lot more than 3 APN. I didn't say I haven't violated any regulation with that code. But in France (where I live), spain and germany (where it has been tested so far), it works very well. It cleared a lot of difficulties with technicians not knowing what is the right APN in the current country.

    If anyone has better ideas, you're welcome.

Best regards,
--
Florent Clairambault


Thomas Hermansson

unread,
Apr 11, 2010, 1:19:05 PM4/11/10
to java...@googlegroups.com
Hi Florent!

I should change this according to your recommendations, and I doubt that this part of the code will violate anything. I was more conserned about any other part of my code. (That reconnects every second minute and fetches a GET url with some arguments. Or if there is any action I need to take if there is an incoming call to this unit for example (or just something else).

So my conclusion is that your code works as it should without causing any problems at all, but still my problem remains. :-/

And I´m not sure if there is any way to debug this further. Is it possible to get further details of why and what the Network responded when trying to activate the correct apn?

br
Thomas

Thomas Hermansson

unread,
Apr 17, 2010, 12:11:55 PM4/17/10
to java...@googlegroups.com
Hi again!

Back with more details:

I turned on the CEER report and now I can see that I get this error:


ER: AT+CEER
                                                                 
+CEER: 50,102,0
 


3.4.10GSM release cause for Session Management (SM)
Number Description
102  Recovery on timer expiry

Anyone knows what this means?

br
Thomas Hermansson

Thomas Hermansson

unread,
Apr 17, 2010, 6:27:06 PM4/17/10
to java...@googlegroups.com

Hi again!

Here comes even a better description with more details :)

When running the APN detection code, with success this is the output I will get:

Trying apn "gprs","internet.tele2.se","",""...
Failed : class java.io.IOException : Profile could not be activated
AT+CEER
+CEER: 50,33,0     <------------------ Note the cause 50,33. This is correct as this is the wrong APN and SHOULD fail.
OK

Next itteration with the correct APN                                                                          
Trying apn "gprs","internet.telenor.se","",""...
                                                             
Start OK: P1NSleep imei:354745030513008

And now the software will run for a longer period aprox 1 week - 1 month. Then communication stops working and my device is automaticly restarted. But this time the startup looks different (even if I cut the power for several minutes and then restarts it)

Now I get the response as in my previous posting:

Trying apn "gprs","internet.tele2.se","",""...
Failed : class java.io.IOException : Profile could not be activatedER: AT+CEER
+CEER: 50,102,0   <--------- Note that now we have a different error code. And I will get the same response even when trying the correct APN.

Error cause 102 in the TC65 AT command manual is: 



3.4.10GSM release cause for Session Management (SM)
Number Description
102  Recovery on timer expiry

But this is all info I can find about this. I guess I could solve the problem by maby add a delay of 1 hour before next retry to get it to work,.....but I´d rather know the background of why and what this means. :-)

Anyone that has heard about this?

br
Thomas Hermansson 

Joschka

unread,
Jan 15, 2013, 8:34:03 AM1/15/13
to java...@googlegroups.com, tho...@tna.se
Hi Zoltán,

in my experience, "profile not found" can also be the result of some problems in the network (i.e. not your code per se). For example, the cell you are in could have filled up with users requesting phone connections, which get prioritized, so it won't let you connect GPRS (or even get kicked out, not sure). If you run into this, is it fixed by immediate reboot? If not, it would indicate a problem with the network first (and your code only by not managing it correctly).

You could go into "disconnected" state when you get these exception (there are others indicating network problems, e.g. couldnotresolvehostname) in which you halt all attempts to use the network and just try to get GPRS attached again. If it is a problem with the cell, you have no idea when it will be back up... So take into consideration it could be some time, maybe progressively increase the delay between attempts. Also have a look at the BearerControlListener class.

No idea why you get memory problems, maybe thats in your exception handling code? I think you can't close Outputstream/Httpconnection because they don't exist (IIRC connector.open will throw you the profilenotfound).

Regards,
Joschka

Am Dienstag, 15. Januar 2013 12:35:20 UTC+1 schrieb Zoltán Baranyi:
Hi,

I hope both of you are still here in the group, or somebody else is here who is familiar with this strange error. 

I experience the same error "Profile could not be activated", with two differences: I use TC65i-X, and I got "+CEER: 0,0,0" response to the execution of "AT+CEER" command after I caught the IOException. So I don't have any error code, what I can use to determine what the real problem is. I've read about a few problems what may cause this error, for example:
- GPRS hasn't been initialized at the time of sending the request
- HttpConnection wasn't closed after the previous request
- Timeout
- Connection error

Here is the shortened code:

public void sendRequest( Request request )
{
 
OutputStream os = null;
 
HttpConnection conn = null;
 
Long transactionId = null;


 
try
 
{
   
byte[] requestXml = buildRequestXML( request );
   conn
= buildHttpConnection( requestUrl );
   os
= conn.openOutputStream();
   os
.write( requestXml );
   transactionId
= processResponse( conn );
 
}
 
catch ( IOException e )
 
{
   
new QueryLastErrorDetailsCommand().execute();
   setupNetwork
();
 
}
 
catch ( Exception e )
 
{
   
ExceptionHandler.handleException( "An exception occured while sending the request: ", e, logger );
 
}
 
finally
 
{
   
try
   
{
     os
.close();
     conn
.close();
   
}
   
catch ( Exception e )
   
{
     
ExceptionHandler.handleException( "An exception occured while closing resources: ", e, logger );
   
}
 
}
}

private HttpConnection buildHttpConnection( String requestUrl ) throws IOException
{
  HttpConnection conn = ( HttpConnection ) Connector.open( requestUrl );
  conn.setRequestMethod( HttpConnection.POST );
  conn.setRequestProperty( "Content-Language", "en-US" );
  conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );

  return conn;
}



Everything seems to be clear and it works fine for a while. But once it fails, it constantly stays in the faulty state and I always get the cited IOException. Additionally, what I also experience is running out of the free memory at each attempt, and I can't close neither the OutputStream nor the HttpConnection.

I tried to re-initialize the GPRS connection, waiting for 60 seconds after an exception, but nothing has helped, I still get the exception, and the attempts eat my memory. 

Does anybody have the same problem, or has the solution? 


Thanks,
Zoltán Baranyi

ejw

unread,
Jan 15, 2013, 10:28:12 AM1/15/13
to java...@googlegroups.com, tho...@tna.se
Hi Zoltán,

From memory most of the 'Profile...' errors I had when testing were network related. In order to deal with these issues we use a system where we try 5 connection attempts, change to different settings and try again. If there is still no connection we finally drop into Airplane mode for a while. The systems store their data and, on coming out of airplane mode, the systems remake a connection and then downloads the stored data packets.

Best wishes
ejw

Florent Clairambault

unread,
Jan 20, 2013, 4:34:10 PM1/20/13
to
All the network stack doesn't handle well unstable network connections.

For the memory leak, as Joschka said, your resource closing code isn't ok. Because the exception does occur while doing the .openOutputStream. So your HttpConnection is never closed. You need to change it to that:
 try {
     if ( os != null )
         os.close();
 }
 catch ( Exception e ) {
     ExceptionHandler.handleException( "An exception occured while closing the output stream: ", e, logger );
 }
 try {
     if ( conn != null )
         conn.close();
 }
 catch ( Exception e ) {
     ExceptionHandler.handleException( "An exception occured while closing the http connection: ", e, logger );
 } 
Still, the JVM *should* release your resources. But it seems it doesn't do it correctly.

For the actual problem, I'm pretty sure it's always related to the network, but some cases are harder to reproduce/explain than others. What you can do is to :
- Dettach GPRS : Some networks break the GPRS connection
- Switch to airplane mode as ejw said
- Obviously restart if you couldn't reach your host in the last X hours as a safety measure.

Best regards,
--
Florent

--
javacint group - http://www.javacint.com/
 
 

Zoltán Baranyi

unread,
Jan 18, 2013, 5:21:18 AM1/18/13
to java...@googlegroups.com
Hi,

Thanks all of you for the quick replies and for the good advice. They helped me a lot.

I've solved the memory leak. Finally, I've found it wasn't related to neither the HttpConnection nor the exception handling. But of course you're right in the resource closing, it seems, I shortened a bit more on the posted code than I should have done :)

And I almost solved the "Profile..." exception as well. When it occurs, I detach the GPRS connection, wait for a while, and attach it again. It works, but I still have a problem: every second request fails with error "+CEER: 50,34,0". AFAIK it means "GSM cause for session management"/"service option temporary out of order". Does anybody know if I can solve it, or do I have to switch the GPRS detached and attached again?

If I detach GPRS after every request, everything works fine, but it causes some delay. Is it the only solution?

Nice community anyway :)

Cheers,
Zoltán Baranyi

Nikita Kapitonov

unread,
Jan 18, 2013, 6:55:16 AM1/18/13
to java...@googlegroups.com
I think if you attach-detach GPRS connection on every request, it could cause excess money loss, if your GSM operator have minimum data quantity per GPRS session (many of them have). As for me, I try to send a request several times before detach the connection, waiting a minute between each try, and most of the time I have success with second or third try, if first one fails.

Another bad condition I experience is when the connection hangs on trying to open it. Sometimes I receive an Exception only after 10-20 minutes after trying to open the connection, so I also look for this condition, and try to create new connection after several minutes of inactivity.

Best regards,
Nikita

2013/1/18 Zoltán Baranyi <blaz...@gmail.com>

--

eppie

unread,
Apr 3, 2013, 6:02:04 AM4/3/13
to java...@googlegroups.com
I have the same problems with some tc65i's. I also dettach from GPRS now and testing this change. Hopefully this helps. :(

Op vrijdag 18 januari 2013 11:21:18 UTC+1 schreef Zoltán Baranyi het volgende:
Reply all
Reply to author
Forward
0 new messages