Fibocom Modem Connect Internet AT Command Sequence - command

I try to connect internet via AT commands with FIBOCOM modem. Sequence as follows. I got different techniques about it AT+COPS for example for carriers. But I guess I cannot go any further.
_serialPort.Write("AT\r");
Thread.Sleep(2000);
_serialPort.Write("ATZ\r");
Thread.Sleep(2000);
_serialPort.Write("ATE0+CMEE=1;+CREG=2\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CPIN?\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CSQ\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CREG?\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CSQ\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CMGF=0\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CIMI\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CGSN\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CPMS?\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CGDCONT=1,\"IP\",\"infoteks\",\"0.0.0.0\",0,0\r");
Thread.Sleep(2000);
_serialPort.Write("AT+CGQMIN=1,1,0,0,4,31\r");
Thread.Sleep(2000);
_serialPort.Write("ATD*99***1#\r");
Thread.Sleep(2000);
After this sequence done I got these report
CONNECT
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
~^Y}#A!}!}!} }8}....
NO CARRIER
What should I do?

COMMAND IS
AT+MIPCALL=1,"APN"/r
apn is acess point name if you give right name it will return ok
and after some time 20 sec max it will return connected ip address

Related

Jmeter - Force close a socket/wait until message recieved

I am opening a socket in jmeter (using groovy in JSR223 Sampler), and storing the message in a jmeter variable. This is the below code:
SocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("localhost"),4801);
def server = new ServerSocket()
server.bind(inetSocketAddress)
while(!vars.get("caseId"))) {
server.accept { socket ->
log.info('Someone is connected')
socket.withStreams { input, output ->
InputStreamReader isReader = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(isReader);
StringBuffer sb = new StringBuffer();
String str;
while((str = reader.readLine())!= null){
sb.append(str);
}
String finalStr = sb.toString()
String caseId = finalStr.split("<caseId>")[1].split("</caseId>")[0]
vars.put("caseId", caseId)
}
log.info("Connection processed")
}
}
if(vars.get("caseId"))
{
try
{
server.close();
vars.put("socketClose",true);
}
catch(Exception e)
{
log.info("Error in closing the socket: " + e.getMessage());
}
}
Now, there is some time delay between the first loop is executed and the message being recieved from the port. It doesnt receive the message immediately, and hence while loop is executed again. And then message is received and it sets caseId. It goes on to close the socket, because caseId is set. And that is throwing the error, because socket is still waiting for the message. So is there a way, to wait until socket has recieved all the messages, so i could properly close it?
Or just force close the socket, and Jmeter wont throw any exception?
Or when i execute next component, say IF controller in Jmeter, it waits until variable socketClose is set true? In that way, instead of while loops inside JSR223 sampler, i could use multiple If Controllers in Jmeter thread.
This is how ServerSocket.close() function works
public void close()
throws IOException
Closes this socket. Any thread currently blocked in accept() will throw a SocketException.
I don't think there is a way "to wait until socket has recieved all the messages" because Socket is dump as a rock and it can either listen for connections or shut down.
Maybe you might be interested in setSoTimeout() function?
Also this line:
vars.put("socketClose",true)
is very suspicious, I think you need to change it either to:
vars.put("socketClose", "true")
or to
vars.putObject("socketClose",true)
as JMeterVariables.put() function can accept only a String, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more details.

Command to re-calibrate magnetic sensor

Is there any command through which I can reset the magnetic sensor in an Android device?
I tried echo 1 > /sys/class/sensors/proximity_sensor/prox_cal as suggested here but it's not working.
Are these commands handset dependent?
I am trying this code:
Process process ;
try {
process = Runtime.getRuntime().exec("echo 1 > /sys/class/sensors/proximity_sensor/prox_cal");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
System.out.println("Executing ADB Command");
}
catch(IOException e)
{
System.out.println("Some error while executing ADB Command");
}
It's always going in the catch block. Can anyone help me on this?

Android socket client slow

I am trying to make a faster socket client to send RGB colors each time, the faster call should be from 1 to 10 times per second.
I am using this code:
try {
socket = new Socket("192.168.0.9",1234);
try {
dataOutputStream = new DataOutputStream(socket.getOutputStream());
//toServer = new BufferedWriter(new PrintWriter(socket.getOutputStream(),true));
//out = new PrintWriter(new BufferedWriter(
// new OutputStreamWriter(socket.getOutputStream())), false);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnknownHostException e1) {
Log.e("Error", "Error");
e1.printStackTrace();
} catch (IOException e1) {
Log.e("Error", "Error");
e1.printStackTrace();
}
And each time I am changing color from the picker, I am calling this method
dataOutputStream.writeUTF(";"+red+";"+green+";"+blue+";"+brightness+";");
I have tried a script in python that does the same, 100 times in 2 seconds and I dont have any lags.
What I am getting, is that the python server is waiting for new requests but Android takes time to send them through the socket connection.
I actually tried 3 different method to instance the output write, but only with the DataOutputStream is faster enough but still have some lag.
What is the best approach to fix this issue?
Put a BufferedOutputStream between the DataOutputStream and the socket, and flush the DOS after each writeUTF(). At the peer, use a DataInputStream over a BufferedInputStream.

Android App: Address Family not Supported by Protocol

I am trying to have my Android application sent Telnet commands over a small network to another device, and whenever I declare the DatagramSocket it throws a SocketException saying: Address Family not Supported by Protocol. Here is my code below:
try {
addr = InetAddress.getByName(ipAddress);
sock = new DatagramSocket(); //SocketException created here
//first message - cmd
length = cmd.length();
message = cmd.getBytes();
packet = new DatagramPacket(message, length, addr, portAddr);
sock.send(packet);
//second message - highCMD
length = highCMD.length();
message = highCMD.getBytes();
packet = new DatagramPacket(message, length, addr, portAddr);
sock.send(packet);
sock.close();
} catch (SocketException e) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(v.getContext()).create();
alertDialog.setTitle("Send High CMD Error!");
alertDialog.setMessage("SocketException");
alertDialog.show();
} catch (IOException e){
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(v.getContext()).create();
alertDialog.setTitle("Send High CMD Error!");
alertDialog.setMessage("IOException");
alertDialog.show();
}
}
Possible solutions I've considered but haven't made work:
Emulator needs port redirect through development machine, which ports to use?
I'm not using correct version of IP4/6, how is this set?
Device uses TCP protocol, maybe I'm using the wrong socket type?
Other Important Info:
I've only run this on an Emulator
Development Machine correctly sent telnet commands from Command Prompt
Network consists of development machine, router, and device.
UPDATE: 2/9/11
I've changed this code to the following, but I'm still getting an exception:
try {
addr = InetAddress.getByName(ipAddress);
socketAddress = new InetSocketAddress(addr, portAddr);
sock = new Socket();
sock.connect(socketAddress);
sock.close();
} catch (SocketException e) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(v.getContext()).create();
alertDialog.setTitle("Send High CMD Error!");
alertDialog.setMessage("SocketException" + e.getMessage());
alertDialog.show();
}
The message from the exception says "Permission Denied." Does this mean that my device is blocking the socket from connecting?
You've coded this the wrong way. Telnet uses TCP which uses stream (connection oriented) sockets, not the datagram sockets used by UDP.
Search for tcp examples.

Invalid attempt to call FieldCount when reader is closed

The error above occurs when I try to do a dataReader.Read on the data recieved from the database. I know there are two rows in there so it isnt because no data actually exists.
Could it be the CommandBehavior.CloseConnection, causing the problem? I was told you had to do this right after a ExecuteReader? Is this correct?
try
{
_connection.Open();
using (_connection)
{
SqlCommand command = new SqlCommand("SELECT * FROM Structure", _connection);
SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);
if (dataReader == null) return null;
var newData = new List<Structure>();
while (dataReader.Read())
{
var entity = new Structure
{
Id = (int)dataReader["StructureID"],
Path = (string)dataReader["Path"],
PathLevel = (string)dataReader["PathLevel"],
Description = (string)dataReader["Description"]
};
newData.Add(entity);
}
dataReader.Close();
return newData;
}
}
catch (SqlException ex)
{
AddError(new ErrorModel("An SqlException error has occured whilst trying to return descendants", ErrorHelper.ErrorTypes.Critical, ex));
return null;
}
catch (Exception ex)
{
AddError(new ErrorModel("An error has occured whilst trying to return descendants", ErrorHelper.ErrorTypes.Critical, ex));
return null;
}
finally
{
_connection.Close();
}
}
Thanks in advance for any help.
Clare
When you use the Using in C#, after the last } from the using, the Connection automatically close, thats why you get the fieldcount to be closed when u try to read him, as that is impossible, because u want those datas, read then before close the using, or u can open and close manually the connection, by not using the (using)
Your code, as displayed is fine. I've taken it into a test project, and it works. It's not immediately clear why you get this message with the code shown above. Here are some debugging tips/suggestions. I hope they're valuable for you.
Create a breakpoint on the while (dataReader.Read()). Before it enters its codeblock, enter this in your Immediate or Watch Window: dataReader.HasRows. That should evaluate to true.
While stopped on that Read(), open your Locals window to inspect all the properties of dataReader. Ensure that the FieldCount is what you expect from your SELECT statement.
When stepping into this Read() iteration, does a student object get created at all? What's the value of dataReader["StructureID"] and all others in the Immediate Window?
It's not the CommandBehavior.CloseConnection causing the problem. That simply tells the connection to also close itself when you close the datareader.
When I got that error, it happened to be a command timeout problem (I was reading some large binary data). As a first attempt, I increased the command timeout (not the connection timeout!) and the problem was solved.
Note: while attempting to find out the problem, I tried to listen to the (Sql)connection's StateChanged event, but it turned out that the connection never fall in a "broken" state.
Same problem here. Tested all the above solutions
increase command timeout
close the connection after read
Here's the code
1 objCmd.Connection.Open()
2 objCmd.CommandTimeout = 3000
3 Dim objReader As OleDbDataReader = objCmd.ExecuteReader()
4 repeater.DataSource = objReader
5 CType(repeater, Control).DataBind()
6 objReader.Close()
7 objCmd.Connection.Dispose()
Moreover, at line 4 objReader has Closed = False
I got this exception while using the VS.NET debugger and trying to examine some IQueryable results. Bad decision because the IQueryable resulted in a large table scan. Stopping and restarting the debugger and NOT trying to preview this particular IQueryable was the workaround.