ibwev
Posts: 28
Joined: Fri Jun 17, 2016 2:00 am

GSM Send Text Fail

Tue Nov 29, 2016 5:12 am

I am trying to send a text using a-gsm shield with Raspberry Pi 3. I am using sample python code that came with the GSM to attempt to send the text and am receiving the following error:

Code: Select all

^CTraceback (most recent call last):
  File "./sendSMS.py", line 96, in <module>
    res = sendSMS(destinationNumber, "129", message)#domestic format numbers
  File "/home/wvandiver/gsm/RPI_examples/a-gsm-RPI-examples-py-library-based-v1_                                                                                        2/agsm_SMS_Lib.py", line 36, in sendSMS
    res = recUARTdata(">","ERROR",12)
  File "/home/wvandiver/gsm/RPI_examples/a-gsm-RPI-examples-py-library-based-v1_                                                                                        2/agsm_Serial_Lib.py", line 88, in recUARTdata
    dt = agsm.read(tm)
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 447, in re                                                                                        ad
    ready,_,_ = select.select([self.fd],[],[], self._timeout)
I think the problem has something to do with "read = bytearray()" on line 444 in /usr/lib/python2.7/dist-packages/serial/serialposix.py. For some reason, "read" does not return a value when printed after calling bytearray().

Code: Select all

# select based implementation, proved to work on many systems
def read(self, size=1):
    """Read size bytes from the serial port. If a timeout is set it may
       return less characters as requested. With no timeout it will block
       until the requested number of bytes is read."""
    if not self._isOpen: raise portNotOpenError
    read = bytearray()
    print "Loosing it at bytearray: ",read  #read is an empty string
    while len(read) < size:
        ready,_,_ = select.select([self.fd],[],[], self._timeout)
        # If select was used with a timeout, and the timeout occurs, it
        # returns with empty lists -> thus abort read operation.
        # For timeout == 0 (non-blocking operation) also abort when there
        # is nothing to read.
        if not ready:
            break   # timeout
        buf = os.read(self.fd, size-len(read))
        # read should always return some data as select reported it was
        # ready to read when we get to this point.
        if not buf:
            # Disconnected devices, at least on Linux, show the
            # behavior that they are always ready to read immediately
            # but reading returns nothing.
            raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
        read.extend(buf)
    return bytes(read)
The following is a copy of the python code I am using to send a text message.

Code: Select all

############################################################################################################################################
#a-gsm-send-SMS.py v1.01/13 June 2016 - a-gsm 2.064 send SMS utility / demo
#COPYRIGHT (c) 2016 Dragos Iosub / R&D Software Solutions srl
#
#You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH a-gsm DEVICES USAGE. Modifications, derivates and redistribution
#of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms
#of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
#
#This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
#warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#Dragos Iosub, Bucharest 2016.
#http://itbrainpower.net
############################################################################################################################################
#HEALTH AND SAFETY WARNING!!!!!!!!!!!!!!!!!!!!
#High power audio (around 700mW RMS)! You can damage your years! Use it with care when headset is connected.
#We recomend to use AT+CLVL=20 (as maximum value), audio setup command in order to limit the output power.
#
# WARNING: WIRING the a-gsm-gsm board with u-controllers/boards(RPi) must be made with boards UNPOWERED!!
#
# LEGAL DISCLAIMER:
# Incorrect or faulty wiring and/or connection can damage your RPi and/or your a-gsm board!
# Following directives are provided "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY!
# Do the wiring on your own risk!
#
# References:
# http://itbrainpower.net/a-gsm/images/RaspberyPI_a-gsm_shield-wiring.png
# http://itbrainpower.net/a-gsm/downloadables/a-gsm_kickstart_v_0-90.pdf
# http://itbrainpower.net/a-gsm/gsm-shield-Arduino-RaspberryPI-features-code-examples.php
# http://itbrainpower.net/a-gsm/gsm-shield-Arduino-RaspberryPI-projects.php
############################################################################################################################################
# this utility must be runned as root (just use: sudo python yourPythonFileName.py)

message="Hi!\r\nThis message has been sent from the a-gsm v2.064 shield connected with my RPi board."
destinationNumber="1234567890"  #usually phone number with International prefix eg. +40 for Romania - in some networks you must use domestic numbers

usePoweringControl = 1  #change it to 0 if you do not want to control powerUP/powerDown the a-gsm board. In this case, please be sure the a-gsm board is powered UP(..see a-gsm_kickstart_v_x-yz.pdf) before run this utility

