diverse Anpassungen
This commit is contained in:
parent
e3e1387117
commit
4610ba3792
|
|
@ -0,0 +1,262 @@
|
|||
## RASPBERRY PI ALS ZENTRALRECHNER FUER BIENENSTOCKUEBERWACHUNG
|
||||
|
||||
# Hardware Variante A
|
||||
- Raspberry Pi Zero W
|
||||
- 3G Stick Huawei E3531
|
||||
|
||||
|
||||
# Hardware Variante B (Kurt Jakob)
|
||||
- Raspberry Pi 3 Model B
|
||||
- Itead Raspberry Pi GSM/GPRS Board (SIM800)
|
||||
- ModMyPi Itead GSM Board Gehäuse
|
||||
|
||||
|
||||
## INSTALLATION
|
||||
|
||||
Image: 2017-09-07-raspbian-stretch-lite.zip
|
||||
|
||||
Installation auf SD:
|
||||
# unzip -p 2017-09-07-raspbian-stretch-lite.zip |dd of=/dev/sdXXX bs=4M conv=fsync
|
||||
|
||||
# raspi-config
|
||||
- Change User Password: meielis-...
|
||||
- Hostname: beielipi
|
||||
- locale: en_US.utf8 (auch Default)
|
||||
- locale: de_CH.utf8
|
||||
- Timezone: Europe/Zurich
|
||||
- Change Wifi Country: CH
|
||||
- Keyboard: Generic 105-key (Intl), German (Switzerland)
|
||||
|
||||
# cat /etc/wpa_supplicant/wpa_supplicant.conf
|
||||
country=CH
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
|
||||
network={
|
||||
ssid="haerdoepfu27"
|
||||
psk="XXXXXXXXXXXX"
|
||||
}
|
||||
|
||||
# apt-get update
|
||||
# apt-get upgrade
|
||||
|
||||
Software installieren:
|
||||
# apt-get install gammu gammu-smsd python-gammu
|
||||
# apt-get install python-serial
|
||||
# apt-get install python-yaml
|
||||
# apt-get install minicom
|
||||
# apt-get install ppp
|
||||
# apt-get install python-pexpect
|
||||
|
||||
|
||||
### Variante A
|
||||
Einrichten GSM:
|
||||
|
||||
/etc/usb_modeswitch.d/12d1:1f01:
|
||||
# Huawei E353 (3.se)
|
||||
|
||||
DefaultVendor=0x12d1
|
||||
DefaultProduct=0x1f01
|
||||
TargetVendor=0x12d1
|
||||
TargetProduct=0x1f01
|
||||
|
||||
MessageContent="55534243123456780000000000000011062000000100000000000000000000"
|
||||
NoDriverLoading=1
|
||||
|
||||
|
||||
/root/.gammurc:
|
||||
; Configuration file generated by gammu-detect.
|
||||
; Please check The Gammu Manual for more information.
|
||||
|
||||
[gammu]
|
||||
device = /dev/ttyUSB0
|
||||
name = Phone on USB serial port HUAWEI HUAWEI_Mobile
|
||||
connection = at
|
||||
|
||||
[gammu1]
|
||||
device = /dev/ttyUSB1
|
||||
name = Phone on USB serial port HUAWEI HUAWEI_Mobile
|
||||
connection = at
|
||||
|
||||
[gammu2]
|
||||
device = /dev/ttyUSB2
|
||||
name = Phone on USB serial port HUAWEI HUAWEI_Mobile
|
||||
connection = at
|
||||
|
||||
|
||||
Quick Tutorial Gammu:
|
||||
https://wammu.eu/docs/manual/quick/index.html
|
||||
|
||||
Test SMS-Versand:
|
||||
gammu sendsms TEXT 0765006123 -text "Halooo von beielipi"
|
||||
|
||||
|
||||
|
||||
### Variante B
|
||||
|
||||
Wie Raspberry Zero, jedoch folgende Besonderheiten:
|
||||
|
||||
# systemctl disable hciuart.service
|
||||
|
||||
root@beielipi:/etc/cron.d# more gsm_poweron
|
||||
@reboot root /usr/local/bin/gsm_poweron.py
|
||||
|
||||
|
||||
root@beielipi:~# cat /usr/local/bin/gsm_poweron.py
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# GSM-Modul anschalten, falls ein keine Antwort gibt...
|
||||
#
|
||||
import time
|
||||
import RPi.GPIO as GPIO
|
||||
import serial
|
||||
|
||||
def PowerOn():
|
||||
# RPi.GPIO Layout verwenden (wie Pin-Nummern)
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
|
||||
# Pin 11 (GPIO 17) auf Output setzen
|
||||
GPIO.setup(11, GPIO.OUT)
|
||||
|
||||
# Druecken simulieren
|
||||
GPIO.output(11, GPIO.HIGH)
|
||||
|
||||
# Pause, mindestens eine Sekunde gemaess https://www.itead.cc/wiki/RPI_SIM800_GSM/GPRS_ADD-ON_V2.0
|
||||
time.sleep(1.5)
|
||||
|
||||
# Weg vom Taster...
|
||||
GPIO.output(11, GPIO.LOW)
|
||||
|
||||
# Cleanup
|
||||
GPIO.cleanup()
|
||||
|
||||
with serial.Serial('/dev/ttyAMA0', 115200, timeout=2) as ser:
|
||||
ser.write(b'AT\n')
|
||||
line = ser.readline()
|
||||
line = ser.readline()
|
||||
print "Feedback: %s" % (line)
|
||||
if line.strip() != "OK":
|
||||
print "Modem reagiert nicht, evtl. abgeschaltet... wir schalten es ein..."
|
||||
PowerOn()
|
||||
ser.close() # close port
|
||||
===
|
||||
|
||||
root@beielipi:~# cat /boot/config.txt
|
||||
...
|
||||
# Wegen GSM Modul
|
||||
dtoverlay=pi3-miniuart-bt
|
||||
#dtoverlay=pi3-disable-bt
|
||||
enable_uart=1
|
||||
===
|
||||
|
||||
root@beielipi:~# cat /boot/cmdline.txt
|
||||
dwc_otg.lpm_enable=0 root=PARTUUID=61612258-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
|
||||
===
|
||||
|
||||
|
||||
root@beielipi:~# cat /root/.gammurc
|
||||
; Diese Konfigurationsdatei wurde von gammu-detect erstellt.
|
||||
; Bitte lesen Sie das Gammu-Benutzerhandbuch für weitere Informationen.
|
||||
|
||||
[gammu]
|
||||
device = /dev/ttyAMA0
|
||||
name = Telefon an serielle USB-Schnittstelle Silicon_Labs CP2102_USB_to_UART_Bri
|
||||
dge_Controller angeschlossen
|
||||
connection = at
|
||||
pin = 8296
|
||||
|
||||
===
|
||||
|
||||
|
||||
SMS senden:
|
||||
|
||||
$ gammu-smsd-inject TEXT 0765006123 -text "Hallo Velo"
|
||||
|
||||
|
||||
|
||||
root@beielipi:/tmp# cat /etc/gammu-smsdrc
|
||||
# Configuration file for Gammu SMS Daemon
|
||||
|
||||
# Gammu library configuration, see gammurc(5)
|
||||
[gammu]
|
||||
# Please configure this!
|
||||
port = /dev/ttyAMA0
|
||||
connection = at
|
||||
# Debugging
|
||||
#logformat = textall
|
||||
logformat = errorsdate
|
||||
pin = 8296
|
||||
|
||||
# SMSD configuration, see gammu-smsdrc(5)
|
||||
[smsd]
|
||||
service = files
|
||||
#logfile = syslog
|
||||
# Increase for debugging information
|
||||
debuglevel = 0
|
||||
PIN = 8296
|
||||
RunOnReceive = /usr/local/bin/run_on_receive.sh
|
||||
|
||||
# Paths where messages are stored
|
||||
inboxpath = /var/spool/gammu/inbox/
|
||||
outboxpath = /var/spool/gammu/outbox/
|
||||
sentsmspath = /var/spool/gammu/sent/
|
||||
errorsmspath = /var/spool/gammu/error/
|
||||
===
|
||||
|
||||
|
||||
## Blabla
|
||||
|
||||
User/Gruppe erstellen:
|
||||
# groupadd -g 2000 beieli
|
||||
# useradd -m -g beieli beieli -s /bin/bash
|
||||
# usermod -a -G gammu beieli
|
||||
# usermod -a -G dialout beieli
|
||||
|
||||
Passwoerter anpassen:
|
||||
# passwd pi => meielis-...
|
||||
|
||||
|
||||
|
||||
|
||||
root@beielipi:~# rpi-update
|
||||
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||
*** Performing self-update
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 13403 100 13403 0 0 25182 0 --:--:-- --:--:-- --:--:-- 25193
|
||||
*** Relaunching after update
|
||||
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||
*** We're running for the first time
|
||||
*** Backing up files (this will take a few minutes)
|
||||
*** Backing up firmware
|
||||
*** Backing up modules 4.9.41+
|
||||
#############################################################
|
||||
This update bumps to rpi-4.9.y linux tree
|
||||
Be aware there could be compatibility issues with some drivers
|
||||
Discussion here:
|
||||
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=167934
|
||||
##############################################################
|
||||
*** Downloading specific firmware revision (this will take a few minutes)
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 168 0 168 0 0 25 0 --:--:-- 0:00:06 --:--:-- 35
|
||||
100 54.1M 100 54.1M 0 0 989k 0 0:00:56 0:00:56 --:--:-- 1153k
|
||||
*** Updating firmware
|
||||
*** Updating kernel modules
|
||||
*** depmod 4.9.50-v7+
|
||||
*** depmod 4.9.50+
|
||||
*** Updating VideoCore libraries
|
||||
*** Using HardFP libraries
|
||||
*** Updating SDK
|
||||
*** Running ldconfig
|
||||
*** Storing current firmware revision
|
||||
*** Deleting downloaded files
|
||||
*** Syncing changes to disk
|
||||
*** If no errors appeared, your firmware was successfully updated to a31db890da1e5135fe666909d562bdc6113c14d6
|
||||
*** A reboot is needed to activate the new firmware
|
||||
root@beielipi:~#
|
||||
root@beielipi:~# init 6
|
||||
Connection to 192.168.0.34 closed by remote host.
|
||||
Connection to 192.168.0.34 closed.
|
||||
|
||||
|
||||
|
|
@ -43,8 +43,8 @@ def send_sms(phonenumbers , text):
|
|||
'Number': phonenumber
|
||||
}
|
||||
|
||||
#os.system('echo "%s" | /usr/bin/gammu-smsd-inject TEXT %s' % (text,phonenumber))
|
||||
print("YYY Send SMS to %s, Text: %s" % (phonenumber, text))
|
||||
os.system('echo "%s" | /usr/bin/gammu-smsd-inject TEXT %s' % (text,phonenumber))
|
||||
#print("YYY Send SMS to %s, Text: %s" % (phonenumber, text))
|
||||
|
||||
def send_mail(send_from, send_to, subject, text, files=None):
|
||||
os.system('/usr/bin/sudo %s/root-bin/connect_to_internet' % (APP_ROOT))
|
||||
|
|
@ -211,10 +211,10 @@ 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))
|
||||
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))
|
||||
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]))
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
@reboot root /usr/local/bin/gsm_poweron.py
|
||||
@reboot root /home/beieli/root-bin/gsm_poweron.py
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@
|
|||
systemctl stop gammu-smsd
|
||||
pon rnet
|
||||
sleep 3
|
||||
# Nameserver statisch eintragen...
|
||||
echo "nameserver 8.8.8.8" >/etc/resolv.conf
|
||||
# Wir wollen sicher sein, dass die Verbindung steht...
|
||||
ping -c 1 -w 30 8.8.8.8 >/dev/null
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
from bottle import Bottle, run, template, static_file, error, redirect
|
||||
from bottle import Bottle, run, template, static_file, error, redirect, post, request
|
||||
import yaml
|
||||
import glob
|
||||
import re
|
||||
|
|
@ -8,6 +8,7 @@ import random
|
|||
import string
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
app = Bottle()
|
||||
|
||||
|
|
@ -88,6 +89,39 @@ def CreateDatafile(scale_uuid,infotime):
|
|||
for line in ifile:
|
||||
file.write(line)
|
||||
|
||||
def GetInfoText():
|
||||
with open('%s/bin/beielimon-config.yaml' % (APP_ROOT), 'r') as f:
|
||||
config_file_lines = f.read()
|
||||
|
||||
# Wir maskieren das Passwort
|
||||
config_file_lines = re.sub(r"mailpwd:.*\n", "mailpwd: MASKED\n", config_file_lines)
|
||||
|
||||
commands_output = ""
|
||||
for comm_arr in [ ['uptime','--pretty'],
|
||||
['df','-h','/boot','/root'],
|
||||
['free','-m'],
|
||||
['ip','a'] ]:
|
||||
commands_output = "%s\n# %s\n%s" % (commands_output,' '.join(comm_arr),subprocess.check_output(comm_arr))
|
||||
|
||||
res = """Konfigurationsfile:<br />
|
||||
|
||||
<pre>%s</pre>
|
||||
|
||||
Diverse Befehle: <pre>%s</pre>
|
||||
|
||||
""" % (config_file_lines, commands_output)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def is_valid_yaml(yaml_string):
|
||||
res = True
|
||||
try:
|
||||
data_parsed = yaml.safe_load(yaml_string)
|
||||
except yaml.YAMLError:
|
||||
res = False
|
||||
|
||||
return res
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
|
|
@ -95,11 +129,40 @@ def index():
|
|||
data = {
|
||||
'scales': hash_scales,
|
||||
'infotime': time.strftime("%Y", time.localtime()),
|
||||
'beielipi_mobile_number': config_data['beielipi_mobile_number']
|
||||
'beielipi_mobile_number': config_data['beielipi_mobile_number'],
|
||||
'infotext': GetInfoText()
|
||||
}
|
||||
|
||||
return template('%s/web-root/index.tpl' % (APP_ROOT), data)
|
||||
|
||||
@app.get('/upload_config')
|
||||
def upload_config():
|
||||
my_message = request.GET.get('message', '').strip()
|
||||
my_level = request.GET.get('level', '').strip()
|
||||
data = {
|
||||
'message': my_message,
|
||||
'level': my_level
|
||||
}
|
||||
|
||||
return template('%s/web-root/upload_config.tpl' % (APP_ROOT), data)
|
||||
|
||||
@app.post('/upload_config')
|
||||
def do_upload_config():
|
||||
config_yaml = request.forms.get('config_yaml')
|
||||
if is_valid_yaml(config_yaml):
|
||||
# Wir machen noch ein Backup vor dem Ueberschreiben
|
||||
date_format_string = "+%Y%m%d-%H%M%S"
|
||||
os.system('cp %s/bin/beielimon-config.yaml %s/config-backups/beielimon-config.yaml.$(date %s)' % (APP_ROOT,APP_ROOT,date_format_string))
|
||||
with open('%s/bin/beielimon-config.yaml' % (APP_ROOT), 'w') as file:
|
||||
file.write(string.replace(config_yaml,'\r',''))
|
||||
redirect("/upload_config?message=Konfiguration%20erfolgreich%20ersetzt.%20Bitte%20BeieliPi%20rebooten%20mit%20http%3A%2F%2Fbeielipi.local%2Freboot_beielipi&level=success")
|
||||
else:
|
||||
redirect("/upload_config?message=Fehler%20mit%20YAML-Syntax&level=danger")
|
||||
|
||||
@app.route('/reboot_beielipi')
|
||||
def reboot_beielipi():
|
||||
os.system('/sbin/init 6')
|
||||
|
||||
@app.route('/static/<filepath:path>')
|
||||
def server_static(filepath):
|
||||
return static_file(filepath, root='%s/web-root/static' % (APP_ROOT))
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@
|
|||
<p></p>
|
||||
% end
|
||||
<a href="/download/{{ infotime }}" type="button" class="btn btn-info btn-lg btn-block"><h2>Messdaten herunterladen</h2><small>Lädt Daten des aktuellen Jahres herunter.</small></a>
|
||||
<p></p>
|
||||
<button type="button" class="btn btn-info btn-block" data-toggle="collapse" data-target="#infotext">Zeige Infos zu BeieliPi</button>
|
||||
<div id="infotext" class="collapse">
|
||||
<p></p>
|
||||
{{ !infotext }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="BeieliPi - Bienenstock-Monitoring">
|
||||
<meta name="author" content="Joerg Lehmann, nbit Informatik GmbH">
|
||||
<link rel="icon" href="/static/images/favicon.ico">
|
||||
<title>BeieliPi - Bienenstock-Monitoring</title>
|
||||
|
||||
<link href="/static/dist/toolkit.min.css" rel="stylesheet">
|
||||
<link href="/static/css/customize.css" rel="stylesheet">
|
||||
|
||||
<script src="/static/js/jquery.min.js"></script>
|
||||
<script src="/static/dist/toolkit.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="banner">
|
||||
</div>
|
||||
<nav class="navbar nav-pills navbar-default">
|
||||
<div class="container-fluid">
|
||||
<div class="text-center">
|
||||
<h3>BeieliPi Upload Konfiguraion</h3>
|
||||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="jumbotron container-fluid myjumbotron">
|
||||
<div class="alert alert-{{ level }}">
|
||||
{{ message }}
|
||||
</div>
|
||||
<form action="/upload_config" method="post">
|
||||
<textarea name="config_yaml" cols="80" rows="30"></textarea>
|
||||
<br />
|
||||
<input value="Update Konfiguration" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue