Socket open on Private APN | Telit Cinterion IoT Developer Community
October 2, 2018 - 8:26pm, 2491 views
Hello.
I'm currently using the BGS5T for a project. For communication, we're using gsm m2m cards to connect into a private APN. (I have tested the connection on public APNs and it works just fine)
Unfortunatly, I'm not managing to open the socket with it. Does the BGS5T support this? If so, how should I do this?
This is the error presented:
avax.microedition.io.ConnectionNotFoundException: error -121 in socket::open
- com.sun.midp.io.j2me.socket.Protocol.open0(), bci=0
- com.sun.midp.io.j2me.socket.Protocol.connect(), bci=101
- com.sun.midp.io.j2me.socket.Protocol.open(), bci=154
- com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
- com.sun.midp.io.j2me.http.Protocol.createConnection(), bci=31
- com.sun.midp.io.j2me.http.Protocol.connect(), bci=41
- com.sun.midp.io.j2me.http.Protocol.streamConnect(), bci=108
- com.sun.midp.io.j2me.http.Protocol.startRequest(), bci=7
- com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=33
- com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=3
- com.sun.midp.io.j2me.http.Protocol.getResponseCode(), bci=5
Thank you so much in advance
Hello,
The message for -121 error is 'Software caused connection abort'. The popular exception for problems with connection to APN would be IOException 'Profile could not be activated' - have you also seen it? Maybe there is a problem with signal quality - have you checked this? Or maybe there is a problem with this APN. You could try to test it with some other device for example. Is it the same SIM card tested with private and public APN? You can also add a listener to BearerControl class to debug the connection state changes, APN, IP, DNS etc.
Best regards,
Bartłomiej
Hello Bartlomiej.
Thank you for your answer.
I have tried in other modem from another brand and it did work.
Could you please provide an example of implementation of the BearerControl class to monitor the connection? I've been trying to find one, but haven't been successful.
Hello,
Here's an example how you could add a listener to com.cinterion.io.BearerControl:
BearerControl.addListenerEx(new BearerControlListenerEx() {
public void stateChanged(String APN, int state, int PdpErrCause) {
try {
println("APN: " + APN);
println("BEARER state change: " + translateBearerState(state));
if (state == BearerControlStates.BEARER_STATE_UP) {
println("BEARER ADDR: "
+ BearerControl.GetBearerV4Addr(APN));
println("BEARER DNS1: "
+ BearerControl.GetBearerV4Dns1(APN));
println("BEARER DNS2: "
+ BearerControl.GetBearerV4Dns2(APN));
}
} catch (IOException e) {
e.printStackTrace();
}
String[] list = BearerControl.GetBearerList();
if (list.length > 0) {
println("Active bearers list: ");
for (int i = 0; i < list.length; i++) {
println("Bearer: \"" + list[i] + "\", state: " + translateBearerState(BearerControl.GetBearerState(list[i])));
try {
println("Bearer: \"" + list[i] + "\", address: " + BearerControl.GetBearerV4Addr(list[i]));
} catch (IOException e) {
// e.printStackTrace();
println("N/A");
}
}
println("End of list.");
}
}
});
private String translateBearerState(int state) {
String stateString = "UNKNOWN";
if (BearerControlStates.BEARER_STATE_CLOSING == state) {
stateString = "BEARER_STATE_CLOSING";
}
if (BearerControlStates.BEARER_STATE_CONNECTING == state) {
stateString = "BEARER_STATE_CONNECTING";
}
if (BearerControlStates.BEARER_STATE_DOWN == state) {
stateString = "BEARER_STATE_DOWN";
}
if (BearerControlStates.BEARER_STATE_LIMITED_UP == state) {
stateString = "BEARER_STATE_LIMITED_UP";
}
if (BearerControlStates.BEARER_STATE_UNKNOWN == state) {
stateString = "BEARER_STATE_UNKNOWN";
}
if (BearerControlStates.BEARER_STATE_UP == state) {
stateString = "BEARER_STATE_UP";
}
return stateString;
}
Maybe the type of authentication is the problem (PAP/CHAP) you can configure it for a certain context that can be used by PPP or IP services over AT commands, but for Java it's always PAP. You might ask the operator about this.
Generally there should be no difference between private and public APN. If all the hardware and configuration is the same and other device is working with the same SIM and APN it should also work. Are you are sure that you have configured APN, user and password properly (maybe there are some special characters and it is some encoding issue) - how do you configure it - can you paste some code and log? Can you also check the firmware version with 'ATI1' command?
Please also test the network registration, signal quality etc. You could also try to check AT+CEER reply after the failure.
If none of the above helps it might be hard to debug this issue. To get more information you'd have to grab the traces from the module - then it could be possible to see what goes wrong. But this could only be done by internal tools, so you'd have to report it to the Gemalto support directly or via your distributor if possible.
Best regards,
Bartłomiej
Hello Bartlomiej.
Thank you so much for your answer.
Regarding the socket creation, I debbuged the whole thing only to find that the mistake was pretty basic. I was using the google DNS in the socket creation. As soon as I removed that parameter, the issue disappeared. Problem solved.
Regarding the BearerControl Listener, I have a question:
- Could this be used as a solution to monitor the communication and its "alive" state? I keep having some units that sometimes lose their communication for hours only recovering after a programmed reset.
Could I automate this process with the refered bearer (send an atcommand for reset) in any of the conditions that you provided?
Thank you once again.
Hello,
You can monitor the state of bearer used by your Java program. In normal conditions it should be brought up when some socket is being open and should be closed when last socket is closed down and the timeout goes by. So these states will probably not give you such condition. You can try to check PdpErrCause parameter of stateChanged() callback. Maybe there is some specific error cause in case of the problem that you describe. You can also try if calling BearerControl.hangUp() will not help instead of module reset.
Best regards,
Bartłomiej