Archive for the “Telefonía” Category

Some time ago I posted about how to do an OTAP with a Siemens modem (a TC65, XT65, TC65T, MTX65 or MTX65+G GPRS modem). In that post I wrote in detail about how to perform the OTAP from the HyperTerminal but I didn’t write a clear example of how to perform the OTAP with an SMS, some of you have already mentioned this to me.

So today I am going to write a small, very practical post about how to start an OTAP process with an SMS. There are various ways of approaching the process. I am going to outline the simplest way so that everyone that does the following steps will be able to do them without any problems.

otap-tc65.gif

Let’s propose that we have OTAP data saved on the modem before sending an SMS. You could send the data with SMSs but for convenience let’s imagine that they were saved in the modem’s configuration beforehand.

To do this let’s write (notice the quotation marks):

AT^SJOTAP=”blogElectronica”,”http://www.blogelectronica.com/TEMP/
HelloWorld.jad”,”a:”,,,”gprs”,”airtelnet.es”,”vodafone”,”vodafone”,”080.058.000.033″,

If we turn the modem off and turn it back on can we see that this information isn’t volatile with the command AT^SJOTAP?

Well after having done this t he modem is ready. Now we can send an SMS message to the modem to start the OTAP process. As I am poor and at home I only have a modem (that’s borrowed) so I will send the SMS from the modem itself.

To do this, I configure SMS text messages (yes text not PDU) ;)

at+cmgf=1
OK

Let’s configure the SMS parameters:

at+csmp=17,167,0,245
OK

And with all this we only have to send an SMS message with the text:

OTAP_IMPNG
PWD:blogElectronica
START:install

 

Obviously we aren’t going to send this message as such. We will convert it to hexadecimal, just as we would on an 8-bit PDU code. We will substitute each character by its corresponding hexadecimal value (O=4F, T=54, A=41, P=50 etc. Remember that the end of each line has to end in 0A including the last line).

For the slackers I’ve put a little program here that I just made to encode the SMS text to hexadecimal properly. I have also included the project with the source code, made in Visual Basic 6.0 for those who want to use, copy or browse it.

Conversor texto hexadecimal

As you can see this small program’s source code is very simple-minded:

sting = “”
hexValue = “”
For i = 1 To Len(Text1.Text)
hexValue = Hex(Asc(Mid(Text1.Text, i, 1)))
If Len(hexValue) = 1 Then hexValue = “0″ & hexValue
string = string & hexValue
Next i
If hexValue <> “0A” Then string = string & “0A”
string = Replace(string, “0D”, “”)
Text2.Text = string

So once you have done this you can send an SMS to the modem. To do this send the command at+cmgs (you already know that first you send at+cmgs = telephone number and we press ENTER, then past the long hexadecimal string that we got from using the small program that I made and press CTRL+ z and the SMS will be sent instantly.

at+cmgs=66627xxxx

>4F5441505F494D504E470A5057443A626C6F67456C656374726F6E69
63610A53544152543A696E7374616C6C0A

After a few seconds have passed you will see the modem’s LED start to blink differently, indicating the OTAP is working. When the process is finished the modem resets itself and you can see how to load HelloWorld.jar and .jad files onto the modem with MES.

I hope that this has been interesting, see you next time. ;)

Comments 13 Comments »

As I said yesterday, today I’m going to present a new product that Matrix is going to distribute soon. It’s a firmware, only 7 Euros, for the MTX65 GPRS modem that we have already talked about (and of course we are going to keep talking about) in this blog. This firmware + the MTX65 GPRS modem are called MTX-Tunnel.

Basically MTX-Tunnel is a GPRS-serial gateway designed for remote maintenance application this means that you can avoid moving by simply connecting an RS232 serial cable to a device. It’s also designed to provide a GPRS connection to those devices that only have an RS232 serial port (e.g. meters, temperature sensors etc.).

There are other solutions, I’ve already told you about some on here like some Digi routers but the MTX-Tunnel has certain advantages in both performance and price that I will tell you about soon.

MTX-tunnel

