8

I have a datacard ZTE MF190. I want to use AT commands to register in 2G or 3G and access internet via datacard. Found this article about how to make data call:

AT+cgatt=1
AT+CGDCONT=1,”IP”,”epc.tmobile.com” //I used my operator PDP context
AT+CGACT=1,1

But ping from OS terminal shows 100% package loss. I've tried on Ubuntu 14 and Windows 7.

How can I connect internet with AT commands using datacard on Ubuntu?

UPDATE

I gave bounty to @tripleee's answer because it's more full than first one and answered all my questions. But I'm not satisfied with answers, so I'll answer my own question in a week.

In my answer I'll show how to handle this process with Java. So, please do not move this question to other Stack Exchange websites.

LEQADA
  • 1,913
  • 3
  • 22
  • 41
  • Your device is made mainly for Russian market. You are better to ask on ru.SO :) Another issue is that it's rated at 7Mbps whereas modern devices can process up to 150Mbps – Oceinic Nov 01 '15 at 15:30
  • @Oceinic, I think it's not a modem problem. It works with dashboard. I tried to sniff USB port but on this case dashboard can not connect because of busy port. – LEQADA Nov 01 '15 at 15:42
  • Not a programming question. This should be migrated to https://superuser.com/ (or maybe https://serverfault.com/?) once the bounty closes. – tripleee Nov 03 '15 at 17:23

3 Answers3

2

Creating a connection between the card and your provider is not sufficient. You need some mechanism for creating a network interface out of this connection, and set up your network stack to route packets over this interface.

Traditionally, the pppd daemon has been a popular choice for this task. You would create a "chat script" with the commands for establishing a data call (these days, pppd might come packaged with a suitable canned script) and the daemon would handle the entire process of placing the call, authenticating, setting up a network interface over the circuit, and configuring the system to route packets over it, as well as configuring DNS etc to use it for resolver queries, etc.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • The last parts would probably be handled by DHCP once the interface is up. It's been a looooong time since I needed dialup. – tripleee Nov 03 '15 at 17:20
  • But how can I explain modem to connect 2G/3G/4G this way? – LEQADA Nov 04 '15 at 11:03
  • Quick googling suggests something like [AT+ZSNT=0,0,2](http://unlockmodemfree.biz/zte-modem-at-commands-to-enable-disable-virtual-cd-rom-and-more/) – tripleee Nov 04 '15 at 11:39
  • I googled about pppd. But not found how to connect with it. pppd help says that I need to use `connect` to connect seral line. But `pppd connect /dev/ttyUSB1` command has no response and no effect. How can I use pppd to connect serial port? – LEQADA Nov 08 '15 at 12:52
  • Try https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd for a general overview; most of it is not specific to Arch Linux, though you may need to make some adaptations for file locations etc. – tripleee Nov 08 '15 at 13:57
1

I tried to sniff USB port but on this case dashboard can not connect because of busy port

It is certainly possible. See this question

Found this article about how to make data call

What that article is about is how to set up the call, not how to make it. After you made correct setup, connect to internet with this command: ATD*99***1#

UPDATE1: After a bit of research I believe that article was written only to promote their software and has no practical use. In reality dialing is made with pppd or wvdial

UPDATE2: We discussed ways to solve the problem in a chat room (in Russian). It turned out cnetworkmanager will be the way to go

Community
  • 1
  • 1
Oceinic
  • 406
  • 4
  • 15
  • Anwer to `ATD*99***1#` is `CONNECT 7200000`. But ping shows 100% package loss. And OS cannot connect modem. – LEQADA Nov 01 '15 at 16:57
  • If I use pppd how can I explain modem to connect 2G/3G/4G...? – LEQADA Nov 04 '15 at 11:04
  • 1
    Since AT+ZSNT makes permanent changes you can run it manually in terminal. Another option is to add it into your chat scripts – Oceinic Nov 04 '15 at 14:15
  • I googled about pppd. But not found how to connect with it. pppd help says that I need to use `connect` to connect seral line. But `pppd connect /dev/ttyUSB1` command has no response and no effect. How can I use pppd to connect serial port? – LEQADA Nov 08 '15 at 13:08
0

As far as I know wvdial uses ppp daemon to connect to the internet using modem. wvdial is preinstalled on desktop version of Ubuntu.

wvdial uses a config file located /etc/wvdial.conf. Let's edit this file. Type in your terminal

sudo nano /etc/wvdial.conf

and you will see something like this

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Stupid Mode = yes
ISDN = 0
Modem Type = Analog Modem
New PPPD = yes
Phone = *99#
Modem = /dev/ttyUSB2
Username = ''
Password = ''
Baud = 9600
Dial Timeout = 30
Dial Attempts = 3

Explanation of all keys you can find in wvdial.conf(5) - Linux man page. If you need to change your provider dial number, username, password or any other information about connection and device you can change file content and save it.

There are 3 serial ports for ZTE MF190. Normally it's ttyUSB0, ttyUSB1 and ttyUSB2. And in my case ttyUSB2 is for internet connection. It would not work on other ports. So you need to find the right serial port for your modem.

There is an automatic configurator which edits wvdial.conf file, sets serial port baud rate etc. Since it is not always configure correctly I would not recommend to use it:

sudo wvdialconf /etc/wvdial.conf

It would be better if you configure wvdial manually.

Now, when your device connected and wvdial configured to work with device, you can execute this line from terminal:

wvdial

You will see a lot of lines. But if you see those lines - you have succeeded.

local  IP address XX.XX.XX.XX
remote IP address XX.XX.XX.XX
primary   DNS address XX.XX.XX.XX
secondary DNS address XX.XX.XX.XX

Now, how we can use it in programming? I'll provide some code to work with it on Java. You can use this code to dial.

public int dialer() { 
    // status for debug. If status == 4 then you connected successfully
    int status; 
    // create process of wvdial
    ProcessBuilder builder = new ProcessBuilder("wvdial");

    try {
        // start wvdial
        final Process process = builder.start();

        // wvdial listener thread
        final Thread ioThread = new Thread() {
            @Override
            public void run() {
                try {

                    final BufferedReader reader = new BufferedReader(
                            new InputStreamReader(process.getErrorStream()));
                    // wvdial output line
                    String line;

                    while ((line = reader.readLine()) != null) {
                        // if "local  IP address" line detected set status 1
                        if (line.contains("local  IP address")) {
                            status = 1;
                        }
                        if (line.contains("remote IP address")) {
                            status = 2;
                        }
                        if (line.contains("primary   DNS address")) {
                            status = 3;
                        }
                        if (line.contains("secondary DNS address")) {
                            status = 4;
                        }
                    }

                    reader.close();
                } catch (final Exception e) {
                }
            }
        };
        // start listener
        ioThread.start();
        // wait 6 secs and return status. Some kind of timeout
        Thread.sleep(6000);
    } catch (Exception e) {
    }
    return status;
}

And here is a disconnector method. All you need is to kill wvdial process and thread will be destroyed:

public boolean disconnect() { 

    ProcessBuilder builder = new ProcessBuilder("pkill", "wvdial");
    try {
        builder.start();
        return true;
    } catch (IOException e) {
        return false;
    }
}
LEQADA
  • 1,913
  • 3
  • 22
  • 41