Raspi 3 + Huawei 3531 = SMS server

16. Juli 2016 um 14:29 | Veröffentlicht in Hardware, Software | 3 Kommentare
Schlagwörter: , , , , , , ,

Pooh, quite some work to do, but now it seems to work…

The problem was simple: I have a Raspi 3, and a Huawei 3531 3G USB stick. The Raspi shall work as monitoring server running icinga2, and for emergency cases, it shall send SMS using the USB stick.

It turned out that this is highly complicated stuff, and that it is very difficult to find a solution. So I decided to get my „it’s running somehow solution“ published here. As I’m actually not a system administrator, although I got a bit of knowledge during the past 30 years, it is not clear to me yet, why the intended solution (with usb_modeswitch alone) does not work. However, this solution does work, and that’s what’s important to me 😉

What do we need?

  • Raspian Jessie
  • usb_modeswitch
  • cron
  • a Huawei 3531 USB Surf Stick

(I did not succeed to get things up and running with usb_modeswitch only!)

Be sure that there is NO pin set for the stick (plug it first on a Mac or Win machine and change that setting through the web interface of the stick)!

This solution should work if you get the following result when entering lsusb after you have plugged in the stick:

Bus 001 Device 004: ID 12d1:1f01 Huawei Technologies Co., Ltd.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

This tells us that the stick is in the default mode, which means that you have a wlan0interface in the list when you perform ifconfig.

To get access as SMS modem, we have to switch the stick into a different mode. This requires some magic. So, if you do not get exactly the same outputs, and do not have exactly that type of stick, it is highly probable that you won’t succeed.

The step-by-step solution:

  1. Create a shell script under /usr/local/sbin/huawei.sh. Do not forget to make it executable with chmod +x /usr/local/sbin/huawei.sh! You probably have to call the editor with sudo (e.g., sudo vi /usr/local/sbin/huawei.sh)
  2. Fill this code into that shell script:
    RESULT=`lsusb | grep -q 12d1:1001 && echo $?`
    echo "result: $RESULT"

    if [ "$RESULT" = "" ]
    then
    echo "Switching Huawei 3531 to modem mode..."
       sudo /usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'
    fi

    if [ "$RESULT" = "0" ]
    then
       echo "Huawei 3531 already switched to modem mode."
    fi

    if [ "RESULT" = "1" ]
    then
       echo "Switching Huawei 3531 to modem mode..."
       sudo /usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000011062000000100000000000000000000'
    fi

    This is the cron-script we will periodically execute, and that performs the switch to the modem mode of the stick.

  3. Call the crontab editor with sudo crontab -e.

  4. Add this line to the crontab and save it:
    * * * * * /usr/local/sbin/huawei.sh

    This checks every minute if the stick is in the right mode. If not, it switches the stick by calling the above script.

  5. Install usb_modeswitch:
    sudo apt-get install usb-modeswitch
  6. Ensure that the settings in /etc/usb_modeswitch.confare set this way:
    #DisableSwitching=0
    EnableLogging=1
    #SetStorageDelay=4

  7. In /etc/usb_modeswitch.dcreate a file name 12d1:1f01.
  8. Put this into that file:
    # Huawei E3531
    TargetVendor=0x12d1

    TargetProduct=0x1001
    MessageContent="55534243123456780000000000000011062000000100000000000000000000"
    NoDriverLoading=1

    Actually, this should be sufficient to make the stick switch, but it wasn’t. That’s the reason why we use the cronjob.

When entering lsusbafter a reboot, latest after a minute this should be the result:

Bus 001 Device 005: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Now, you can install gammu from  http://de.wammu.eu/smsd/ and configure it (see below). This is a SMS server daemon, which you can use to send messages pretty easily:

echo "test" | sudo gammu-smsd-inject TEXT "+49<your mobile number>"

After a few seconds, you should receive the SMS on your mobile device.

The configuration is quite easy to perform, just edit /etc/gammu-smsdrc and set these values (the pin entry is required even if the stick has none active):

# Configuration file for Gammu SMS Daemon
# Gammu library configuration, see gammurc(5)

[gammu]
# Please configure this!
port = /dev/ttyUSB0
connection = at

# Debugging
logformat = textalldate

# SMSD configuration, see gammu-smsdrc(5)
[smsd]
pin = 0000
service = files
# logfile = syslog
logfile = /var/log/gammu-smsd
# Increase for debugging information
debuglevel = 4
ReceiveFrequency = 60
# Paths where messages are stored
inboxpath = /var/spool/gammu/inbox/
outboxpath = /var/spool/gammu/outbox/
sentsmspath = /var/spool/gammu/sent/
errorsmspath = /var/spool/gammu/error/

3 Kommentare »

RSS feed for comments on this post. TrackBack URI

  1. Huawei stopped supporting old serialport AT commands for reading out received SMS (Send SMS with AT Comms works, receive does not work). Better to switch to the REST based communication protocols more or less explained here: https://stackoverflow.com/questions/38016641. Good luck

  2. Hello,

    i use a HUAWEI E3531 too.

    With modeswitch the E3531 is in modemmode. I can send SMS with gammu, but i can’t receive SMS.

    Can you receive SMS with the E3531?

    Thank in advance!

    Best regards
    Pascal

    • Hi Pascal,

      as far as I remember, I did not check that, as I did not need it. So I can’t answer your question, unfortunately.

      Best regards
      Hardy


Hinterlasse einen Kommentar

Erstelle kostenlos eine Website oder ein Blog auf WordPress.com.
Entries und Kommentare feeds.