From 9d6d4ad022475adbd1e9219ce954163b1a57b1b2 Mon Sep 17 00:00:00 2001 From: Findus23 Date: Fri, 27 Dec 2013 09:33:23 +0100 Subject: [PATCH] erstmaliges Hochladen --- .gitattributes | 22 +++++ .gitignore | 215 ++++++++++++++++++++++++++++++++++++++++++++++++ Einstellungen | 18 ++++ display.py | 117 ++++++++++++++++++++++++++ dygraphs.html | 46 +++++++++++ export.sh | 82 ++++++++++++++++++ installation.sh | 31 +++++++ rand.sh | 8 ++ transpose.sh | 22 +++++ 9 files changed, 561 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Einstellungen create mode 100644 display.py create mode 100644 dygraphs.html create mode 100644 export.sh create mode 100644 installation.sh create mode 100644 rand.sh create mode 100644 transpose.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/Einstellungen b/Einstellungen new file mode 100644 index 0000000..f3ec7b0 --- /dev/null +++ b/Einstellungen @@ -0,0 +1,18 @@ +# x-Achse enthält Zeitinformation +set xdata time +# Zeitformat zur Eingabe +set timefmt x "%H:%M:%S" +# Zeitformat zur Beschriftung der x-Achse +set format x "%H:%M:%S" +# set nokey #keine Legende +set grid #Gitter anzeigen +# set title "LOAD-Wert" #eventuell Überschrift +set ylabel 'LOAD' +set xlabel 'Uhrzeit' +set y2tics # Zahlen auch auf 2. y-Achse + +plot "daten_gnuplot.txt" using 1:2 title 'LOAD' with lines axes x1y1, \ + "daten_gnuplot.txt" using 1:3 title 'Rand' with lines axes x1y2 +set terminal svg size 1200,800 +set output "gnuplot.svg" +replot diff --git a/display.py b/display.py new file mode 100644 index 0000000..c733552 --- /dev/null +++ b/display.py @@ -0,0 +1,117 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Originales Programm von http://www.schnatterente.net/technik/raspberry-pi-32-zeichen-hitachi-hd44780-display +# von mir modifiziert (Anzeige ausgelagert, ergänzt, um Text aus einer Datei anzuzeigen) +import time +import RPi.GPIO as GPIO + +# Zuordnung der GPIO Pins (ggf. anpassen) +DISPLAY_RS = 7 +DISPLAY_E = 8 +DISPLAY_DATA4 = 25 +DISPLAY_DATA5 = 24 +DISPLAY_DATA6 = 23 +DISPLAY_DATA7 = 18 + + + + +DISPLAY_WIDTH = 16 # Zeichen je Zeile +DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile +DISPLAY_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile +DISPLAY_CHR = True +DISPLAY_CMD = False +E_PULSE = 0.00005 +E_DELAY = 0.00005 + + +def anzeige(): # Anzeige auslagern, um es wiederholt anzuzeigen + lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD) + lcd_string(oben) + lcd_byte(DISPLAY_LINE_2, DISPLAY_CMD) + lcd_string(unten) + +def main(): + GPIO.setmode(GPIO.BCM) + GPIO.setup(DISPLAY_E, GPIO.OUT) + GPIO.setup(DISPLAY_RS, GPIO.OUT) + GPIO.setup(DISPLAY_DATA4, GPIO.OUT) + GPIO.setup(DISPLAY_DATA5, GPIO.OUT) + GPIO.setup(DISPLAY_DATA6, GPIO.OUT) + GPIO.setup(DISPLAY_DATA7, GPIO.OUT) + display_init() + +# GPIO.cleanup() + + + + + +def display_init(): + lcd_byte(0x33,DISPLAY_CMD) + lcd_byte(0x32,DISPLAY_CMD) + lcd_byte(0x28,DISPLAY_CMD) + lcd_byte(0x0C,DISPLAY_CMD) + lcd_byte(0x06,DISPLAY_CMD) + lcd_byte(0x01,DISPLAY_CMD) + +def lcd_string(message): + message = message.ljust(DISPLAY_WIDTH," ") + for i in range(DISPLAY_WIDTH): + lcd_byte(ord(message[i]),DISPLAY_CHR) + +def lcd_byte(bits, mode): + GPIO.output(DISPLAY_RS, mode) + GPIO.output(DISPLAY_DATA4, False) + GPIO.output(DISPLAY_DATA5, False) + GPIO.output(DISPLAY_DATA6, False) + GPIO.output(DISPLAY_DATA7, False) + if bits&0x10==0x10: + GPIO.output(DISPLAY_DATA4, True) + if bits&0x20==0x20: + GPIO.output(DISPLAY_DATA5, True) + if bits&0x40==0x40: + GPIO.output(DISPLAY_DATA6, True) + if bits&0x80==0x80: + GPIO.output(DISPLAY_DATA7, True) + time.sleep(E_DELAY) + GPIO.output(DISPLAY_E, True) + time.sleep(E_PULSE) + GPIO.output(DISPLAY_E, False) + time.sleep(E_DELAY) + GPIO.output(DISPLAY_DATA4, False) + GPIO.output(DISPLAY_DATA5, False) + GPIO.output(DISPLAY_DATA6, False) + GPIO.output(DISPLAY_DATA7, False) + if bits&0x01==0x01: + GPIO.output(DISPLAY_DATA4, True) + if bits&0x02==0x02: + GPIO.output(DISPLAY_DATA5, True) + if bits&0x04==0x04: + GPIO.output(DISPLAY_DATA6, True) + if bits&0x08==0x08: + GPIO.output(DISPLAY_DATA7, True) + time.sleep(E_DELAY) + GPIO.output(DISPLAY_E, True) + time.sleep(E_PULSE) + GPIO.output(DISPLAY_E, False) + time.sleep(E_DELAY) + +#Beginn der Ergaenzung +main() # Initialisierung +Seiten = 4 # hier kann man die Anzahl der Seiten ändern +while True: # endlos wiederholen + Seite = 1 # von Vorne zu zählen beginnen + while Seite <= Seiten: # so lange durchlaufen bis man bei der letzten Seite angekommen ist -> dann von vorne beginnen + zeile1 = (Seite * 2) - 2 # Die obere Zeile ist das Doppelte der Seiten anzahl - 2 (!!! Array fängt bei 0 zu zählen an !!!) + zeile2 = (Seite * 2) - 1 # Die untere Zeile ist das Doppelte der Seiten anzahl - 1 (!!! Array fängt bei 0 zu zählen an !!!) + datei = open("text.txt", "r") # Datei text.txt zum Lesen oeffnen + inhalt = datei.readlines() # alle Zeile lesen und in Array "inhalt" speichern + datei.close() # Datei schliessen + oben = inhalt[zeile1] # die Richtigen Zeilen aus dem Array speichern + unten = inhalt[zeile2] # die Richtigen Zeilen aus dem Array speichern + oben = oben[:-1] # Steuerzeichen am Ende loeschen (erzeugt ein komisches Symbol (|n) am Display) + unten = unten[:-1] # Steuerzeichen am Ende loeschen + anzeige() # oben und unten anzeigen + time.sleep(2) # 2 Sekunden warten + Seite += 1 # Seite um 1 erhöhen diff --git a/dygraphs.html b/dygraphs.html new file mode 100644 index 0000000..22488b9 --- /dev/null +++ b/dygraphs.html @@ -0,0 +1,46 @@ + + + + + + + + +
+
+ + + + diff --git a/export.sh b/export.sh new file mode 100644 index 0000000..f2c90e2 --- /dev/null +++ b/export.sh @@ -0,0 +1,82 @@ +#!/bin/bash +PFAD="/var/www/" +a=0 +Anzahl=0 +Summe=0 +min=$(echo "scale=3; $(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277abe1/w1_slave | awk -F 't=' '{print $2}') / 1000" | bc -l) # Sowohl Minimum als auch Maximum auf die aktuelle Temperatur setzen +max=$min +if [ $1 ] +then + case "$1" in + "-d") echo "" > rohdaten.csv + rm dygraph.csv + ;; + "-h") echo -e "-d csv-Datei leeren \nfür weitere Informationen siehe http://lukaswiki.onpw.de/rasp" + exit 1 + ;; + *) echo "unbekannter Parameter - Für Hilfe -h" + exit + ;; + esac +fi +while true +do + #a=$(($a + $((RANDOM % 10)) - 5)) # a um eine zufällige Zahl zwischen -5 und 5 ändern + ##a=a+[Zufallszahl von 0-32767] modulo 10 (um eine Zahl von 0-10 zu bekommen) -5 (-> -5 bis 5) + #wert2=$a + #wert2=$(cut -c 1,2,3,4 /proc/loadavg) # Load messen + #wert=$(/opt/vc/bin/vcgencmd measure_temp | cut -c 6,7,8,9) #Betriebstemberatur messen + #wert2=$(sensors |grep Core\ 0 |cut -c 18,19,20,21) #CPU-Temperatur, lm-sensors muss installiert sein, bei jedem PC anders + wert1=$(echo "scale=3; $(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277abe1/w1_slave | awk -F 't=' '{print $2}') / 1000" | bc -l) + wert2=$(echo "scale=3; $(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277a5db/w1_slave | awk -F 't=' '{print $2}') / 1000" | bc -l) + wert3=$(echo "scale=3; $(grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-000802b4635f/w1_slave | awk -F 't=' '{print $2}') / 1000" | bc -l) + uhrzeit=$(date +%H:%M:%S) + uhrzeit_dy=$(date +%Y/%m/%d\ %H:%M:%S) + if [ "$wert1" == "-1.250" ] # manchmal gibt der Sensor "-1.250" als Wert zurück -> diese sollen gelöscht werden + then + wert1="" + fi + if [ "$wert2" == "-1.250" ] + then + wert2="" + fi + if [ "$wert3" == "-1.250" ] + then + wert3="" + fi +#Mathematische Auswertung Anfang + Summe=$(echo "$Summe + $wert1" | bc -l) # mithilfe von bc den aktuellen Wert zur Summe aller Werten dazuzählen ... + Anzahl=$(($Anzahl +1)) # ... die Anzahl um 1 erhöhen ... + MW=$(echo "scale=3;$Summe / $Anzahl" | bc -l) # ... und den Mittelwert berechnen + if [ "$(echo "$wert1 < $min" | bc -l)" = "1" ] # Falls der aktuelle Wert kleiner als das Minimum ist ... + then + min=$wert1 # ... soll er zum neuen Minimum werden + fi + if [ "$(echo "$wert1 > $max" | bc -l)" = "1" ] # Wie Minimum + then + max=$wert1 + fi + + +#Mathematische Auswertung Ende + ausgabe=${uhrzeit}\,${wert1}\,${wert2} + ausgabe_dy=${uhrzeit_dy}\,${wert1}\,${wert2}\,${wert3} + echo $ausgabe >>rohdaten.csv + echo $ausgabe_dy >>dygraph.csv + echo "$uhrzeit_dy $wert1 $MW $min $max" #Ausgabe des aktuellen Wertes im Terminal + sed "s/,/ /g" rohdaten.csv >daten_gnuplot.txt #für Gnuplot die Beistriche durch Leerzeichen ersetzen + echo "Uhrzeit:" >text.txt #Anzeige für Display + echo "$uhrzeit" >>text.txt #Anzeige für Display + echo "Temperatur 1" >>text.txt #Anzeige für Display + echo "$wert1" >>text.txt #Anzeige für Display + echo "Temperatur 2" >>text.txt #Anzeige für Display + echo "$wert2" >>text.txt #Anzeige für Display + echo "Aussentemperatur" >>text.txt #Anzeige für Display + echo "$wert3" >>text.txt #Anzeige für Display +# ./transpose.sh #anderes Skript starten, welches die Daten für Highchart vorbereitet +# gnuplot Einstellungen # Gnuplot starten +# sudo cp gnuplot.svg ${PFAD}gnuplot.svg # das generierte Bild ... + sudo cp daten_transformiert.txt ${PFAD}daten_transformiert.txt # ... und die Tabelle für Highchart in den Webordner kopieren + sudo cp dygraph.csv ${PFAD}dygraph.csv + sleep 8 # kurz warten +done diff --git a/installation.sh b/installation.sh new file mode 100644 index 0000000..98b12ff --- /dev/null +++ b/installation.sh @@ -0,0 +1,31 @@ +#!/bin/bash +SKRIPTPFAD=$(pwd) +if [[ -f $(which gnuplot 2>/dev/null) ]] + then + echo "Gnuplot ist installiert" >installation.log + else + dialog --title "Gnuplot" --msgbox "Gnuplot wird im nächsten Schritt installiert. Abbrechen mit STRG+C" 80 80 + sudo apt-get install gnuplot-nox >>installation.log +fi +wget http://lukaswiki.onpw.de/rasp/skripte/export.sh 2>>installation.log +wget http://lukaswiki.onpw.de/rasp/skripte/transpose.sh 2>>installation.log +wget http://lukaswiki.onpw.de/rasp/skripte/Einstellungen 2>>installation.log +chmod 755 export.sh transpose.sh +chmod 644 Einstellungen +dialog --yesno "Sollen die Dateien automatisch in ein Web-verzeichis kopiert werden?" 80 80 +if [ $? == "1" ] +then + sed -i "s/sudo cp/#sudo cp/g" export.sh +else + dialog --title "Verzeichnis" --msgbox "Wo liegt das Web-verzeichis?" 80 80 + dialog --dselect / 10 10 2> temp.tmp + PFAD=$(cat temp.tmp) + ZEILE="PFAD=\"$PFAD\"" + sed -i 2c"$ZEILE" export.sh #2. Zeile + rm temp.tmp + cd $PFAD + sudo wget http://lukaswiki.onpw.de/rasp/javascript/highcharts.js 2>>$SKRIPTPFAD/installation.log + sudo wget http://lukaswiki.onpw.de/rasp/beispiele/highcharts.html 2>>$SKRIPTPFAD/installation.log + dialog --title "Highchart" --msgbox "Die Highchart-Dateien wurden nach $PFAD kopiert. Das Diagramm kann unter localhost/highcharts.html gefunden werden." 80 80 +fi +dialog --title "Abgeschlossen" --msgbox "Die Installation ist abgeschlossen." 80 80 diff --git a/rand.sh b/rand.sh new file mode 100644 index 0000000..19b4afb --- /dev/null +++ b/rand.sh @@ -0,0 +1,8 @@ +a=0 +while true +do + a=$(($a + $((RANDOM % 10)) - 5)) # a um eine zufällige Zahl zwischen -5 und 5 ändern + #a=a+[Zufallszahl von 0-32767] modulo 10 (um eine Zahl von 0-10 zu bekommen) -5 (-> -5 bis 5) + echo -ne "${a}\r" #keine neue Zeile und Steuerzeichen beachten +sleep 0.5 +done diff --git a/transpose.sh b/transpose.sh new file mode 100644 index 0000000..abfd8ce --- /dev/null +++ b/transpose.sh @@ -0,0 +1,22 @@ +#!/bin/bash +#(c) http://www.cs.waikato.ac.nz/~fracpete/programming/csv2gnuplot/ +echo "Zeit LOAD Temperatur" > temp +cat daten_gnuplot.txt >> temp +cat temp | exec awk ' + NR == 1 { + n = NF + for (i = 1; i <= NF; i++) + row[i] = $i + next + } + { + if (NF > n) + n = NF + for (i = 1; i <= NF; i++) + row[i] = row[i] " " $i + } + END { + for (i = 1; i <= n; i++) + print row[i] + }' > daten_transformiert.txt +rm temp