From 9cad25580467d5b79a1801247dce58f7b397efdd Mon Sep 17 00:00:00 2001 From: flothi Date: Thu, 25 Aug 2016 21:38:40 +0200 Subject: [PATCH 1/2] Enabling SMS functionality Use gammu to send SMS immediately via BOSWatch (connected UMTS-Stick). Watch out the prerequisites! --- plugins/SMS/SMS.prereq | 16 ++++ plugins/SMS/SMS.py | 163 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 plugins/SMS/SMS.prereq create mode 100644 plugins/SMS/SMS.py diff --git a/plugins/SMS/SMS.prereq b/plugins/SMS/SMS.prereq new file mode 100644 index 0000000..eadc9d7 --- /dev/null +++ b/plugins/SMS/SMS.prereq @@ -0,0 +1,16 @@ +gammu installieren + +sudo apt-get install gammu python-gammu +Konfig erstellen (zB /etc/gammurc) + +root-Pflicht entfernen +http://askubuntu.com/questions/211739/gammu-and-device-permissions + +Daten eintragen + +PIN-Abfrage deaktivieren mittels minicom +minicom -D /dev/ttyUSB0 +ATI # alle infos + +AT+CLCK="SC",0,"0000" # 0000 = PIN +AT+CLCK="SC",2 # Status-Check \ No newline at end of file diff --git a/plugins/SMS/SMS.py b/plugins/SMS/SMS.py new file mode 100644 index 0000000..bb5fc81 --- /dev/null +++ b/plugins/SMS/SMS.py @@ -0,0 +1,163 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" +This plugin enables the function of sendig SMS to +a given number defined in config.ini +It is sensitive to ric and subric, also defined in +config.ini + +@author: Jens Herrmann +@author: Bastian Schroll +@author: Florian Thillmann + +@requires: Installed and configured gammu, SMS-gateway (such as UMTS-stick) working as non-root +""" + +# +# Imports +# +import logging # Global logger +from includes import globals # Global variables + +# Helper function, uncomment to use +#from includes.helper import timeHandler +#from includes.helper import wildcardHandler +from includes.helper import configHandler + +# import for gammu +import gammu + +def find(l, elem): + for row, i in enumerate(l): + try: + column = i.index(elem) + except ValueError: + continue + return row, column + return -1 + +## +# +# onLoad (init) function of plugin +# will be called one time by the pluginLoader on start +# +def onLoad(): + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin + + @requires: nothing + + @return: nothing + @exception: Exception if init has an fatal error so that the plugin couldn't work + + """ + try: + pass + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) + raise + +## +# +# Main function of plugin +# will be called by the alarmHandler +# +def run(typ,freq,data): + """ + This function is the implementation of the Plugin. + + If necessary the configuration hast to be set in the config.ini. + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see interface.txt) + @param data: Contains the parameter for dispatch + @type freq: string + @keyword freq: frequency of the SDR Stick + + @requires: If necessary the configuration hast to be set in the config.ini. + + @return: nothing + @exception: nothing, make sure this function will never thrown an exception + """ + try: + if configHandler.checkConfig("SMS"): #read and debug the config (let empty if no config used) + if typ == "POC": # only available for POC! + logging.debug("Plugin SMS enabled") + + # get number of cases and build a RIC-Array + i = globals.config.get("SMS","quantity") + aRic = [] + + # build the array + for x in range (1, int(i) + 1): + # check the number of subrics + subric = globals.config.get("SMS","subric" + str(x)) + if len(subric) > 1: # we have more than one subric + subric_list = subric.split(",") + for y in range (0, len(subric_list)): + sric = subric_list[y].replace(' ','') + full_ric = globals.config.get("SMS","ric" + str(x)) + sric + case = x + tmp = [] + tmp.append(full_ric) + tmp.append(case) + aRic.append(tmp) + else: + #get ric AND subric at once with ONE subric + tmp = [] + tmp.append(globals.config.get("SMS","ric" + str(x)) + subric) + tmp.append(x) + aRic.append(tmp) # 2D-Array... + + # Debug: Display the multidimensional array aRic + #logging.debug("aRic: %s", aRic) + + target = data["ric"] + data["functionChar"] + + #logging.debug("Searching for any occurences of %s", target) + #if target in aRic: + try: + index = find(aRic, target) + except: + logging.error("RIC not found") + + logging.debug("Return from find: %s", index) + if index != -1: + case = aRic[index[0]][1] + logging.debug("Enabling case %s", case) + + text = globals.config.get("SMS","text" + str(case)) + number = globals.config.get("SMS","phonenumber" + str(case)) + + #just for debug + logging.debug("Aktivierter Text: %s", text) + logging.debug("Aktivierte Nummer: %s", number) + + # send sms + try: + sm = gammu.StateMachine() + sm.ReadConfig() + sm.Init() + + message = { + 'Text': text, + 'SMSC': {'Location': 1}, + 'Number': number, + } + sm.SendSMS(message) + except: + logging.error("Failed to send SMS") + else: + logging.debug("Falsche SUB-RIC entdeckt - weiter gehts!") + + else: + logging.warning("Invalid Typ: %s", typ) + ########## User Plugin CODE ########## + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) From 18dae06266bf1e15c1313cc2f779d2e6ee78ca7d Mon Sep 17 00:00:00 2001 From: flothi Date: Thu, 25 Aug 2016 21:39:27 +0200 Subject: [PATCH 2/2] Adding SMS Enabling SMS-functions --- config/config.template.ini | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index a7b8c26..3be9c60 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -283,6 +283,23 @@ appName = BOSWatch # configuration loaded from csv/nma.csv usecsv = 0 +[SMS] +# be aware that you need 'gammu' installed and running +# at least you need an UMTS-stick which is supported by 'gammu' + +quantity = 1 +# be sensitive to single RIC +ric1 = 1234567 + +# but you can watch several subrics, comma-separated +subric1 = a, b + +# a single cellphone-number +phonenumber1 = 0160321654987 + +# and the text for the sms +# ! DO NOT USE ANY UMLAUT ! +text1 = Rueckruf Leitstelle! ##################### ##### Not ready yet #