#Do not change under following line! Insteed make one copy of the file and play with!
#Hint: if you make changes of the code, before you run it run clear utility (erase the Python compiled *.pyc files)...
        ###erase .pyc files by         `find . -name '*.pyc' -delete`
############################################################################################################################################

import os
import serial
from time import sleep, time
from string import replace

from globalParVar import *
from agsm2_064_hw_control import *
from agsm_Serial_Lib import *
from agsm_Basic_Lib import *
from agsm_SMS_Lib import *

print "Light example - just send a SMS to a destination number"
sleep(1)

if not os.getuid() == 0:
    print("please use root privileges! try: \"sudo python yourPythonFileName.py\"")
    exit(0)

if destinationNumber=="":
    print("No destination number has been set for your SMS!")
    print("Edit the file and set the destinationNumber in line 35\r\n")
    exit(0)

# set SERIAL/USB communication section start
# bellow chose value bw [SER] Serial /dev/ttyAMA0 or [USB] /dev/ttyUSB0
# if module USB port maps to other port as /dev/ttyUSB1, just edit the moduleName_Serial_lib.py...
serialCommunicationVia = SERIALCON      # OVERRIDE the default value loaded from globalParVar.py. here I use via SERIAL communication
setSerialCom(serialCommunicationVia)    # set the current communication option
startSerialCom()                        # open serial communication bw. RPi and a-gsm shield
# set SERIAL/USB communication section end

# set HARDWARE CONTROL setup & POWER ON section start
if usePoweringControl==1:
    hwControlSetup()                    # setup the RPi I/O ports

sleep(2)#some delay...

if usePoweringControl==1:
    poweron()

sleep(1)
# set HARDWARE CONTROL setup & POWER ON section end

# set MODEM STARTUP SETUP section start
setupMODEM()
# set MODEM STARTUP SETUP section end


# MAIN PROGRAM section start
print "try to send a SMS...."

#check AT command pdf for proper 129/145 parameter/number format usage
res = sendSMS(destinationNumber, "129", message)#domestic format numbers
#res = sendSMS(destinationNumber, "145", message)#international format numbers
if res==0:
        print "SMS has been sent with succes"
# MAIN PROGRAM section end

# stop SERIAL COMMUNICATION section start
stopSerialCom()                             # close modem communication
# stop SERIAL COMMUNICATION section end

# HARDWARE CONTROL release & POWER OFF section start
if usePoweringControl==1:
    poweroff()                              #shutdown modem

if usePoweringControl==1:
    hwControlRelease()                      # free GPIO
# HARDWARE CONTROL release & POWER OFF section end


print("\r\n\r\nThat's all folks!\r\n")
Please help me understand why bytearray() is returning an empty string.

ibwev
Posts: 28
Joined: Fri Jun 17, 2016 2:00 am

Re: GSM Send Text Fail

Wed Nov 30, 2016 2:06 am

SOLVED

There is a discrepancy with the wiring schematic in the sample code http://itbrainpower.net/a-gsm/Raspberry ... code-a-gsm and the wiring schematic from the manufacturer http://itbrainpower.net/a-gsm/images/Ra ... wiring.png.
#name RPi a-gsm shield
#
#POWER a-gsm 16 D7 - power(UP/DOWN)
#RESET a-gsm 18 D6 - reset
#a-gsm STATUS 12 D5 - status
#
#serial TXD0 08 D4 - tx(rxd)
#serial RXD0 10 D3 - rx(txd)
#
#5V 02/04 5V - on Arduino power IN connector
#GND 06/14 GND - on Arduino power IN connector

a-gsm D2 goes to Pin 10 of the RPi
a-gsm D3 goes to Pin 8 of the RPi
a-gsm D4 should not be used for standard setup of RPi

Once the wires were switched and this tutorial viewtopic.php?f=28&t=165897&p=1069504#p1069504 was followed, I was able to send text.

User avatar
DragosIosub
Posts: 2
Joined: Wed Nov 30, 2016 8:23 am
Location: Bucharest, RO
Contact: Website

Re: GSM Send Text Fail

Wed Nov 30, 2016 8:44 am

Hi ibwev,

That mess was fixed in the a-gsm documentation in Dec. 2014 / Jan. 2015 (v1.03 of the presentation document). Please always check for the last version of itbrainpower.net gsm/3G/4G modems/shields documentation:
http://itbrainpower.net/downloads

Regards,

Dragos Iosub

Return to “Troubleshooting”