Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

Lock module to single operator

Showcase, July 1, 2016 - 1:05pm, 2683 views

Description:

Sometimes you need to lock your module to single operator. An example would be when your module is located near country border and it could connect to foregin network, which would result you paying extra charges.

We can prevent this by using AT+COPS command: AT+COPS=<mode>[, <format>[, <opName>][, <AcT>]]
Response(s)

mode 0 - automatic

mode 1 - manual

mode 2 - derigster from network

mode 3-  set only format

mode 4 - manual/automatic, if manual selection fails, automatic mode (<mode>=0) is entered (<opName> field will be present).

For our example we will use mode 1(manual), format will be set to (1) which means short operator name(***. 8 characters), operator will be retrived from .txt file and last parameter is Act(radio access Technology) and is allways 0. You can read more about AT+COPS command in atc_ext documentation for your module.

Solution:

Here is example code for OperatorSelector class:

public class OperatorSelector
{
    JurGem jurGem = new JurGem();
    String OPERATOR_FILE = "operator";
   
    public void selectOperator()
    {
        try
        {
            if(jurGem.fileExists(OPERATOR_FILE))
            {
                String operator = jurGem.readFile(OPERATOR_FILE);
                jurGem.sendCommand("at+cops=1,1,\"" + operator + "\",0");
                System.out.println("Operator locked to: " + operator);
            }
        }catch(Exception ex)
        {
            System.out.println("Exception on selectOperator: " + ex);
            ex.printStackTrace();
        }
    }
}

Since I am using methods from jurGem which aren't part of Gemalto librarys, I am attaching those here:

public String sendCommand(String command)  //this one is acctualy one of Gemalto examples
    {
       try
            {
                m_Cmd = new ATCommand(true);
                 String answer = m_Cmd.send (command + "\r");
                 System.out.println("AT response " + answer);
                 //System.out.println("answer " + answer);
                 Thread.sleep (100); // Remember at least to implement 100 ms sleep in order to recevie any URC
                 m_Cmd.release();
                 return answer; //Return the AT command execution answer
                
             }
             catch (Exception e)
            { 
             // implemment the treatment for the exceptions in this block
                return "ERROR";
            }
    }

public boolean fileExists(String file) throws IOException
    {
        String filename_new = "file:///a:/" + file + ".txt" ; // mesto datoteke
        FileConnection fc;
        fc = (FileConnection) Connector.open(filename_new, Connector.READ_WRITE);
        if(fc.exists())
        {
            fc.close();
            return true;
        }
        fc.close();
        return false;
    }

public String readFile(String file) throws IOException
    {
        String filename_new = "file:///a:/" + file + ".txt";
        FileConnection fc;
        fc = (FileConnection) Connector.open(filename_new, Connector.READ_WRITE);
        DataInputStream dis;
        dis = fc.openDataInputStream();
        dis.mark((int) fc.fileSize());
        String content = "";
        while(dis.available() > 0)
        {
            int ch = dis.read();
            char msg = (char) ch;
            content = content + msg;
        }
        dis.close();
        fc.close();
        //System.out.println("settings : " + settings);
        return content; 
    }

So to use this functionality you just implement OperatorSelector class and call it with:

new OperatorSelector().selectOperator();

and if you have file operator.txt on your file it will read short operator name and set that network as default one. If there is no file on module's flash, then nothing will happen and module will automaticly register to network.

Author

Jure's picture
Jure