To be honest I have to say that this device is special to me, as I have quite involved with the firmware that goes inside the MTX65 and altogether they make the MTX-Tunnel.

That said, for those of you who are interested I’ll put more information on here like I usually do. You already know the question/answer routine.

What is the MTX-Tunnel device used for? 

The MTX-Tunnel is basically a GPRS-serial gateway that allows you to connect to an office with any device that has an RS232 serial port without moving via GPRS. You could do the same thing connecting an RS232 serial cable to the device; you can do it remotely via GPRS with MTX-Tunnel.

Is it complicated to set up?

In all, it is very simple. Basically you have to edit a file with notepad to configure certain parameters (IP, port, baud rate etc.). Once configured, simply drag the file inside the modem as if it were a pen drive. The MTX-Tunnel is then configured.

How does it work? Is it the MTX-Tunnel who connects to the central server in the office via GPRS or does it wait for incoming connections? In other words, does it act as a TCP/IP client or server?

It can be configured to work in two ways.

If MTX-Tunnel is configured to work in client mode, when you power it up it automatically connects to a server i.e. to a certain IP and port (specified in the configuration file). Once the connection is established with the server, all the data that comes from the server through the TCP/IP socket via GPRS is sent out through the serial port and vice versa. All of the data that enters through the serial port is sent towards the server through the socket via GPRS.

In server mode the MTX-Tunnel is connected to the GPRS and is stays listening through a certain port waiting to receive an external connection. Upon receiving the connection it behaves the same as in the previous case. When it comes via GPRS it is sent out through the RS232 serial port and vice versa.

Does MTX-Tunnel have to have a SIM card with a fixed IP address in client mode? 

No, not in this mode seeing as the MTX-Tunnel initiates the connection you don’t need to have a fixed IP. The server that is connects to has to have a fixed IP address, if it doesn’t you need to get an office router with DynDNS so that a DNS type yourOffice.yourDomain can tell you your company’s IP address.

And if it’s in server mode does it have to have a fixed IP address? 

It’s recommended but it’s not essential. If you have a SIM card with a fixed IP address it’s very quick to make a connection. If you don’t the IP you should work out the IP address assigned by the operator (Movistar, Vodafone etc.) to MTX-Tunnel when it connects to the GPRS.

And how do you find out the IP address that has been assigned to MTX-Tunnel by the operator? 

There are two ways. You can make a missed call or send an SMS to MTX-Tunnel. If MTX-Tunnel is configured to do this (indicated in the configuration file), the MTX-Tunnel will return an SMS to the phone number that sent the SMS or made the missed call, the SMS will contain the IP address that has been assigned by the operator.

So anyone who accidentally makes a missed call can get the device’s IP? 

No. In the MTX-Tunnel’s configuration file you can set up to ten valid phone numbers which can request actions like sending the IP address. If the telephone isn’t valid the MTX-Tunnel doesn’t do anything.

Does the MTX-Tunnel have to be permanently connected to GPRS? 

It depends. In client mode yes, the connection is permanent. As soon as the device has power it is connected to a specific IP address and port as I said before. If communication is lost for any reason, the MTX-Tunnel keeps trying to reconnect (every 30 seconds) until it is connected.

In server mode you do not need to be permanently connected to GPRS. If we want to be connected to GPRS at any point, all we need to do is make a missed call or send an SMS with the word “on”. Then you will be connected to GPRS and as I said in point 6, if configured to do so it will send an SMS with the IP address assigned by the operator.

And if MTX-Tunnel is in server mode and you don’t want the connection to be permanent, once you remotely activate the GPRS connection with the missed call or SMS, how do you disconnect from the GPRS connection? 

You can define a time out in the configuration file. Let’s suppose that you set it to 3 minutes. If the MTX-Tunnel doesn’t detect GPRS traffic after 3 minutes it will automatically disconnect from the GPRS network.

And if MTX-Tunnel works in server mode can you connect to any IP? I.e. can intruders connect to my devices? 

No. It’s the same with the telephone numbers. You can set up to 10 IPs that you can connect to in the configuration file. Any other attempted connection with an unauthorized IP is aborted.

