Diverse Modifikationen; Elimination von gammu-smsd
This commit is contained in:
parent
4610ba3792
commit
410972b8ce
|
|
@ -176,7 +176,8 @@ def send_sms(phonenumbers , text):
|
||||||
}
|
}
|
||||||
|
|
||||||
#GELD SPAREN smsd.InjectSMS([message])
|
#GELD SPAREN smsd.InjectSMS([message])
|
||||||
#print("Send SMS to %s, Text: %s" % (phonenumber, text))
|
smsd.InjectSMS([message])
|
||||||
|
print("Send SMS to %s, Text: %s" % (phonenumber, text))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
scales = []
|
scales = []
|
||||||
|
|
@ -218,6 +219,7 @@ def main():
|
||||||
send_sms(scale.GetScaleConfig()['sms_alert_phonenumbers'],sms_message)
|
send_sms(scale.GetScaleConfig()['sms_alert_phonenumbers'],sms_message)
|
||||||
scale.ResetValues()
|
scale.ResetValues()
|
||||||
|
|
||||||
|
sys.stdout.flush()
|
||||||
time.sleep(config_data['read_scale_interval_sec'])
|
time.sleep(config_data['read_scale_interval_sec'])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"""Beehive Monitoring - SMS Processing"""
|
"""Beehive Monitoring - SMS Processing"""
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import gammu.smsd
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
@ -23,6 +24,9 @@ from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.utils import COMMASPACE, formatdate
|
from email.utils import COMMASPACE, formatdate
|
||||||
|
|
||||||
|
# Interface to gammu-smsd
|
||||||
|
smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc')
|
||||||
|
|
||||||
# Root Path
|
# Root Path
|
||||||
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
|
|
@ -30,21 +34,20 @@ APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
with open("%s/bin/beielimon-config.yaml" % APP_ROOT, 'r') as stream:
|
with open("%s/bin/beielimon-config.yaml" % APP_ROOT, 'r') as stream:
|
||||||
try:
|
try:
|
||||||
config_data = yaml.load(stream)
|
config_data = yaml.load(stream)
|
||||||
#print(config_data)
|
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
|
|
||||||
def send_sms(phonenumbers , text):
|
def send_sms(phonenumbers , text):
|
||||||
print("BBB: %s" % (text))
|
|
||||||
for phonenumber in phonenumbers:
|
for phonenumber in phonenumbers:
|
||||||
message = {
|
message = {
|
||||||
'Text': text,
|
'Text': text,
|
||||||
'SMSC': {'Location': 1},
|
'SMSC': {'Location': 1},
|
||||||
'Number': phonenumber
|
'Number': phonenumber
|
||||||
}
|
}
|
||||||
|
|
||||||
os.system('echo "%s" | /usr/bin/gammu-smsd-inject TEXT %s' % (text,phonenumber))
|
#GELD SPAREN smsd.InjectSMS([message])
|
||||||
#print("YYY Send SMS to %s, Text: %s" % (phonenumber, text))
|
smsd.InjectSMS([message])
|
||||||
|
print("Send SMS to %s, Text: %s" % (phonenumber, text))
|
||||||
|
|
||||||
def send_mail(send_from, send_to, subject, text, files=None):
|
def send_mail(send_from, send_to, subject, text, files=None):
|
||||||
os.system('/usr/bin/sudo %s/root-bin/connect_to_internet' % (APP_ROOT))
|
os.system('/usr/bin/sudo %s/root-bin/connect_to_internet' % (APP_ROOT))
|
||||||
|
|
@ -56,9 +59,7 @@ def send_mail(send_from, send_to, subject, text, files=None):
|
||||||
|
|
||||||
msg.attach(MIMEText(text))
|
msg.attach(MIMEText(text))
|
||||||
|
|
||||||
print("XXX: %s" % (files))
|
|
||||||
for f in files or []:
|
for f in files or []:
|
||||||
print("AAA: %s" % (f))
|
|
||||||
with open(f, "rb") as fil:
|
with open(f, "rb") as fil:
|
||||||
part = MIMEApplication(
|
part = MIMEApplication(
|
||||||
fil.read(),
|
fil.read(),
|
||||||
|
|
@ -68,8 +69,8 @@ def send_mail(send_from, send_to, subject, text, files=None):
|
||||||
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
|
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
|
||||||
msg.attach(part)
|
msg.attach(part)
|
||||||
|
|
||||||
smtp = smtplib.SMTP(config_data['mailserver'],config_data['mailserver_port'],timeout=30)
|
smtp = smtplib.SMTP(config_data['mailserver'],config_data['mailserver_port'],timeout=60)
|
||||||
#smtp.set_debuglevel(1)
|
smtp.set_debuglevel(1)
|
||||||
smtp.ehlo()
|
smtp.ehlo()
|
||||||
smtp.starttls()
|
smtp.starttls()
|
||||||
smtp.login(config_data['mailuser'], config_data['mailpwd'])
|
smtp.login(config_data['mailuser'], config_data['mailpwd'])
|
||||||
|
|
@ -144,10 +145,7 @@ def CreateAttachements(infotime):
|
||||||
os.makedirs(myzipdir)
|
os.makedirs(myzipdir)
|
||||||
res = []
|
res = []
|
||||||
my_pattern = '%s%s' % (infotime,'?' * (8 - len(infotime)))
|
my_pattern = '%s%s' % (infotime,'?' * (8 - len(infotime)))
|
||||||
print('AAA: %s' % (my_pattern))
|
|
||||||
files = glob.glob("%s/data/weight-*-%s.log" % (APP_ROOT,my_pattern))
|
files = glob.glob("%s/data/weight-*-%s.log" % (APP_ROOT,my_pattern))
|
||||||
for f in files:
|
|
||||||
print("%s" % (f))
|
|
||||||
for s in config_data['scales']:
|
for s in config_data['scales']:
|
||||||
filename = "%s/%s-%s.csv" % (mycsvdir,s['alias'].replace(' ','_'),infotime)
|
filename = "%s/%s-%s.csv" % (mycsvdir,s['alias'].replace(' ','_'),infotime)
|
||||||
with_data = False
|
with_data = False
|
||||||
|
|
@ -157,7 +155,7 @@ def CreateAttachements(infotime):
|
||||||
with_data = True
|
with_data = True
|
||||||
with open(ifile, 'r') as ifile:
|
with open(ifile, 'r') as ifile:
|
||||||
for line in ifile:
|
for line in ifile:
|
||||||
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d,(\d+)", line)
|
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d),(\d+)", line)
|
||||||
if m:
|
if m:
|
||||||
file.write("%s.%s.%s %s,%s\n" % (m.group(3),m.group(2),m.group(1),m.group(4),m.group(5)))
|
file.write("%s.%s.%s %s,%s\n" % (m.group(3),m.group(2),m.group(1),m.group(4),m.group(5)))
|
||||||
else:
|
else:
|
||||||
|
|
@ -167,17 +165,17 @@ def CreateAttachements(infotime):
|
||||||
|
|
||||||
zipfile = "%s/%s" % (myzipdir,infotime)
|
zipfile = "%s/%s" % (myzipdir,infotime)
|
||||||
shutil.make_archive(zipfile, 'zip', mycsvdir)
|
shutil.make_archive(zipfile, 'zip', mycsvdir)
|
||||||
#print("ATTA: %s" % (res))
|
|
||||||
return [ "%s.zip" % (zipfile) ]
|
return [ "%s.zip" % (zipfile) ]
|
||||||
|
|
||||||
def send_report(infotime):
|
def send_report(infotime):
|
||||||
# Send EMail Report
|
# Send EMail Report
|
||||||
my_text = "Letzte Messwerte:\n"
|
my_text = my_text = "Letzte Messwerte:\n"
|
||||||
for s in config_data['scales']:
|
for s in config_data['scales']:
|
||||||
my_text += "%s: %s\n" % (s['alias'],GetLastValues(s['scale_uuid']))
|
my_text += "%s: %s\n" % (s['alias'],GetLastValues(s['scale_uuid']))
|
||||||
|
my_text += "\n\nIm ZIP-File sind die Messwerte der gewuenschten Periode enthalten. Die Daten sind im CSV-Format abgespeichert und koennen z.B. mit Excel analysiert werden.\n"
|
||||||
attachements = CreateAttachements(infotime)
|
attachements = CreateAttachements(infotime)
|
||||||
|
|
||||||
#send_mail(config_data['mailfrom'],config_data['mailto'],'Messwerte mini-beieli',my_text,attachements)
|
#send_mail(config_data['mailfrom'],config_data['mailto'],'Messwerte BeieliPi',my_text,attachements)
|
||||||
|
|
||||||
def send_info_sms(phonenumber):
|
def send_info_sms(phonenumber):
|
||||||
my_text = "Letzte Messwerte:\n"
|
my_text = "Letzte Messwerte:\n"
|
||||||
|
|
@ -187,19 +185,24 @@ def send_info_sms(phonenumber):
|
||||||
send_sms([phonenumber],my_text)
|
send_sms([phonenumber],my_text)
|
||||||
|
|
||||||
def send_info(phonenumber, message_uc):
|
def send_info(phonenumber, message_uc):
|
||||||
|
print("AAA: send_info %s" % message_uc)
|
||||||
m = re.match(".*(INFO)\s+(\d{8})", message_uc)
|
m = re.match(".*(INFO)\s+(\d{8})", message_uc)
|
||||||
if m:
|
if m:
|
||||||
send_report(m.group(2))
|
send_report(m.group(2))
|
||||||
|
print("BBB: send_info %s" % message_uc)
|
||||||
else:
|
else:
|
||||||
m = re.match(".*(INFO)\s+(\d{6})", message_uc)
|
m = re.match(".*(INFO)\s+(\d{6})", message_uc)
|
||||||
if m:
|
if m:
|
||||||
send_report(m.group(2))
|
send_report(m.group(2))
|
||||||
|
print("CCC: send_info %s %s" % (message_uc,m.group(2)))
|
||||||
else:
|
else:
|
||||||
m = re.match(".*(INFO)\s+(\d{4})", message_uc)
|
m = re.match(".*(INFO)\s+(\d{4})", message_uc)
|
||||||
if m:
|
if m:
|
||||||
send_report(m.group(2))
|
send_report(m.group(2))
|
||||||
|
print("DDD: send_info %s" % message_uc)
|
||||||
else:
|
else:
|
||||||
send_info_sms(phonenumber)
|
send_info_sms(phonenumber)
|
||||||
|
print("EEE: send_info %s" % message_uc)
|
||||||
|
|
||||||
def balance():
|
def balance():
|
||||||
send_sms([config_data['balance_number']],config_data['balance_command'])
|
send_sms([config_data['balance_number']],config_data['balance_command'])
|
||||||
|
|
@ -220,9 +223,7 @@ def command_not_understood(phonenumber, message):
|
||||||
send_sms([phonenumber],'Befehl nicht verstanden: %s\n\nMoegliche Befehle: help, info, balance, reboot, shutdown, hotspot' % (message[:50]))
|
send_sms([phonenumber],'Befehl nicht verstanden: %s\n\nMoegliche Befehle: help, info, balance, reboot, shutdown, hotspot' % (message[:50]))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(config_data)
|
print('%s was called at %s with these arguments: %s\n' % (sys.argv[0],formatdate(localtime=True),str(sys.argv)))
|
||||||
print('Number of arguments:', len(sys.argv), 'arguments.')
|
|
||||||
print('Argument List:', str(sys.argv))
|
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
print("Da kann etwas nicht stimmen, ungueltige Anzahl Argumente")
|
print("Da kann etwas nicht stimmen, ungueltige Anzahl Argumente")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
@ -233,8 +234,6 @@ def main():
|
||||||
# Falls es von forward_sms_from_this_number kommt, machen wir ein Foward an
|
# Falls es von forward_sms_from_this_number kommt, machen wir ein Foward an
|
||||||
# die Master Nummer
|
# die Master Nummer
|
||||||
if phonenumber == config_data['forward_sms_from_this_number']:
|
if phonenumber == config_data['forward_sms_from_this_number']:
|
||||||
print("AAA: %s" % (message))
|
|
||||||
#send_mail(config_data['mailfrom'],config_data['mailto'],'Beielimon Subject',message,[])
|
|
||||||
send_sms([config_data['master_sms_number']],message)
|
send_sms([config_data['master_sms_number']],message)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,325 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
# vim: expandtab sw=4 ts=4 sts=4:
|
||||||
|
#
|
||||||
|
# Beehive-Monitoring, process SMS Requests
|
||||||
|
#
|
||||||
|
# Author: Joerg Lehmann, nbit Informatik GmbH
|
||||||
|
#
|
||||||
|
"""Beehive Monitoring - SMS Processing"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import gammu
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import yaml
|
||||||
|
import smtplib
|
||||||
|
import re
|
||||||
|
import glob
|
||||||
|
import shutil
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
from os.path import basename
|
||||||
|
from email.mime.application import MIMEApplication
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.utils import COMMASPACE, formatdate
|
||||||
|
|
||||||
|
# Root Path
|
||||||
|
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
|
||||||
|
# Set Default Encoding to UTF-8
|
||||||
|
reload(sys) # Reload does the trick!
|
||||||
|
sys.setdefaultencoding('UTF8')
|
||||||
|
print(sys.getdefaultencoding())
|
||||||
|
|
||||||
|
# State Machine fuer Gammu
|
||||||
|
sm = gammu.StateMachine()
|
||||||
|
|
||||||
|
# Read Configuration from YAML-File
|
||||||
|
with open("%s/bin/beielimon-config.yaml" % APP_ROOT, 'r') as stream:
|
||||||
|
try:
|
||||||
|
config_data = yaml.load(stream)
|
||||||
|
except yaml.YAMLError as exc:
|
||||||
|
print(exc)
|
||||||
|
|
||||||
|
def send_sms(phonenumbers , text):
|
||||||
|
for phonenumber in phonenumbers:
|
||||||
|
message = {
|
||||||
|
'Text': text,
|
||||||
|
'SMSC': {'Location': 1},
|
||||||
|
'Number': phonenumber
|
||||||
|
}
|
||||||
|
|
||||||
|
#GELD SPAREN smsd.InjectSMS([message])
|
||||||
|
sm.SendSMS(message)
|
||||||
|
print("Send SMS to %s, Text: %s" % (phonenumber, text))
|
||||||
|
|
||||||
|
def send_mail(send_from, send_to, subject, text, files=None):
|
||||||
|
sm.Terminate()
|
||||||
|
os.system('/usr/bin/sudo %s/root-bin/connect_to_internet' % (APP_ROOT))
|
||||||
|
msg = MIMEMultipart()
|
||||||
|
msg['From'] = send_from
|
||||||
|
msg['To'] = send_to
|
||||||
|
msg['Date'] = formatdate(localtime=True)
|
||||||
|
msg['Subject'] = subject
|
||||||
|
|
||||||
|
msg.attach(MIMEText(text))
|
||||||
|
|
||||||
|
for f in files or []:
|
||||||
|
with open(f, "rb") as fil:
|
||||||
|
part = MIMEApplication(
|
||||||
|
fil.read(),
|
||||||
|
Name=basename(f)
|
||||||
|
)
|
||||||
|
# After the file is closed
|
||||||
|
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
|
||||||
|
msg.attach(part)
|
||||||
|
|
||||||
|
smtp = smtplib.SMTP(config_data['mailserver'],config_data['mailserver_port'],timeout=60)
|
||||||
|
smtp.set_debuglevel(1)
|
||||||
|
smtp.ehlo()
|
||||||
|
smtp.starttls()
|
||||||
|
smtp.login(config_data['mailuser'], config_data['mailpwd'])
|
||||||
|
smtp.sendmail(send_from, send_to, msg.as_string())
|
||||||
|
smtp.close()
|
||||||
|
os.system('/usr/bin/sudo %s/root-bin/disconnect_from_internet' % (APP_ROOT))
|
||||||
|
# Wir reinitialisieren das Modem
|
||||||
|
sm.Init()
|
||||||
|
|
||||||
|
def send_help(phonenumber,command):
|
||||||
|
# SMS Maximale Groesse: 140 Zeichen
|
||||||
|
if command == '':
|
||||||
|
sms_message = """Moegliche Befehle:
|
||||||
|
|
||||||
|
help, info, balance, reboot, shutdown, hotspot
|
||||||
|
|
||||||
|
Naehere Hilfe: help <befehl>, z.B. help info"""
|
||||||
|
|
||||||
|
elif command == 'info':
|
||||||
|
sms_message = """info - letzte Messwerte (SMS)
|
||||||
|
info 2017 - Messwerte 2017 (EMail)
|
||||||
|
info 201711 - Messwerte Nov. 2017
|
||||||
|
info 20171102 - Messwerte 2. Nov. 2017"""
|
||||||
|
|
||||||
|
elif command == 'help':
|
||||||
|
sms_message = "Zeigt die moeglichen Befehle an"
|
||||||
|
|
||||||
|
elif command == 'balance':
|
||||||
|
sms_message = "Anforderung Info zum Prepaid-Guthaben"
|
||||||
|
|
||||||
|
elif command == 'reboot':
|
||||||
|
sms_message = "Neustart des Raspberry Pi's"
|
||||||
|
|
||||||
|
elif command == 'shutdown':
|
||||||
|
sms_message = """Herunterfahren des Raspberry Pi's
|
||||||
|
|
||||||
|
ACHTUNG: ZUM STARTEN MUSS STROM AUS- UND WIEDER EINGESTECKT WERDEN!
|
||||||
|
"""
|
||||||
|
|
||||||
|
elif command == 'hotspot':
|
||||||
|
sms_message = """hotspot on - Hotspot Funktion einschalten
|
||||||
|
hotspot off - Hotspot ausschalten
|
||||||
|
|
||||||
|
Hotspot erlaubt ein Auslesen per Smartphone/Table (WLAN)"""
|
||||||
|
|
||||||
|
send_sms([phonenumber],sms_message)
|
||||||
|
|
||||||
|
|
||||||
|
def GetLastValues(scale_uuid):
|
||||||
|
files = glob.glob("%s/data/weight-%s-????????.log" % (APP_ROOT,scale_uuid))
|
||||||
|
if len(files) > 0:
|
||||||
|
with open(sorted(files)[-1], "r") as f:
|
||||||
|
for line in f: pass
|
||||||
|
result = line
|
||||||
|
|
||||||
|
|
||||||
|
# Beispiel: 2017-11-07 08:23,0
|
||||||
|
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d),(\d+)", result)
|
||||||
|
if m:
|
||||||
|
return "%sg (%s.%s.%s %s)" % (m.group(5),m.group(3),m.group(2),m.group(1),m.group(4))
|
||||||
|
else:
|
||||||
|
return "Fehler beim Parsen: %s" % (result)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return "keine Messwerte"
|
||||||
|
|
||||||
|
def CreateAttachements(infotime):
|
||||||
|
mypid = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(7))
|
||||||
|
mycsvdir = "%s/tmp/%s/csv" % (APP_ROOT,mypid)
|
||||||
|
if not os.path.exists(mycsvdir):
|
||||||
|
os.makedirs(mycsvdir)
|
||||||
|
myzipdir = "%s/tmp/%s/zip" % (APP_ROOT,mypid)
|
||||||
|
if not os.path.exists(myzipdir):
|
||||||
|
os.makedirs(myzipdir)
|
||||||
|
res = []
|
||||||
|
my_pattern = '%s%s' % (infotime,'?' * (8 - len(infotime)))
|
||||||
|
files = glob.glob("%s/data/weight-*-%s.log" % (APP_ROOT,my_pattern))
|
||||||
|
for s in config_data['scales']:
|
||||||
|
filename = "%s/%s-%s.csv" % (mycsvdir,s['alias'].replace(' ','_'),infotime)
|
||||||
|
with_data = False
|
||||||
|
with open(filename, 'a') as file:
|
||||||
|
for ifile in sorted(files):
|
||||||
|
if (s['scale_uuid'] in ifile) and (infotime in ifile):
|
||||||
|
with_data = True
|
||||||
|
with open(ifile, 'r') as ifile:
|
||||||
|
for line in ifile:
|
||||||
|
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d),(\d+)", line)
|
||||||
|
if m:
|
||||||
|
file.write("%s.%s.%s %s,%s\n" % (m.group(3),m.group(2),m.group(1),m.group(4),m.group(5)))
|
||||||
|
else:
|
||||||
|
file.write("Fehler beim Parsen: %s" % (line))
|
||||||
|
if with_data:
|
||||||
|
res.append(filename)
|
||||||
|
|
||||||
|
zipfile = "%s/%s" % (myzipdir,infotime)
|
||||||
|
shutil.make_archive(zipfile, 'zip', mycsvdir)
|
||||||
|
return [ "%s.zip" % (zipfile) ]
|
||||||
|
|
||||||
|
def send_report(infotime):
|
||||||
|
# Send EMail Report
|
||||||
|
my_text = my_text = "Letzte Messwerte:\n"
|
||||||
|
for s in config_data['scales']:
|
||||||
|
my_text += "%s: %s\n" % (s['alias'],GetLastValues(s['scale_uuid']))
|
||||||
|
my_text += "\n\nIm ZIP-File sind die Messwerte der gewuenschten Periode enthalten. Die Daten sind im CSV-Format abgespeichert und koennen z.B. mit Excel analysiert werden.\n"
|
||||||
|
attachements = CreateAttachements(infotime)
|
||||||
|
|
||||||
|
send_mail(config_data['mailfrom'],config_data['mailto'],'Messwerte BeieliPi',my_text,attachements)
|
||||||
|
|
||||||
|
def send_info_sms(phonenumber):
|
||||||
|
my_text = "Letzte Messwerte:\n"
|
||||||
|
for s in config_data['scales']:
|
||||||
|
my_text += "%s: %s\n" % (s['alias'],GetLastValues(s['scale_uuid']))
|
||||||
|
|
||||||
|
send_sms([phonenumber],my_text)
|
||||||
|
|
||||||
|
def send_info(phonenumber, message_uc):
|
||||||
|
print("AAA: send_info %s" % message_uc)
|
||||||
|
m = re.match(".*(INFO)\s+(\d{8})", message_uc)
|
||||||
|
if m:
|
||||||
|
send_report(m.group(2))
|
||||||
|
print("BBB: send_info %s" % message_uc)
|
||||||
|
else:
|
||||||
|
m = re.match(".*(INFO)\s+(\d{6})", message_uc)
|
||||||
|
if m:
|
||||||
|
send_report(m.group(2))
|
||||||
|
print("CCC: send_info %s %s" % (message_uc,m.group(2)))
|
||||||
|
else:
|
||||||
|
m = re.match(".*(INFO)\s+(\d{4})", message_uc)
|
||||||
|
if m:
|
||||||
|
send_report(m.group(2))
|
||||||
|
print("DDD: send_info %s" % message_uc)
|
||||||
|
else:
|
||||||
|
send_info_sms(phonenumber)
|
||||||
|
print("EEE: send_info %s" % message_uc)
|
||||||
|
|
||||||
|
def balance():
|
||||||
|
send_sms([config_data['balance_number']],config_data['balance_command'])
|
||||||
|
|
||||||
|
def reboot():
|
||||||
|
os.system('/usr/bin/sudo /sbin/init 6')
|
||||||
|
|
||||||
|
def shutdown():
|
||||||
|
os.system('/usr/bin/sudo /sbin/init 0')
|
||||||
|
|
||||||
|
def hotspot_on():
|
||||||
|
os.system('/usr/bin/sudo %s/root-bin/hotspot_on' % (APP_ROOT))
|
||||||
|
|
||||||
|
def hotspot_off():
|
||||||
|
os.system('/usr/bin/sudo %s/root-bin/hotspot_off' % (APP_ROOT))
|
||||||
|
|
||||||
|
def command_not_understood(phonenumber, message):
|
||||||
|
send_sms([phonenumber],'Befehl nicht verstanden: %s\n\nMoegliche Befehle: help, info, balance, reboot, shutdown, hotspot' % (message[:50]))
|
||||||
|
|
||||||
|
|
||||||
|
def process_received_sms(phonenumber,message):
|
||||||
|
# Falls es von forward_sms_from_this_number kommt, machen wir ein Foward an
|
||||||
|
# die Master Nummer
|
||||||
|
if phonenumber == config_data['forward_sms_from_this_number']:
|
||||||
|
send_sms([config_data['master_sms_number']],message)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# message in Grossbuchstaben (damit Gross-/Kleinschreibung keine Rolle spielt)
|
||||||
|
message_uc = message.upper()
|
||||||
|
|
||||||
|
# Bestimmung, ob es eine gueltige Telefonnummer ist
|
||||||
|
valid_number = False
|
||||||
|
for s in config_data['scales']:
|
||||||
|
if phonenumber in s['sms_alert_phonenumbers']:
|
||||||
|
valid_number = True
|
||||||
|
|
||||||
|
if not valid_number:
|
||||||
|
print("Da versucht ein unberechtigter, etwas abzufragen... (Nummer: %s)" % (phonenumber))
|
||||||
|
return
|
||||||
|
|
||||||
|
if 'HELP INFO' in message_uc:
|
||||||
|
send_help(phonenumber,'info')
|
||||||
|
elif 'HELP HELP' in message_uc:
|
||||||
|
send_help(phonenumber,'help')
|
||||||
|
elif 'HELP BALANCE' in message_uc:
|
||||||
|
send_help(phonenumber,'balance')
|
||||||
|
elif 'HELP REBOOT' in message_uc:
|
||||||
|
send_help(phonenumber,'reboot')
|
||||||
|
elif 'HELP SHUTDOWN' in message_uc:
|
||||||
|
send_help(phonenumber,'shutdown')
|
||||||
|
elif 'HELP HOTSPOT' in message_uc:
|
||||||
|
send_help(phonenumber,'hotspot')
|
||||||
|
elif 'HELP' in message_uc:
|
||||||
|
send_help(phonenumber,'')
|
||||||
|
elif 'INFO' in message_uc:
|
||||||
|
send_info(phonenumber, message_uc)
|
||||||
|
elif 'BALANCE' in message_uc:
|
||||||
|
balance()
|
||||||
|
elif 'REBOOT' in message_uc:
|
||||||
|
reboot()
|
||||||
|
elif 'SHUTDOWN' in message_uc:
|
||||||
|
shutdown()
|
||||||
|
elif 'HOTSPOT OFF' in message_uc:
|
||||||
|
hotspot_off()
|
||||||
|
elif 'HOTSPOT ON' in message_uc:
|
||||||
|
hotspot_on()
|
||||||
|
else:
|
||||||
|
command_not_understood(phonenumber, message)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sm.ReadConfig()
|
||||||
|
sm.Init()
|
||||||
|
counter = 9999
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
counter += 1
|
||||||
|
if counter > 1000:
|
||||||
|
# Wir synchronisren die Zeit mit dem Internet
|
||||||
|
sm.Terminate()
|
||||||
|
os.system('/usr/bin/sudo %s/root-bin/sync_time_with_internet' % (APP_ROOT))
|
||||||
|
sm.Init()
|
||||||
|
counter = 0
|
||||||
|
status = sm.GetSMSStatus()
|
||||||
|
print(status)
|
||||||
|
remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed']
|
||||||
|
|
||||||
|
print("remain: %d\n" % (remain))
|
||||||
|
|
||||||
|
if remain:
|
||||||
|
firstsms = sm.GetNextSMS(Start = True, Folder = 0)
|
||||||
|
print("FIRSTSMS: %s" % (firstsms))
|
||||||
|
for x in range(len(firstsms)):
|
||||||
|
sm.DeleteSMS(firstsms[x]['Folder'], firstsms[x]['Location'])
|
||||||
|
print("sm.DeleteSMS: %s %s" % (firstsms[x]['Folder'], firstsms[x]['Location']))
|
||||||
|
number = firstsms[x]['Number']
|
||||||
|
message = firstsms[x]['Text']
|
||||||
|
print(number,message)
|
||||||
|
print("process_received_sms %s %s" % (number,message))
|
||||||
|
process_received_sms(number,message)
|
||||||
|
remain = remain - len(firstsms)
|
||||||
|
|
||||||
|
sys.stdout.flush()
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Defaults for gammu-smsd initscript
|
||||||
|
# sourced by /etc/init.d/gammu-smsd
|
||||||
|
# installed at /etc/default/gammu-smsd by the maintainer scripts
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is a POSIX shell fragment
|
||||||
|
#
|
||||||
|
|
||||||
|
# Additional options that are passed to the Daemon.
|
||||||
|
DAEMON_OPTS=""
|
||||||
|
|
||||||
|
# user to use (gammu is default)
|
||||||
|
#USER=gammu
|
||||||
|
USER=beieli
|
||||||
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
#imis/internet is the apn for idea connection
|
||||||
|
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T gprs.swisscom.ch"
|
||||||
|
|
||||||
|
# For Raspberry Pi3 use /dev/ttyS0 as the communication port:
|
||||||
|
/dev/ttyAMA0
|
||||||
|
|
||||||
|
# Baudrate
|
||||||
|
115200
|
||||||
|
|
||||||
|
# Assumes that your IP address is allocated dynamically by the ISP.
|
||||||
|
noipdefault
|
||||||
|
|
||||||
|
# Try to get the name server addresses from the ISP.
|
||||||
|
usepeerdns
|
||||||
|
|
||||||
|
# Use this connection as the default route to the internet.
|
||||||
|
defaultroute
|
||||||
|
|
||||||
|
# Replace any existing default routes
|
||||||
|
replacedefaultroute
|
||||||
|
|
||||||
|
# Makes PPPD "dial again" when the connection is lost.
|
||||||
|
persist
|
||||||
|
|
||||||
|
# Do not ask the remote to authenticate.
|
||||||
|
noauth
|
||||||
|
|
||||||
|
# No hardware flow control on the serial link with GSM Modem
|
||||||
|
nocrtscts
|
||||||
|
|
||||||
|
# No modem control lines with GSM Modem
|
||||||
|
local
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
beieli ALL=(ALL) NOPASSWD: /sbin/init,/home/beieli/root-bin/connect_to_internet,/home/beieli/root-bin/disconnect_from_internet,/home/beieli/root-bin/hotspot_on,/home/beieli/root-bin/hotspot_off
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
[Unit]
|
||||||
|
Description=SMS daemon for Gammu
|
||||||
|
Documentation=man:gammu-smsd(1)
|
||||||
|
After=mysql.service postgresql.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
EnvironmentFile=-/etc/sysconfig/gammu-smsd
|
||||||
|
# Run daemon as root user
|
||||||
|
#ExecStart=/usr/bin/gammu-smsd --pid=/var/run/gammu-smsd.pid --daemon
|
||||||
|
# Run daemon as non-root user (set user/group in /etc/sysconfig/gammu-smsd)
|
||||||
|
ExecStart=/usr/bin/gammu-smsd --user=beieli --group=gammu --pid=/var/run/gammu-smsd.pid --daemon
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
ExecStopPost=/bin/rm -f /var/run/gammu-smsd.pid
|
||||||
|
Type=forking
|
||||||
|
PIDFile=/var/run/gammu-smsd.pid
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
systemctl stop gammu-smsd
|
echo "$(date): Connect to Internet..."
|
||||||
|
#systemctl stop gammu-smsd
|
||||||
pon rnet
|
pon rnet
|
||||||
sleep 3
|
sleep 20
|
||||||
# Nameserver statisch eintragen...
|
|
||||||
echo "nameserver 8.8.8.8" >/etc/resolv.conf
|
# Wait until connection is established
|
||||||
|
if ping -c 1 8.8.8.8 &>/dev/null ; then
|
||||||
|
echo "Already Connected - $(date)"
|
||||||
|
else
|
||||||
|
echo "Not Connected - $( date )"
|
||||||
|
echo "connecting wait ..."
|
||||||
|
sleep 20
|
||||||
|
fi
|
||||||
|
|
||||||
# Wir wollen sicher sein, dass die Verbindung steht...
|
# Wir wollen sicher sein, dass die Verbindung steht...
|
||||||
ping -c 1 -w 30 8.8.8.8 >/dev/null
|
ping -c 1 -w 30 8.8.8.8 >/dev/null
|
||||||
|
sleep 3
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
echo "$(date): Disconnect from Internet..."
|
||||||
poff rnet
|
poff rnet
|
||||||
systemctl start gammu-smsd
|
sleep 10
|
||||||
|
#systemctl start gammu-smsd
|
||||||
|
pkill pppd
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
PROGRAM=/home/beieli/bin/process_sms_request.py
|
PROGRAM=/home/beieli/bin/process_sms_request.py
|
||||||
echo "Received $SMS_MESSAGES physical messages and $DECODED_PARTS of decoded message parts" >> /home/beieli/log/process_sms_request.log
|
echo "Received $SMS_MESSAGES physical messages and $DECODED_PARTS of decoded message parts" >> /tmp/process_sms_request.log 2>&1
|
||||||
for i in `seq $SMS_MESSAGES` ; do
|
for i in `seq $SMS_MESSAGES` ; do
|
||||||
eval "$PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\" >>/home/beieli/log/process_sms_request.log"
|
eval "/usr/bin/sudo -u beieli $PROGRAM \"\${SMS_${i}_NUMBER}\" \"\${SMS_${i}_TEXT}\" >> /tmp/process_sms_request.log 2>&1"
|
||||||
done
|
done
|
||||||
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
/home/beieli/root-bin/connect_to_internet
|
||||||
|
/usr/sbin/ntpdate 3.de.pool.ntp.org
|
||||||
|
/home/beieli/root-bin/disconnect_from_internet
|
||||||
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="description" content="mini-beieli.ch - Bienenstock-Monitoring">
|
<meta name="description" content="BeieliPi - Bienenstock-Monitoring">
|
||||||
<meta name="author" content="Joerg Lehmann, nbit Informatik GmbH">
|
<meta name="author" content="Joerg Lehmann, nbit Informatik GmbH">
|
||||||
<link rel="icon" href="/static/images/favicon.ico">
|
<link rel="icon" href="/static/images/favicon.ico">
|
||||||
<title>mini-beieli.ch - Bienenstock-Monitoring</title>
|
<title>BeieliPi - Messkurve für {{ scale_alias }}</title>
|
||||||
|
|
||||||
<script type="text/javascript" src="/static/js/dygraph.js"></script>
|
<script type="text/javascript" src="/static/js/dygraph.js"></script>
|
||||||
<link rel="stylesheet" src="/static/css/dygraph.css" />
|
<link rel="stylesheet" src="/static/css/dygraph.css" />
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<meta name="description" content="BeieliPi - Bienenstock-Monitoring">
|
<meta name="description" content="BeieliPi - Bienenstock-Monitoring">
|
||||||
<meta name="author" content="Joerg Lehmann, nbit Informatik GmbH">
|
<meta name="author" content="Joerg Lehmann, nbit Informatik GmbH">
|
||||||
<link rel="icon" href="/static/images/favicon.ico">
|
<link rel="icon" href="/static/images/favicon.ico">
|
||||||
<title>BeieliPi - Bienenstock-Monitoring</title>
|
<title>BeieliPi - Upload der Konfiguration</title>
|
||||||
|
|
||||||
<link href="/static/dist/toolkit.min.css" rel="stylesheet">
|
<link href="/static/dist/toolkit.min.css" rel="stylesheet">
|
||||||
<link href="/static/css/customize.css" rel="stylesheet">
|
<link href="/static/css/customize.css" rel="stylesheet">
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
<nav class="navbar nav-pills navbar-default">
|
<nav class="navbar nav-pills navbar-default">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h3>BeieliPi Upload Konfiguraion</h3>
|
<h3>BeieliPi Upload Konfiguration</h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="navbar-collapse collapse">
|
<div id="navbar" class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
|
@ -32,11 +32,16 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<div class="jumbotron container-fluid myjumbotron">
|
<div class="jumbotron container-fluid myjumbotron">
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<strong>ACHTUNG</strong> - diese Operation ist potentiell gefährlich! Wenn die Konfiguration erfolgreich hochgeladen wurde muss der BeieliPi neu gestartet werden. Am einfachsten geht das mit der URL http://beielipi.local/reboot_beielipi.
|
||||||
|
</div>
|
||||||
|
% if message != "":
|
||||||
<div class="alert alert-{{ level }}">
|
<div class="alert alert-{{ level }}">
|
||||||
{{ message }}
|
{{ message }}
|
||||||
</div>
|
</div>
|
||||||
|
% end
|
||||||
<form action="/upload_config" method="post">
|
<form action="/upload_config" method="post">
|
||||||
<textarea name="config_yaml" cols="80" rows="30"></textarea>
|
<textarea name="config_yaml" class="form-control" rows="30"></textarea>
|
||||||
<br />
|
<br />
|
||||||
<input value="Update Konfiguration" type="submit" />
|
<input value="Update Konfiguration" type="submit" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue