Utilizamos cookies propias y de terceros. [Más información sobre las cookies].
Política de cookies
Proyecto AjpdSoft

· Inicio
· Buscar
· Contactar
· Cookies
· Descargas
· Foros
· Historia
· Nosotros
· Temas
· Top 10
· Trucos
· Tutoriales
· Wiki

Linux: Cómo enviar SMS desde un equipo con sistema operativo Linux CentOS 6
Internet y comunicaciones


Tutorial donde mostramos paso a paso y con capturas de pantalla cómo conectar un módem GSM GPRS a un equipo con Linux CentOS y cómo enviar SMS desde Linux a móviles. Todo ello de forma gratuita salvo, obviamente, el coste del SMS y del dispositivo GSM.



Requisitos para enviar SMS a móviles desde equipo con Linux

Para poder enviar SMS en un equipo con Linux necesitaremos lo siguiente:

  • Un módem GSM GPRS. En nuestro caso usaremos un módem GSM Falcom SAMBA55 USB, compatible con Linux:

Requisitos para enviar SMS a móviles desde equipo con Linux

Insertaremos la tarjeta SIM en el módem GSM y conectaremos el módem GSM por USB al PC, como se muestra en la imagen:

Requisitos para enviar SMS a móviles desde equipo con Linux

 

Comprobar conexión módem GSM GPRS y detección desde Linux CentOS

Una vez conectado el módem GSM GPRS en el equipo Linux por USB, podremos ver si ha sido detectado correctamente ejecutando el comando Linux:

dmesg

El comando anterior nos devolverá los mensajes de diagnóstico del sistema. Revisando esta salida veremos que nos muestra unas líneas con "usb x-x: new USB device found, idVendor=xxx idProduct=xxx", esto querrá decir que Linux ha detectado correctamente el módem GSM GPRS USB. Anotaremos el idVendor y el ttyUSB que le haya asignado, en nuestro caso ttyUSB0 (remarcamos ambos valores en la imagen), pues los necesitaremos más adelante:

Comprobar conexión módem GSM GPRS y detección desde Linux CentOS

(consultar la salida completa del comando dmesg)

Si el módem GSM no ha sido detectado por Linux tendremos que seguir las instrucciones del fabricante para instalar el driver apropiado. Obviamente el módem GSM debe ser compatible con Linux, de lo contrario no funcionará.

Continuando con la verificación de que el módem GSM ha sido correctamente detectado ejecutaremos el siguiente comando:

lsusb

Donde podremos ver el número de bus asignado al dispositivo por Linux CentOS, con el ID devuelto en en comando dmesg anterior en idVendor:

Comprobar conexión módem GSM GPRS y detección desde Linux CentOS

(consultar la salida completa del comando lsusb)

Por lo tanto sabremos con el comando anterior que nuestro módem GSM ha sido asignado al bus USB del equipo Linux 0002/003. Para consultar toda la información del bus asignado al módem ejecutaremos el siguiente comando:

lsusb -D /dev/bus/usb/002/003

Comprobar conexión módem GSM GPRS y detección desde Linux CentOS

 

Instalar y configurar paquete gratuito SMSTOOLS SMS Server Tools en Linux CentOS para envío de SMS

Para instalar el paquete smstols (SMS Server Tools) en un equipo con Linux CentOS seguiremos los siguientes pasos:

1. Podemos probar directamente a intentar instalar el paquete smstools con el comando:

yum install smstools

2. Si nos muestra que no existe el paquete tendremos que añadir el repositorio correspondiente, para ello descargaremos el repositorio con:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/smstools-3.1.15-3.el6.x86_64.rpm

(la ruta puede variar en función de la versión y disposición del repositorio, que podemos buscar en Internet)

Actualizaremos el paquete en el repositorio con:

rpm -Uvh smstools-3.1.15-3.el6.x86_64.rpm

Y lo instalaremos con yum ya que nos resolverá posibles dependencias:

yum install smstools

Instalar y configurar paquete gratuito SMSTOOLS SMS Server Tools en Linux CentOS para envío de SMS

Para configurar SMS Tools Server editaremos el fichero /etc/smsd.conf:

nano /etc/smsd.conf

Instalar y configurar paquete gratuito SMSTOOLS SMS Server Tools en Linux CentOS para envío de SMS

Algunos parámetros interesantes de este fichero son, por ejemplo, "pin" que nos permitirá introducir el PIN de la tarjeta SIM (si lo tiene) para establecer la conexión. Otro parámetro interesante es "device" donde estableceremos el ttyUSB obtenido anteriormente, en nuestro caso /dev/ttyUSB0:

Instalar y configurar paquete gratuito SMSTOOLS SMS Server Tools en Linux CentOS para envío de SMS

(Ejemplo fichero /etc/smsd.conf)

