EHS6 - Problem HTTP request. ATCommand class instance is not in transparent data **** | Telit Cinterion IoT Developer Community
April 7, 2021 - 4:40pm, 898 views
Hello:
I try to read a web file, but the ATCommand of the cinterion always gives me the error
java.io.IOException: ATCommand class instance is not in transparent data mode
I had the same code in previous modules and it worked correctly. I leave you an example code to see if you could guide me. Thank you.
package ehs6comat;
import com.cinterion.io.ATCommand;
public class ControlerAT {
private static ControlerAT controlador = null;
private static ATCommand atc;
public static boolean confirmacionLectura = false;
private ControlerAT() {
try {
atc = new ATCommand(false);
atc.addListener(new ListenerAT());
} catch (IllegalStateException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static ControlerAT getInstance() {
if (controlador == null) {
controlador = new ControlerAT();
}
return controlador;
}
public boolean inicializarPerfilServicioHttp(int servicio, String direccion) {
try {
sendAT("AT^SISS=" + servicio + ",srvType,http");
sendAT("AT^SISS=" + servicio + ",conId,0");
sendAT("AT^SISS=" + servicio + ",address," + direccion);
sendAT("AT^SISS=" + servicio + ",cmd,get");
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
}
//TODO: Return con estado;
return true;
}
public String sendAT(String str) {
synchronized (atc) {
try {
System.out.println("COMANDO :" + str);
str = atc.send(str + "\r".toUpperCase());
} catch (Exception e) {
e.printStackTrace();
}
}
return str;
}
public void inicializarPerfilConexion(String apn, String user, String password) {
try {
sendAT("AT^SICS=0,conType,GPRS0");
sendAT("AT^SICS=0,inactTO,10");
sendAT("AT^SICS=0,user," + user);
sendAT("AT^SICS=0,passwd," + password);
sendAT("AT^SICS=0,apn," + apn);
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public byte[] leerSocket(int idSocket) {
synchronized (atc) {
byte[] buffer = new byte[0];
try {
atc.send("AT^SISR=" + idSocket + ",1500" + "\r".toUpperCase());
atc.setDTR(true);
buffer = new byte[atc.getDataInputStream().available()];
//atc.getDataInputStream().read(buffer, 0, buffer.length);
atc.getDataInputStream().read(buffer);
} catch (Exception e) {
e.printStackTrace();
}
return buffer;
}
}
public boolean cerrarSocket(int idSocket) {
sendAT("AT^SISC=" + idSocket);
return true;
}
public boolean abrirSocket(int idSocket) {
sendAT("AT^SISO=" + idSocket);
return true;
}
}
package ehs6comat;
import com.cinterion.io.ATCommandListener;
public class ListenerAT implements ATCommandListener {
public void ATEvent(String arg0) {
arg0 = arg0.trim();
if (arg0.indexOf("^SISR:") != -1) {
try {
byte[] respuesta = ControlerAT.getInstance().leerSocket(0);
ControlerAT.getInstance().cerrarSocket(0);
String version = new String(respuesta).trim().toUpperCase();
System.out.println("VERSION: " + version);
} catch (Exception e) {
}
}
}
public void RINGChanged(boolean bln) {
}
public void DCDChanged(boolean bln) {
}
public void DSRChanged(boolean bln) {
}
public void CONNChanged(boolean bln) {
}
}
package ehs6comat;
import javax.microedition.midlet.*;
public class IMlet extends MIDlet {
public void startApp() {
ControlerAT at = ControlerAT.getInstance();
at.inicializarPerfilConexion("m2m.movistar.es", "MOVISTAR", "MOVISTAR");
at.inicializarPerfilServicioHttp(0, "http://pruebas:8081/VERSION.VER");
at.abrirSocket(0);
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
======
Never mind. We found solution.
We read from response of atc.send and dont open any stream
Thanks
Hello,
The exception is thrown probably on attempt to open streams while the instance is not in the data mode. It could be switched on with AT^SIST command.
Apart from that using Java APIs would be more recommended for network connections inside the MIDlet than AT commands.
Regards,
Bartłomiej
Hí.
I would really prefer to use Java to manage the connections, but a provider asks us to recover the connections (broken socket) as soon as possible, and we have only seen it possible by managing the connections with AT commands
Regards