Using AT Commands with the Huawei E303

/ Written By Reuben Balik

Many of our customers using the Huawei E303 want to move beyond the HiLink feature of the modems described in our other tutorials and gain more low-level control by using AT commands. This method is more complicated, but can allow you to programmatically send SMS or disconnect the radio.

This tutorial was created on the BeagleBone Black, but most of the steps will apply to any Linux system and there are some notes for Windows users at the end.

Switching the Huawei E303 into Serial Mode

Before sending any AT commands to the modem, you need to switch it from the default HiLink mode into serial mode. Follow these instructions to get to that point:

  1. Boot up your BeagleBone, SSH to it, and login.
  2. We need to disable USB mode switching so that the modem doesn’t get stuck in HiLink mode when we plug it in. To do this, edit the file /etc/usb_modeswitch.conf and set DisableSwitching to 1. Here’s what it should look like if you’re using the nano editor:modeswitch
  3. Save the file and reboot the board by typing reboot
  4. Plug in the USB modem and type lsusb. You should see a line in the output like this:
    Bus 001 Device 002: ID 12d1:1f01 Huawei Technologies Co., Ltd.
  5. The 12d1:1f01 indicates that the modem is in storage mode and we need to switch it to serial mode. To do that, type this command:
    usb_modeswitch -v 0x12d1 -p 0x1f01 -V 0x12d1 -P 0x1001 -M "55534243000000000000000000000611060000000000000000000000000000"

    To confirm that it worked, type lsusb again. The line should now show:

    Bus 001 Device 003: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem

    Note: Some users have reported that this only works with the -I flag on the command. If the modem doesn’t switch into 12d1:1001 mode, try rerunning the above command with -I.

  6. Now we need to connect to the modem . Type screen /dev/ttyUSB0. This will give you a blank screen session. Note that to disconnect and exit screen you need to type Ctrl+A and then k (There are many other utilities besides screen that will work for this as well, including minicom, but screen is included in the BeagleBone OS image.)
  7. To confirm that you’re actually talking to the modem, type AT . You should get an OK response. (If you can’t see what you’re typing, type ATE1 to turn echo on.)

Creating a PPP Session

Once you have access to send AT commands, you can use the Linux PPP daemon to establish an internet connection.

  1. Type the following commands exactly. You’ll want to wait for an “OK” response after each one so don’t copy and paste this whole block at once.
    ATH
    ATZ
    ATQ0
    AT+CGDCONT=1,"IP","apn.konekt.io"
    ATDT*99***1#
    

    If all goes well, your window should look like this:
    atcommands

  2. Exit the screen session by hitting Ctrl-A and then k (Say yes if it asks if you’re sure.)
  3. Now you can start up a PPP server with this command:
    pppd debug -detach noauth defaultroute /dev/ttyUSB0 9600 > ppp.log &
  4. You should now be online. Let’s try pinging an IP address to be sure:
    ping 8.8.8.8

Sending SMS

Using AT commands you can easily send an SMS message from your device. (Note that SMS may incur additional charges.)
Starting from your screen session connection to the modem:

  1. Send AT
  2. Switch into text SMS mode (easier than the other mode) by sending AT+CMGF=1
  3. Prepare the message by sending AT+CMGW="+<phone number>" The phone number includes the country code so to send an SMS to the US number 773-555-1234 you would send the command AT+CMGW="+17735551234". If it worked, you should get a > prompt.
  4. Type in your message at the prompt and hit Ctrl+Z to end the message.
  5. After you hit Ctrl+Z you should get a message back in the format +CMGW: X where X is a number. This number is needed in the next step.
  6. Send AT+CMSS=X where X was the number from the previous step.
  7. If all goes well you should get a +CMSS response followed by an OK. Your SMS should have sent!

Here’s a screenshot of a complete transaction:

SMS screenshot

Other useful Commands

There are tons of commands for controlling various aspects of the modem behavior. Here is just a small sample:

  • ATI gives some useful information about the modem
  • AT^U2DIAG=0 will force the modem into serial modem mode every time it’s plugged in. Use AT^U2DIAG=375 to get back into HiLink mode
  • AT+CFUN=7 will turn off the radio and AT+CFUN=1 will turn it back on

Notes on Windows

