Sunday, June 3, 2012

Huawei E220 and USSD

Huawei E220 modem when connected creates two devices:

- /dev/ttyUSB0
- /dev/ttyUSB1

In order to get an USSD message e.g balance check one shall execute:

# echo "AT+CUSD=1,*102#^M" > /dev/ttyUSB0; cat /dev/ttyUSB1

IMPORTANT: ^M (Carriage Return character) is typed as CTRL+v and CTRL+m

Let's create a one liner that gives back the balance check as a single line:

# echo "AT+CUSD=1,*102#,15^M" > /dev/ttyUSB0; for i in `seq 15`; \
 do read line; if echo $line | grep '+CUSD'; then break; fi ; done < /dev/ttyUSB1

I use this as an input content for my monthly SMS from my server to my mobile phone.