more G-Labs products

Author Topic: HG send sms with a usb-key and SIM Card  (Read 4810 times)

February 04, 2014, 02:25:19 PM
Read 4810 times

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
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

February 04, 2014, 02:37:55 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

February 12, 2014, 10:10:59 PM
Reply #2

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
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
« Last Edit: February 25, 2014, 09:30:42 PM by nolio »

October 06, 2014, 04:44:51 PM
Reply #3

Bitcraze

  • ***
  • Information
  • Full Member
  • Posts: 73
Hi, all

It will be great if SMS via USB 3G dongle can be added by default to HG!

October 17, 2014, 03:17:30 PM
Reply #4

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
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 :
Code: [Select]
echo "testtttt" | /usr/bin/gammu --sendsms TEXT 0606060606"---->>>> Failed C# code ---->>>>
Code: [Select]
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

December 12, 2014, 10:10:33 PM
Reply #5

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
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).

###########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 :
Code: [Select]
lsusb | grep Huawei
Bus 001 Device 006: ID 12d1:141b Huawei Technologies Co., Ltd.
2/ Install Gammu
Code: [Select]
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 :
Code: [Select]
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
Or adapt it ;)

Bye
« Last Edit: December 12, 2014, 10:18:44 PM by nolio »