Android Question Usb Gsm modem huawei e220

camolas

Member
Licensed User
Longtime User
Hi,

I cant send at commands to my usb gsm modem huawei e220 with all serial or and usbserial examples. If i use the code below in pyton/sl4a ( i connect to usb2 gsm = "/dev/ttyUSB2")
i can send and receive data, can you masters please help me on geting this work in b4a?

Thz

B4X:
#-*-coding:utf8;-*-
#qpy:console
#qpy:2

import os
import sys
import serial
import time
print'ok'

import android
droid = android.Android()

os.system("su -c chmod 777 /dev/ttyUSB*")

gsm = "/dev/ttyUSB2"
tries = 5

def GetAllSMS():
    retry = tries
    while retry > 1:
        try:
            print "### PI ON ###"
            ser = serial.Serial(gsm, 4800, timeout=1)
            ser.flushInput()
            ser.flushOutput()
            ser.write('ATZ\r\n')
            ser.read(100)
            ff = ser.read(100)
            print "1",ff
            time.sleep(1) 
            ser.write('AT\r/n')
            time.sleep(1)          
            ser.read(100)
            print "2",ser.read(100)
            ser.write('AT+CMGF=1\r\n')
            time.sleep(1) 
            ser.read(100)
            ser.write('AT+CMGL="ALL"\r\n')
            ser.read(16)
            data1 = ser.readlines()
            print data1
            ser.close()
            if data1:
                #print "4"
                result = data1
                #print "5", result
                for index, i in enumerate(result):                  
                    if i[:5] == "+CMGL":
                        data = result[index]
                        index = index + 1
                        text = result[index]
                        data = data + ',' + text
                        data = data.replace('\r\n','')
                        data = data.replace('"','')
                        data = data.replace('+CMGL: ','')
                        return data
                    else:
                        return "No SMS"
        except:
            print "Serial Port Not available READ SMS"
            print "Waiting 10 seconds"
            retry = retry - 1
            time.sleep(1)
               
while True:
    result = GetAllSMS()
    print result
   
    droid.makeToast(result)
    if result == 'No SMS':
        print result
    else:
        print result 
        result = result.split(',')
        print result
        print ".."
        if result:
            #responce = delmessage(result[0])
            command = result[6]
            print command
            print result[2]
            command = command.split(':')
            bb = "rrrrrr"
            print bb
            if command[0] == 'Stop':
                print" ############# STOP ON #################" 
                sendSMS(command[0],result[2])
            elif command[0]=="Celia":
                sendSMS(command[0],result[2])
                print " ############# STOP OFF #################"    
            elif command[0]=="Abre":
                sendSMS(command[0],result[2])
                print " ############# ABRE #################"
            elif command[0]=="Fecha":
                sendSMS(command[0],result[2])
                print " ############# Fecha #################"
            else:
                print "Junk"
 

Beja

Expert
Licensed User
Longtime User
Hi camolas,
I apologize because this is not an answer to your question.. but since you are working with this modem I wanted to ask if it has a GSM SIM card slot.. I searched and know it supports GSM but in the picture didn't see a slot to insert a SIM card.
Thanks.
 
Upvote 0

camolas

Member
Licensed User
Longtime User
Hi camolas,
I apologize because this is not an answer to your question.. but since you are working with this modem I wanted to ask if it has a GSM SIM card slot.. I searched and know it supports GSM but in the picture didn't see a slot to insert a SIM card.
Thanks.

Hi Beja,

Yes it has, if i can help you on any thing please let me know
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks camolas
I used wavecom GSM modem for long time and very comfortable using it through AT commands embedded into VB6 code.
It was about 120 Yuan (Chinese money) or $60.
What's the different between the two?
 
Upvote 0

camolas

Member
Licensed User
Longtime User
This is
Thanks camolas
I used wavecom GSM modem for long time and very comfortable using it through AT commands embedded into VB6 code.
It was about 120 Yuan (Chinese money) or $60.
What's the different between the two?
a

I dont have a wavecom to compare, mine is from internet mobile service, im using it because i have it in house... need to kill the boot install software and from that works like a normal serial gsm modem
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks camolas
Yesterday I ordered the Huawei E226.. I just want to be able to send SMS messages to cellphones and receive same. I hope it will work
 
Upvote 0
Top