[ANSWERED]Need help with scripting/programming for SMS text

Posted on
Sat Dec 27, 2014 10:18 am
lochnesz offline
Posts: 366
Joined: Oct 01, 2014
Location: Stockholm, Sweden

[ANSWERED]Need help with scripting/programming for SMS text

I would like to be able to send text messages as an action in Indigo.

I have a 3g dongle with SMS capabilities, and I control it using "terminal" and "screen". After connecting to the 3g dongle (screen '/dev/tty.GI505 Modem' 115200) I can use AT commands to send text messages. So far so good.

Now I would like Indigo to send the text messages for me when I trigger the text sending action. I would like to have variables in Indigo with phone number and text to send, also Z-wave device names etc.

Can anyone with scripting/programming knowledge help me with this?

A bonus would be if there is a way to receive text messages and control my Indigo network that way...

Thanks!

Posted on
Mon Dec 29, 2014 12:27 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Need help with scripting/programming for SMS text sendin

We include pyserial - which is a python library to control serial devices. I suspect if you write a script that opens that port then you should be able to write the necessary AT commands to it. You'll need to know some Python, but it's a straight-forward language really.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Dec 29, 2014 12:35 pm
lochnesz offline
Posts: 366
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: Need help with scripting/programming for SMS text sendin

Thanks Jay, I am not familiar with python but I will give it a try.
(If anyone can give me a helping hand I'd appreciate it.)

Posted on
Mon Jan 05, 2015 12:34 pm
lochnesz offline
Posts: 366
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: Need help with scripting/programming for SMS text sendin

Okay, I think I am on the right path, but would need some help.

This works with variables inside the script:
Code: Select all
#!/usr/bin/env python

import serial
import time

phonenumber = "+1234567890"
message = "Test message"

ser = serial.Serial('/dev/tty.GI505 Modem', 115200)
ser.write('ATZ\r')
time.sleep(1)
ser.write('AT+CMGF=1\r')
time.sleep(1)
ser.write('''AT+CMGS="''' + phonenumber + '''"\r''')
time.sleep(1)
ser.write(message + "\r")
time.sleep(1)
ser.write(chr(26))
time.sleep(1)
ser.close()


But this doesn't work, when I try to give the python variables values from Indigo:

Code: Select all
#!/usr/bin/env python

import serial
import time

phonenumber = indigo.variables[172971071]
message = indigo.variables[225832042]

ser = serial.Serial('/dev/tty.GI505 Modem', 115200)
ser.write('ATZ\r')
time.sleep(1)
ser.write('AT+CMGF=1\r')
time.sleep(1)
ser.write('''AT+CMGS="''' + phonenumber + '''"\r''')
time.sleep(1)
ser.write(message + "\r")
time.sleep(1)
ser.write(chr(26))
time.sleep(1)
ser.close()


I get error: embedded script: cannot concatenate 'str' and 'Variable' objects
Anyone have a clue?

Posted on
Mon Jan 05, 2015 12:45 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Need help with scripting/programming for SMS text sendin

it should be:
Code: Select all
phonenumber = indigo.variables[172971071].value
message = indigo.variables[225832042].value

See the variable documentation here

Hope this helps :)

Posted on
Mon Jan 05, 2015 12:48 pm
lochnesz offline
Posts: 366
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: Need help with scripting/programming for SMS text sendin

Many thanks! Works perfect now!

Posted on
Tue Jan 06, 2015 2:06 pm
lochnesz offline
Posts: 366
Joined: Oct 01, 2014
Location: Stockholm, Sweden

Re: [ANSWERED]Need help with scripting/programming for SMS t

Here is the result of the script for sending SMS text messages via serial mobile modem.
Code: Select all
#!/usr/bin/env python
#sms from indigo
#version 1.1
#uses pyserial
#create variable "mob_number_1" in indigo before running this script
#create variable "mob_message_1" in indigo before running this script
#create variable "mob_sms_last_run" in indigo before running this script

import serial
import time

phonenumber1 = indigo.variables["mob_number_1"].value # get the phone number from indigo variable
message1 = "S.O.M: " + indigo.variables["mob_message_1"].value + " E.O.M." # message content

indigo.server.log ("Starting sending text message to " + phonenumber1) #indigo log message
indigo.server.log ("Message to send: " + message1) #indigo log message

ser = serial.Serial('/dev/tty.GI505 Modem', 115200, timeout=2) #serial port is /dev/tty.GI505 Modem, baudrate 115200, timeout 2
ser.write('ATZ\r')
time.sleep(.5)
ser.write('AT+CMGF=1\r') #set modem to text mode
time.sleep(.5)
ser.write('''AT+CMGS="''' + phonenumber1 + '''"\r''') #send text message1 to this number
time.sleep(.5)
ser.write(message1 + "\r") #text message body
time.sleep(.5)
ser.write(chr(26)) #ctrl-z
time.sleep(1)
res = ser.read(size=256) #read result from modem
time.sleep(1)
ser.close()

indigo.server.log ("Modem result codes: " + "\r" + res) #indigo log message

localtime = time.asctime( time.localtime(time.time()) )
indigo.variable.updateValue("mob_sms_last_run", value=localtime)
indigo.server.log ("Text message sending script completed on: " + localtime) #indigo log message

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests