HomeGenie Forum
Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: nolio on February 04, 2014, 02:25:19 PM
-
Hi,
I configure HG to send sms with a usb-key and SIM Card, when the "security alarm system" is armed and triggered.
Do you think it can be interesting to describe on how to configure it ?
The needed things :
#######################################
- Raspberry Pi Model B rev2 (for me)
- USB Key 3G (Huawei E1752 for me)
- SIM Card from a operator which permit to send SMS
- USB Key reconize on rasp
- Install Gammu
- Use of a python script which listen as socket server
- Modification of script "90-Security_Alarm_System"
- HG >= r326 (permit to use TCP Helper Class)
##########################################
Bye
-
Yes! Please share :)
-
Hi,
So i try to describe what i did ...
The differents steps :
1/ Install USB Key on rasp
I just plug my USB key and it is recognize :
lsusb | grep Huawei
Bus 001 Device 006: ID 12d1:141b Huawei Technologies Co., Ltd.
2/ Install python
sudo apt-get install python
sudo apt-get install python-setuptools
3/ Install Gammu
sudo apt-get update
sudo apt-get install gammu
dmesg |grep ttyUSB*
sudo gammu-config
sudo gammu --identify
You can test to send a sms with this command :
echo "testtttt" | /usr/bin/gammu --sendsms TEXT "+xxxxxx"
xxxxxx = your phone number
4/ Install python script
from this web site :
http://domotique-info.fr/2014/01/un-script-python-comme-serveur-sms/
(french site but the code is compliant ;))
part 6 : "6 – Le script Python « passerelle SMS »" ("...import socket.....")
I use :
filename='/tmp/sms-gw.log'
And on line 40 :
cmd = "echo " + chr(34) + data + chr(34)+ " | /usr/bin/gammu --sendsms TEXT " + num
I use too the part 7 to create a bootable script
5/ Adapt C# script "90-Security_Alarm_System" to use the python script
..........
var recipients = Program.InputField("Email.Recipients").Value;
////////////////////// Send SMS //////////////////////
var remoteserversms = "xx.xx.xx.xx"; //@IP of your server with python script
var tel1 = "xxxxxxxx"; // Your phone number
//////////////////// 1st SMS /////////////////////
TcpClient
.Service( remoteserversms ) // server
.Connect( 3000 ); // port of python script
TcpClient.SendMessage(tel1+"::Alarm //"+Program.Parameter("HomeGenie.SecurityTriggerSource").Value+" //");
Pause(3);
TcpClient.Disconnect();
Pause(3);
////////////////////////////////////////////////////////////
if (recipients != "")
....
I want to send 2 SMS so i copy the code between "1st SMS" and "//////////" with a new variable "tel2".
So it work fine for me. There is some more advance solutions than gammu which use php (and compatible with older version of HG), but i doesn't want to install php on my raspberry (i think so heavy).
Perhaps, there is better way to code in C#, but i am not a expert in C#, and i am more useful to code simple code in bash, perl, or VB.
Bye
-
Hi, all
It will be great if SMS via USB 3G dongle can be added by default to HG!
-
Hi,
We can only work on :
- Step 5 : Add the code in the script existing with the installation "90-Security_Alarm_System"
- Use the new program execution available in script to call gammu command (more simple than add a python script)
I try the last one but the command is little bit hard to pass a lot of arguments, the command to execute :
echo "testtttt" | /usr/bin/gammu --sendsms TEXT 0606060606"
---->>>> Failed C# code ---->>>>
var proc = new System.Diagnostics.Process {
StartInfo = new System.Diagnostics.ProcessStartInfo {
FileName = "echo",
Arguments = "'test cle 3G depuis HG en processsss' | /usr/bin/gammu --sendsms TEXT '0606060606'",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
And last, we can't do the installation of key and gammu ;).
Bye
-
Hi,
An update, it's more simple now. On HG, i pass from TcpClientHelper to System.Diagnostics.Process.
That's mean, the python script is no more needed but a direct call to gammu command line (you can see an example in my script here : http://www.homegenie.it/forum/index.php?topic=520.0 (http://www.homegenie.it/forum/index.php?topic=520.0)).
###########Need thing ############################
- Raspberry Pi Model B rev2 (for me)
- USB Key 3G (Huawei E1752 for me)
- SIM Card from a operator which permit to send SMS
- USB Key reconize on rasp
- Install Gammu
(- Powered USB Hub or Raspberry pi B+ to avoid the startup bad recognition and the need of unplug/plug after a reboot ?? )
#############The different steps######################
1/ Install USB Key on rasp
I just plug my USB key and it is recognize :
lsusb | grep Huawei
Bus 001 Device 006: ID 12d1:141b Huawei Technologies Co., Ltd.
2/ Install Gammu
sudo apt-get update
sudo apt-get install gammu
dmesg |grep ttyUSB*
sudo gammu-config
sudo gammu --identify
You can test to send a sms with this command :
echo "testtttt" | /usr/bin/gammu --sendsms TEXT "+xxxxxx"
xxxxxx = your phone number
3/ Import of the C# script
http://www.homegenie.it/forum/index.php?topic=520.0 (http://www.homegenie.it/forum/index.php?topic=520.0)
Or adapt it ;)
Bye