But I already have a private VPN network i.e. I’m not going to have any unauthorized access to MTX-Tunnel. Do you need to specify authorized IP addresses like you said in the previous section? 

It’s not necessary. If you specify an authorized IP as 0.0.0.0 you can connect to MTX-Tunnel from any IP address. Remember that this option is only recommended for VPN networks in order to avoid any unauthorized access.

Can you configure the MTX-Tunnel’s serial port parameters?

Of course. You can change the baud rate, flow control, data bits and stop bits. As always you can do all this through the configuration file.

Let’s imagine that we have 100 temperature sensors which are all the same, without any intelligence and all using 100 MTX-Tunnels in client mode i.e. all 100 are permanently GPRS connected to a server. If the MTX-Tunnels don’t have a fixed IP address, how do I know which temperature probe corresponds to which temperature that the server receives? 

MTX-Tunnel has a configurable identification parameter that allows you to set which is sent to the server first once the connection is established. With this you always know which device corresponds to which data in cases like I mentioned where devices work in client mode and don’t have a fixed IP address to send identification.

Will I have a problem with any up to date application that I use with a serial cable if I substitute it for an MTX-Tunnel? 

Usually not, but there is one thing that you should keep in mind. That is that GPRS communications are quick but they have a bit of a delay (just as it’s not the same to work with a LAN via the internet). Let me explain. If you have a question-answer application (a typical example of a PC questioning a temperature sensor), you have to take into account the time from when you send the command from via GPRS to when you receive the answer with the sensor’s data. This obviously will take more time than if you used a cable. It’s the only things that you have to keep in mind so that you can modify the timeout.

There’s more information on Matrix: gsmsupport@matrix.es / telephone 915602737

I hope that you found it interesting. See you next time, have a good weekend. ;)

Tags: , ,

Comments 54 Comments »

In my last post we saw how to use a file system to store and retrieve information in some of the Siemens modems. I think that it was quite interesting. This time we will look at something that I think is even more interesting and the truth is that there aren’t many examples out there (I haven’t found any). Therefore I think this post will be widely read.

Let’s look at how to make a TCP/IP connection from an embedded Java program in a Siemens modem. You will see how to send data through a socket and how to receive data through it from a server. I’ve used an MTX65 GPRS modem even though the example would work the same if I used an MTX+G GPRS modem in a Siemens TC65 or a Siemens XT65 (distributed by Matrix in Spain).

modem-gprs

What server can we connect to for testing? 

Well as I do regularly, I use the Google server’s IP to do tests. What you see in the Java program below is how to make a TCP/IP connection to a server with the IP address 216.239.59.147 and port 80 (HTTP port). In this program, as well as making a TCP/IP connection, once the connection is established (asked on the homepage) data is sent to the server through the socket and data (HTML data) is also received at the socket too. It’s very simple but I think that it illustrates the mechanics well and it could be useful for you at some point.

Below you have an example of a program. I’ve written enough comments so that you can follow it easily but let me know if you want to get in contact with me. So there you go, I’ve made you a cable. ;)

package src;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.siemens.icm.io.ATCommand;
import com.siemens.icm.io.ATCommandFailedException;
import com.siemens.icm.io.ATCommandListener;