Si hemos hecho alguna modificación en el fichero anterior reiniciaremos el servicio de SMS Tools Server para aplicar los cambios, con el comando:

/etc/init.d/smsd restart

o también:

service smsd restart

Instalar y configurar paquete gratuito SMSTOOLS SMS Server Tools en Linux CentOS para envío de SMS

A partir de ahora ya podremos probar el envío de SMS desde nuestro equipo Linux a un móvil, como mostramos a continuación.

 

Enviar SMS a móvil desde equipo con Linux CentOS mediante módem GSM y SMS Tools

Una vez conectado el módem con la tarjeta SIM e instalado y configurado SMS Tools como hemos indicado anterioremente, podremos enviar SMS directamente desde la línea de comandos con el comando:

smssend numero_telefono "Texto mensaje SMS"

Por ejemplo:

smssend 34XXX "Prueba envio SMS AjpdSoft"

(donde "34" será el código de país y "XXX" será el número de móvil)

Enviar SMS a móvil desde equipo con Linux CentOS mediante módem GSM y SMS Tools

Si todo es correcto nos llegará un SMS al móvil especificado:

Enviar SMS a móvil desde equipo con Linux CentOS mediante módem GSM y SMS Tools

Si por el contrario no llega el SMS podremos comprobar el motivo del fallo de envío de SMS en el fichero de log, con el comando:

cat /var/log/smsd/smsd.log

Enviar SMS a móvil desde equipo con Linux CentOS mediante módem GSM y SMS Tools

En dicho fichero veremos todos los comandos AT que envía SMS Tools al módem para realizar el envío de SMS. Entre estos comandos realiza una comprobación del estado del módem, de la red de datos, de la cobertura (dato interesante por si tenemos problemas de cobertura) y realiza el envío de los SMS encolados. Un ejemplo de su contenido tras enviar satisfactoriamente un SMS:

2014-10-23 14:32:24,5, smsd: Moved file /var/spool/sms/outgoing/send_IsD5dF to /var/spool/sms/checked
2014-10-23 14:32:25,6, GSM1: I have to send 1 short message for /var/spool/sms/checked/send_IsD5dF
2014-10-23 14:32:25,6, GSM1: Sending SMS from to XXX
2014-10-23 14:32:25,6, GSM1: Checking if modem is ready
2014-10-23 14:32:25,7, GSM1: - AT
2014-10-23 14:32:25,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:26,7, GSM1: - OK
2014-10-23 14:32:26,6, GSM1: Pre-initializing modem
2014-10-23 14:32:26,7, GSM1: - ATE0+CMEE=1;+CREG=2
2014-10-23 14:32:26,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:26,7, GSM1: - OK
2014-10-23 14:32:26,7, GSM1: - AT+CSQ
2014-10-23 14:32:26,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:27,7, GSM1: - +CSQ: 27,99 OK
2014-10-23 14:32:27,6, GSM1: Signal Strength Indicator: (27,99) -59 dBm (Excellent), Bit Error Rate: not known or not detectable
2014-10-23 14:32:27,6, GSM1: Checking if Modem is registered to the network
2014-10-23 14:32:27,7, GSM1: - AT+CREG?
2014-10-23 14:32:27,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:27,7, GSM1: - +CREG: 2,1,"0BBD","1184" OK
2014-10-23 14:32:27,6, GSM1: Modem is registered to the network
2014-10-23 14:32:27,6, GSM1: Selecting PDU mode
2014-10-23 14:32:27,7, GSM1: - AT+CMGF=0
2014-10-23 14:32:27,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:28,7, GSM1: - OK
2014-10-23 14:32:28,7, GSM1: - AT+CMGS=19
2014-10-23 14:32:28,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:28,7, GSM1: -
2014-10-23 14:32:28,7, GSM1: - 000B463700089D6
2014-10-23 14:32:28,7, GSM1: Command is sent, waiting for the answer
2014-10-23 14:32:31,7, GSM1: - +CMGS: 58 OK
2014-10-23 14:32:31,5, GSM1: SMS sent, Message_id: 58, To: XXX, sending time 6 sec.
2014-10-23 14:32:31,6, GSM1: Deleted file /var/spool/sms/checked/send_IsD5dF


 

Algunos errores típicos en el módem GSM y envío de SMS

  • Si el módem no está registrado en la red de datos correctamente, o bien por problemas en la tarjeta SIM o bien porque que no está correctamente dada de alta y activada en el proveedor de telefonía:

2014-10-23 12:14:03,7, GSM1: - AT+CSQ
2014-10-23 12:14:03,7, GSM1: Command is sent, waiting for the answer
2014-10-23 12:14:03,7, GSM1: - AT+CSQ +CSQ: 24,99 OK
2014-10-23 12:14:03,5, GSM1: Signal Strength Indicator: (24,99) -65 dBm (Excellent), Bit Error Rate: not known or not detectable
2014-10-23 12:14:03,7, GSM1: - AT+CREG?
2014-10-23 12:14:03,7, GSM1: Command is sent, waiting for the answer
2014-10-23 12:14:04,7, GSM1: - AT+CREG? +CREG: 0,1 OK
2014-10-23 12:14:04,5, GSM1: MODEM IS NOT REGISTERED, WAITING 1 SEC. BEFORE RETRYING 100. TIME
2014-10-23 12:14:05,3, GSM1: Error: Modem is not registered to the network
2014-10-23 12:14:05,6, GSM1: Deleted file /var/spool/sms/checked/send_e59bTB

  • Problemas con la cobertura:

2014-10-20 14:57:32,7, GSM1: - AT
2014-10-20 14:57:32,7, GSM1: Command is sent, waiting for the answer
2014-10-20 14:57:32,7, GSM1: - AT OK
2014-10-20 14:57:32,6, GSM1: Pre-initializing modem
2014-10-20 14:57:32,7, GSM1: - ATE0+CMEE=1;+CREG=2
2014-10-20 14:57:32,7, GSM1: Command is sent, waiting for the answer
2014-10-20 14:57:33,7, GSM1: - ATE0+CMEE=1;+CREG=2 OK
2014-10-20 14:57:33,6, GSM1: Checking if modem needs PIN
2014-10-20 14:57:33,7, GSM1: - AT+CPIN?
2014-10-20 14:57:33,7, GSM1: Command is sent, waiting for the answer
2014-10-20 14:57:33,7, GSM1: - +CPIN: READY OK
2014-10-20 14:57:33,7, GSM1: - AT+CSQ
2014-10-20 14:57:33,7, GSM1: Command is sent, waiting for the answer
2014-10-20 14:57:34,7, GSM1: - +CSQ: 99,0 OK
2014-10-20 14:57:34,6, GSM1: Signal Strength Indicator: not present of not measurable, Bit Error Rate: less than 0.2 %
2014-10-20 14:57:34,6, GSM1: Checking if Modem is registered to the network

  • Error en la detección del módem GSM:

2014-10-17 13:34:34,6, GSM1: Sending SMS from to XXX
2014-10-17 13:34:34,6, GSM1: Checking if modem is ready
2014-10-17 13:34:34,7, GSM1: - AT
2014-10-17 13:34:34,3, GSM1: write_to_modem: error 5: Input/output error
2014-10-17 13:36:06,3, GSM1: write_to_modem: error 5: Input/output error
2014-10-17 13:36:17,3, GSM1: Couldn't open serial port /dev/ttyUSB2, error: No such file or directory

2014-10-17 13:37:27,2, GSM1: Modem handler 0 terminated. PID: 7824, was started 14-10-16 15:29:53.
2014-10-19 03:21:01,2, smsd: Smsd mainprocess is awaiting the termination of all modem handlers. PID: 7822.
2014-10-19 03:21:01,2, smsd: Smsd mainprocess terminated. PID 7822, was started 14-10-16 15:29:53.

  • Fallo en la tarjeta SIM:

2014-10-13 11:55:06,6, GSM1: Checking if modem is ready
2014-10-13 11:55:07,7, GSM1: - AT
2014-10-13 11:55:07,7, GSM1: Command is sent, waiting for the answer
2014-10-13 11:55:07,7, GSM1: - OK
2014-10-13 11:55:07,6, GSM1: Pre-initializing modem
2014-10-13 11:55:07,7, GSM1: - ATE0+CMEE=1;+CREG=2
2014-10-13 11:55:07,7, GSM1: Command is sent, waiting for the answer
2014-10-13 11:55:07,7, GSM1: - +CME ERROR: 13 (SIM failure)
2014-10-13 11:55:07,3, GSM1: Modem did not accept the pre-init string
2014-10-13 11:55:07,6, GSM1: Checking if modem needs PIN
2014-10-13 11:55:08,7, GSM1: - AT+CPIN?
2014-10-13 11:55:08,7, GSM1: Command is sent, waiting for the answer
2014-10-13 11:55:08,7, GSM1: - +CME ERROR: 13 (SIM failure)
2014-10-13 11:55:08,2, GSM1: PIN handling: expected READY, modem answered +CME ERROR: 13 (SIM failure), SIM failure
2014-10-13 11:55:08,2, GSM1: Modem handler 0 terminated abnormally. PID: 22590.

  • El servicio smsd no está iniciado:

2014-10-13 12:20:14,2, smsd: Smsd mainprocess is awaiting the termination of all modem handlers. PID: 28013.
2014-10-13 12:20:14,7, GSM1: put_command expected (OK)|(ERROR), timeout occurred. 1.
2014-10-13 12:20:14,7, GSM1: -
2014-10-13 12:20:14,3, GSM1: The modem answer was not OK:
2014-10-13 12:20:14,5, GSM1: Waiting 10 sec. before retrying
2014-10-13 12:20:14,4, GSM1: Sending SMS to XXX failed, trying time 127 sec. Retries: 1.
2014-10-13 12:20:14,6, GSM1: Deleted file /var/spool/sms/checked/send_oU7uyu
2014-10-13 12:20:14,2, GSM1: Modem handler 0 terminated. PID: 28014, was started 14-10-13 12:18:02.
2014-10-13 12:20:14,2, smsd: Smsd mainprocess terminated. PID 28013, was started 14-10-13 12:18:02.

 

Anexo

  • Salida completa del comando dmesg:

ftdi_sio ttyUSB0: Unable to write latency timer: -32
e1000e 0000:13:00.0: irq 26 for MSI/MSI-X
e1000e 0000:13:00.0: irq 26 for MSI/MSI-X
ADDRCONF(NETDEV_UP): eth0: link is not ready
8021q: adding VLAN 0 to HW filter on device eth0
e1000e 0000:13:00.1: irq 27 for MSI/MSI-X
e1000e 0000:13:00.1: irq 27 for MSI/MSI-X
ADDRCONF(NETDEV_UP): Auto_eth1: link is not ready
8021q: adding VLAN 0 to HW filter on device Auto_eth1
alloc irq_desc for 28 on node -1
alloc kstat_irqs on node -1
bnx2 0000:04:00.0: irq 28 for MSI/MSI-X
bnx2 0000:04:00.0: eth2: using MSI
ADDRCONF(NETDEV_UP): eth2: link is not ready
alloc irq_desc for 29 on node -1
alloc kstat_irqs on node -1
bnx2 0000:06:00.0: irq 29 for MSI/MSI-X
bnx2 0000:06:00.0: eth3: using MSI
ADDRCONF(NETDEV_UP): eth3: link is not ready
ftdi_sio ttyUSB0: Unable to write latency timer: -32
e1000e: Auto_eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
ADDRCONF(NETDEV_CHANGE): Auto_eth1: link becomes ready
Auto_eth1: no IPv6 routers present
fuse init (API version 7.13)
ftdi_sio ttyUSB0: Unable to write latency timer: -32
usb 2-2: USB disconnect, device number 2
ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
ftdi_sio 2-2:1.0: device disconnected
usb 2-2: new full speed USB device number 3 using uhci_hcd
usb 2-2: New USB device found, idVendor=0f94, idProduct=0005
usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-2: Product: Falcom SAMBA
usb 2-2: Manufacturer: FALCOM
usb 2-2: SerialNumber: F0012773
usb 2-2: configuration #1 chosen from 1 choice
ftdi_sio 2-2:1.0: FTDI USB Serial Device converter detected
usb 2-2: Detected FT8U232AM
usb 2-2: Number of endpoints 2
usb 2-2: Endpoint 1 MaxPacketSize 64
usb 2-2: Endpoint 2 MaxPacketSize 64
usb 2-2: Setting MaxPacketSize 64
ftdi_sio ttyUSB0: Unable to read latency timer: -32
usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0
ftdi_sio ttyUSB0: Unable to write latency timer: -32
ftdi_sio ttyUSB0: Unable to write latency timer: -32

  • Salida del comando lsusb:

    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 003: ID 0f94:0005
    Bus 003 Device 002: ID 046d:c312 Logitech, Inc. DeLuxe 250 Keyboard
    Bus 003 Device 003: ID 046d:c018 Logitech, Inc. Optical Wheel Mouse

  • Salida del comando lsusb -D /dev/bus/usb/002/003:

Device: ID 0f94:0005
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0f94
idProduct 0x0005
bcdDevice 2.00
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 498mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 2
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0003
Self Powered
Remote Wakeup Enabled

  • Ejemplo fichero /etc/smsd.conf


# Example smsd.conf. Read the manual for a description

devices = GSM1
logfile = /var/log/smsd/smsd.log
loglevel = 10
user = smstools
infofile = /var/run/smsd/smsd.working
pidfile = /var/run/smsd/smsd.pid
# 3.1.5 introduced smart logging
# once your configuration is OK, set log level lower (5 is good in most cases)
smart_logging = yes

[GSM1]
device = /dev/ttyUSB0
incoming = no
#pin = 1111


Artículos relacionados

  

Créditos

Artículo realizado íntegramente por Alonsojpd miembro fundador del Proyecto AjpdSoft.

Artículo en inglés.


Anuncios


Enviado el Jueves, 23 octubre a las 15:03:36 por ajpdsoft
Visita nuestro nuevo sitio web con programas y contenidos actualizados: Proyecto A