Archive for March, 2008

The Siemens TC65 modem’s version 3.0 firmware came out not long ago. This version has a number of very interesting improvements compared to its predecessor version 2.0 (there was also an intermediate version 2.8 but it didn’t last long).

In the new Siemens TC65 gprs modem’s version 3.0 firmware, the main thing is that it has Java classes to implement watchdog and control GPIOs. The TC65 remains the same, there aren’t any hardware changes which means you can update the module’s firmware from version 2.0 to version 3.0 but be careful because the change is irreversible.

Watchdog-siemens-tc65

Out of all of the new version’s main features, today we will look at how to use the one that’s most interesting to me, which is Java’s Watchdog class. The module has watchdog hardware, but with this new version 3.0 Siemens provides the necessary Java classes to control it.

The first thing that we have to do is activate it with the command AT^SCFG. If you use the command AT^SCFG you will see a new watchdog user option appears which is deactivated by default. We will be able to configure watchdog as disabled but enabled for rebooting i.e. if it appears it will restart the module (if autostart is 1, our application will restart) or enabled for shutdown. So if watchdog appears the modem will be turned off.

Then we will only have to import the Watchdog class into the software at the beginning of the program:

import com.siemens.icm.misc.Watchdog;

We will activate the start of the watchdog program using a static class in the following way:

Watchdog.start(15);

We activate the system with this so that if it’s not refreshed in 15 seconds, Watchdog does it. We can configure watchdog so that it’s deactivated (value 0) or activated where you can set a value between 10 and 300 or rather between 10 seconds and 5 minutes.

To refresh Watchdog simply put:

Watchdog.kick()

Put this at any strategic point in the program where it runs at least once during the configured Watchdog period.

Important Considerations 

  1. You can update the TC65’s version 2.0 to 3.0 but it’s irreversible.
  2. You must use a new SDK i.e. you have to use the new version of Eclipse, ME plug-in and SMTK. There’s no point using version 2.0.
  3. This applies to the TC65 module and TC65T Terminal as well as the (boxed) terminal modems that they mount e.g. the MTX65 distributed by Matrix can be updated to the new version 3.0.
  4. Although the TC65 now has Watchdog, there’s no excuse for the other programs to not continue doing well!!! :-)

Well I hope that you found this article interesting and it helped you. See you next time. ;-)  

Update: You can now update to version 3.0 on the TC65 module as well as the TC65T module.

 

Comments 41 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 »