public class Connection extends MIDlet
{

ATCommand ATC;
ATCommandListener LIS;
int dataReceived=0;

//Class constructor
public Connection()
{
//We initiate the ATCommand class and the Listener
try
{
LIS = new ATListener();
ATC=new ATCommand(false);
ATC.addListener(LIS);
}
catch (IllegalStateException e){e.printStackTrace();}
catch (ATCommandFailedException e) {e.printStackTrace();}

//We initiate the TCP connection
initiateConnection();

}

//We definte the ATListener class
class ATListener implements ATCommandListener
{
//We will only control one URC in this example
//and it will be to know what we receive data
public void ATEvent(String Event)
{
//We remove the event that occurred:
System.out.println(“Event: “+ Event);

//If the URC corresponds with the data that has come …
if (Event.indexOf(“SISR”)>0)
{
//We send data from the socket to read
System.out.println(“Read TCP data”);
readSocket();
}
}
public void RINGChanged(boolean Event) {}
public void DCDChanged(boolean Event) {}
public void DSRChanged(boolean Event) {}
public void CONNChanged(boolean Event) {}
}

protected void startApp() throws MIDletStateChangeException {}

protected void pauseApp() {}

protected void destroyApp(boolean arg0) throws
MIDletStateChangeException {}

//Method for connecting to remote server
public void initiateConnection()
{
//Connect to Google
IPaddress string = “216.239.59.147″;
Port string = “80″;
R string=”";

System.out.println(“Initiating GPRS connection sequence”);

try
{
r=ATC.send(“AT^SICS=1,conType,GPRS0\r”);
Thread.sleep(100);

r=ATC.send(“at^sics=1,user,CLIENTE\r”);
Thread.sleep(100);

r=ATC.send(“at^sics=1,passwd,AMENA\r”);
Thread.sleep(100);

r=ATC.send(“at^sics=1,apn,internet\r”);
Thread.sleep(100);

r=ATC.send(“AT^SICI=1\r”);
Thread.sleep(100);

r=ATC.send(“AT^SISS=1,srvType,socket\r”);
Thread.sleep(100);

r=ATC.send(“AT^SISS=1,conId,1\r”);
Thread.sleep(100);

r=ATC.send(“AT^SISS=1,address,socktcp://” + IPaddress + “:” + port + “\r”);
Thread.sleep(100);

r=ATC.send(“AT^SISO=1\r”);
System.out.println(r);
Thread.sleep(3000);

System.out.println(“Sending data …”);

//We send a request to Google’s homepage
writeSocket(“GET / HTTP/1.1\r\n\r\n”);
System.out.println(“Data sent”);

//We keep waiting for something to be received via TCP
System.out.println(“Waiting to receive a TCP data package…”);
while (receivedData==0);

//Close the socket
r=ATC.send(“AT^SISC=1\r”);
Thread.sleep(100);

//Stop the program
notifyDestroyed();

}
catch (Exception e){System.out.println(“Error.”);}
}

//Method for reading data from the socket
public void readSocket()
{
try
{
//We send the AT command to read whatever there is in the socket..
ATC.send(“AT^SISR=1,1500\r”);
Thread.sleep(1000);

//We associate the input data stream
InputStream is = ATC.getDataInputStream();
//If there is data available we read it …
if (is.available() > -1)
{
//We create a buffer that is the size of the data received
byte[] buffer = new byte[is.available()];
//We read the data and load it into the buffer
is.read(buffer, 0, is.available());
//We show the data through the standard output …
System.out.println(new String(buffer));
//We activate the flag so that we are not still waiting
receivedData=1;
}

//Managing exceptions
} catch (IllegalStateException e) {e.printStackTrace();
} catch (IllegalArgumentException e) {e.printStackTrace();
} catch (ATCommandFailedException e) {e.printStackTrace();
} catch (InterruptedException e) {e.printStackTrace();
} catch (IOException e) {e.printStackTrace();}

}

//Method for writing data in the socket
public void writeSocket(String)
{
OutputStream os;

try
{
System.out.println(“Sent: ” + string);
//We associate the output stream to the ATCommand class
os = ATC.getDataOutputStream();
//We send the sending command AT^SISW
ATC.send(“AT^SISW=1,” + string.length() + “,0,0\r”);
Thread.sleep(500);
//We write the data through the socket
os.write(string.getBytes());
Thread.sleep(500);
}
//Managing exceptions
catch (IOException e) {e.printStackTrace();}
catch (IllegalStateException e) {e.printStackTrace();}
catch (IllegalArgumentException e) {e.printStackTrace();}
catch (ATCommandFailedException e) {e.printStackTrace();}
catch (InterruptedException e) {e.printStackTrace();}

}

}

Well I hope that you liked it and it will be useful for you at some point. See you next time ;)  

Comments 149 Comments »