Connecting to the modem to send AT commands on Windows is a little more complicated. When the modem is connected and is in HiLink mode you can go to the URL http://192.168.1.1/html/switchProjectMode.html in any browser and the modem will switch into serial mode. However, this is only half of the solution. You need to install the Huawei Mobile Partner software and then you need to actually edit some of the driver files that it comes with in order to get Windows to mount the modem on a COM port. Instead of putting all of those instructions right here, there’s already a great tutorial for editing these files at another site.

Other Useful Links

I’d recommend the following links for more information on all of this. There is some great information out there on other useful AT commands and tips for automating and scripting the whole process.


I hope this was helpful. As always, leave any comments or questions down below or on our community forum. You can also view all of our additional tutorials here. Thanks!

Update 8/11/2015: Fixed a typo on the U2^DIAG command. 375 gets back to HiLink mode, not 376. Also added information about another version of the mode switch command.
Update 11/7/2016: Fixed a typo in the IP to use to switch modem mode on Windows.

  • Jean-Louis Bonnaffé

    Hi Reuben, very useful post, thanks.
    I’ve noticed ping 8.8.8.8 reports a 300~350ms delay, and I suppose the packet reaches apn.konekt.io before reaching the internet.
    Now, I’d like to send packets between two E303 devices with the lowest latency possible. In this case, can I send data directly over the cellular network, like when placing a phone call ?
    In this case, can I know my SIM card’s phone number beforehand, and how would the data be billed ?

    • Reuben Balik

      Hi Jean-Louis,
      I don’t think there would be any way to send data directly like that, but we’ll do some research and get back to you. You may want to post something on our community forum about this too as there may be some people out there who have done something like that.

  • Mark Lee

    Hi Reuben, that Huawei Mobile Partner software link you mentioned in Notes on WIndows is dead. The download is available from this page: http://m.huawei.com/enmobile/consumer/mobile-broadband/dongles/detail/e303-en.htm

    However, there’s a link on the original page that leads to “the Latest Drivers,Firmware and Software”, so it’s not all bad even though the message is “Sorry, No results were found”

  • Tom Cook

    Does anyone know of Huawei documentation on the AT command set for these modems?

    • Web Programmer

      May by this help you

  • Web Programmer

    Hi,
    I have a Huawei USB dongle and I need to change IMEI via one of these methods: [AT Command / Diagnostic mode / QCDM Command]
    I find a tool.exe to change it but I need to do it manually, also I run Serial Port Monitor to see what’s the tool is doing ? I capture codes in HEX in Diag mode

    Thanks all

    —————————————————-
    Found Applications port COM4
    Found Diagnostics port COM5

    Found modem : E303
    Model : Huawei E303
    IMEI : ****************
    Serial NR. : E9PBY*******
    Firmware : 22.157.79.02.37
    Compile date / time : Sep 5 2012 13:57:36
    Hardware ver. : CH2E303SM
    Dashboard version : HiLink12.012.02.03.37
    Web UI version : HiLink12.012.02.03.37
    Chipset : HiSilicon
    Voice feature : not supported in current firmware
    SIM Lock status : Locked (CardLock)
    Wrong codes entered : 0 (unlock attempts left : 10)

  • Md Idiake

    https://uploads.disquscdn.com/images/2100f3f3f243926a282e8d382bed1b44b7c515edd0d6bea736ae6949955b6f74.png
    Hi.

    I have this Huawei e3531 modem (pls, see attachment) that persistently boots up everytime in hilink mode.

    http://192.168.8.1/html/switchprojectmode.html does not switch it to modem mode- it rather provokes http error 404.

    I am running windows 10 professional. 64-bit.

    Your assistance would be much appreciated as I would like to interract with this modem by programmatically sending SMS.

    Expecting your quick response.

    Thanks.

    God Bless.

    • Reuben Balik

      Hi, I think that’s a typo. Should be http://192.168.1.1/html/switchprojectmode.html

      • Md Idiake

        Hi.

        If I use 192.168.1.1, it would not be able to access the modem. You can see it from the screen shot.

        Thanks.

        • Reuben Balik

          Oh, didn’t notice that. Interesting. I haven’t tested with that specific modem yet. The E303 always uses 192.168.1.1. I don’t think I have anymore information on that modem model.

          • Md Idiake

            Ok.

            Do I give you some time? How long?

            Thanks.

            MDi

          • Reuben Balik

            We don’t sell that modem and we’ve never tested it so I don’t know if we’ll be able to provide any information on it. If you want to try another modem, we sell them in our store at https://hologram.io/store/