From b3ad812dcee2752e6e098570650e6dade2f2f0a9 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 5 Dec 2015 16:29:44 +0100 Subject: [PATCH] first commit --- config.txt | 15 +++ etc/dnsmasq.conf | 4 + etc/hostapd.conf | 7 ++ etc/issue | 6 ++ etc/network/interfaces | 12 +++ etc/udev/rules.d/70-usb-modeswitch.rules | 4 + etc/wvdial.conf | 11 +++ scripts.txt | 14 +++ tutorials.txt | 4 + usr/bin/dial | 9 ++ usr/bin/disp | 100 +++++++++++++++++++ usr/bin/dispchar | 100 +++++++++++++++++++ usr/bin/dispprogress | 114 ++++++++++++++++++++++ usr/bin/monitor_luftinternet | 116 +++++++++++++++++++++++ 14 files changed, 516 insertions(+) create mode 100644 config.txt create mode 100644 etc/dnsmasq.conf create mode 100644 etc/hostapd.conf create mode 100644 etc/issue create mode 100644 etc/network/interfaces create mode 100644 etc/udev/rules.d/70-usb-modeswitch.rules create mode 100644 etc/wvdial.conf create mode 100644 scripts.txt create mode 100644 tutorials.txt create mode 100755 usr/bin/dial create mode 100755 usr/bin/disp create mode 100755 usr/bin/dispchar create mode 100755 usr/bin/dispprogress create mode 100755 usr/bin/monitor_luftinternet diff --git a/config.txt b/config.txt new file mode 100644 index 0000000..bdc03c9 --- /dev/null +++ b/config.txt @@ -0,0 +1,15 @@ +/etc/hostapd.conf + SSID + WPA-key +/etc/dnsmasq.conf + DHCP range + DNS server +/etc/wvdial.conf + UMTS modem connection settings +/etc/issue + Prompt you see before logging in via HDMI +/etc/network/interfaces + IP of your raspberry + Various network settings +/etc/udev/rules.d/70-usb-modeswitch.rules + switching info for your UMTS modem diff --git a/etc/dnsmasq.conf b/etc/dnsmasq.conf new file mode 100644 index 0000000..bcdeb01 --- /dev/null +++ b/etc/dnsmasq.conf @@ -0,0 +1,4 @@ +bind-interfaces +interface=wlan0 +dhcp-range=192.168.150.2,192.168.150.10 +dhcp-option=6,8.8.8.8,8.8.4.4 diff --git a/etc/hostapd.conf b/etc/hostapd.conf new file mode 100644 index 0000000..4fcdafa --- /dev/null +++ b/etc/hostapd.conf @@ -0,0 +1,7 @@ +interface=wlan0 +driver=nl80211 +ssid=linksys +hw_mode=g +channel=6 +wpa=2 +wpa_passphrase=defaultpassword diff --git a/etc/issue b/etc/issue new file mode 100644 index 0000000..67e1cd6 --- /dev/null +++ b/etc/issue @@ -0,0 +1,6 @@ +[RaspiRouter, SSID: linksys] +WPA2-PSK: defaultpassword +Root-Password: hunter2 +Kali GNU/Linux 1.1.0 \n \l + + diff --git a/etc/network/interfaces b/etc/network/interfaces new file mode 100644 index 0000000..4ad8b4e --- /dev/null +++ b/etc/network/interfaces @@ -0,0 +1,12 @@ + +auto lo +iface lo inet loopback + +iface eth0 inet dhcp + +allow-hotplug wlan0 +auto wlan0 +iface wlan0 inet static + +allow-hotplug wwan0 +iface wwan0 inet dhcp diff --git a/etc/udev/rules.d/70-usb-modeswitch.rules b/etc/udev/rules.d/70-usb-modeswitch.rules new file mode 100644 index 0000000..1be60b3 --- /dev/null +++ b/etc/udev/rules.d/70-usb-modeswitch.rules @@ -0,0 +1,4 @@ +# define your rules for usb_modeswitch here + +ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="14fe", RUN+="/usr/sbin/usb_modeswitch -v 12d1 -p 14fe -M '55534243123456780000000000000011062000000100000000000000000000'" +ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1506", RUN+="/bin/bash -c 'modprobe option && echo 12d1 1506 > /sys/bus/usb-serial/drivers/option1/new_id'" diff --git a/etc/wvdial.conf b/etc/wvdial.conf new file mode 100644 index 0000000..bfab001 --- /dev/null +++ b/etc/wvdial.conf @@ -0,0 +1,11 @@ +[Dialer Defaults] +Init = AT+CGDCONT=1,"IP","drei.at" +Stupid Mode = 1 +Modem Type = Analog Modem +IDSN = 0 +Phone = *99# +Modem = /dev/gsmmodem +Username = { } +Password = { } +Baud = 460800 +#New PPPD = yes diff --git a/scripts.txt b/scripts.txt new file mode 100644 index 0000000..b6d05b0 --- /dev/null +++ b/scripts.txt @@ -0,0 +1,14 @@ +/usr/bin/disp + echoes the first parameter to the LCD after clearing it + needs the RPi.GPIO library. +/usr/bin/dispchar + prints a single ASCII character at the current position of the LCD. + does not advance cursor. +/usr/bin/dispchar + scrolls the _ cursor from left to right in 8 seconds (used as a fancy sleep) +/usr/bin/dial + a while-wrapper for wvdial, as wvdial does not automatically reconnect when + the connection is lost. +/usr/bin/monitor-luftinternet + my rather extensive status-checker. + prints status to the first tty and the HD44780 diff --git a/tutorials.txt b/tutorials.txt new file mode 100644 index 0000000..483addd --- /dev/null +++ b/tutorials.txt @@ -0,0 +1,4 @@ +https://www.thefanclub.co.za/how-to/how-setup-usb-3g-modem-raspberry-pi-using-usbmodeswitch-and-wvdial +http://doku.yellowtux.org/index.php?id=34 +http://www.schnatterente.net/technik/raspberry-pi-32-zeichen-hitachi-hd44780-display + diff --git a/usr/bin/dial b/usr/bin/dial new file mode 100755 index 0000000..4bed941 --- /dev/null +++ b/usr/bin/dial @@ -0,0 +1,9 @@ +#!/bin/bash + +#wrapper for wvdial, because it looses connection and quits often +while : ; do + wvdial + #sleep 10 + sleep 2 +done + diff --git a/usr/bin/disp b/usr/bin/disp new file mode 100755 index 0000000..8a3a7b7 --- /dev/null +++ b/usr/bin/disp @@ -0,0 +1,100 @@ +#!/usr/bin/python + +# modified version if this tutorial's demo script (German): +# http://www.schnatterente.net/technik/raspberry-pi-32-zeichen-hitachi-hd44780-display + +import time +import sys +import RPi.GPIO as GPIO +GPIO.setwarnings(False) + +# 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 (colums per line) +DISPLAY_LINE_1 = 0x80 # Adresse der ersten Display Zeile +DISPLAY_LINE_2 = 0xC0 + +DISPLAY_CHR = True +DISPLAY_CMD = False +E_PULSE = 0.0005 +E_DELAY = 0.0005 + +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() + + # my screen is internally wired as a 2x8, so that's that bodge. + if len (sys.argv) > 1: + mystring = sys.argv[1].ljust (8, " ") + lcd_byte (DISPLAY_LINE_1, DISPLAY_CMD) + lcd_string (mystring[0:8]) + lcd_byte (DISPLAY_LINE_2, DISPLAY_CMD) + lcd_string (mystring[8:16]) + + +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) + +if __name__ == '__main__': + main() + diff --git a/usr/bin/dispchar b/usr/bin/dispchar new file mode 100755 index 0000000..cd0a7cb --- /dev/null +++ b/usr/bin/dispchar @@ -0,0 +1,100 @@ +#!/usr/bin/python +import time +import sys +import RPi.GPIO as GPIO +GPIO.setwarnings(False) + +# 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 + +DISPLAY_CHR = True +DISPLAY_CMD = False +E_PULSE = 0.0005 +E_DELAY = 0.0005 + +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() + + lcd_byte (0x0c, DISPLAY_CMD) #cursor off + if len (sys.argv) > 1: + message = sys.argv[1] + lcd_byte(ord(message[0]),DISPLAY_CHR) + lcd_byte (0x10, DISPLAY_CMD) #shift curpos left + #mychar = ord(sys.argv[1]) + #print (mychar) + #lcd_byte (mychar, DISPLAY_CMD) +# lcd_string (mystring[0:8]) +# lcd_byte (DISPLAY_LINE_2, DISPLAY_CMD) +# lcd_string (mystring[8:16]) + + +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) #advance cursor + #lcd_byte(0x01,DISPLAY_CMD) #clear display + +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) + +if __name__ == '__main__': + main() + diff --git a/usr/bin/dispprogress b/usr/bin/dispprogress new file mode 100755 index 0000000..f5bfe83 --- /dev/null +++ b/usr/bin/dispprogress @@ -0,0 +1,114 @@ +#!/usr/bin/python +import time +import sys +import RPi.GPIO as GPIO +GPIO.setwarnings(False) + +# 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 + +DISPLAY_CHR = True +DISPLAY_CMD = False +E_PULSE = 0.0005 +E_DELAY = 0.0005 + +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() + + #lcd_byte(DISPLAY_LINE_1, DISPLAY_CMD) + #lcd_string("Luftinte") + #lcd_byte(DISPLAY_LINE_2, DISPLAY_CMD) + #lcd_string("rnet!") + while (1): + lcd_byte(0x0e, DISPLAY_CMD)#enable cursor + lcd_byte(0x02, DISPLAY_CMD)#put cursor to the left + lcd_byte(DISPLAY_LINE_1 - 1, DISPLAY_CMD) + for i in range (0, 8): + lcd_byte (0x14, DISPLAY_CMD)#advance cursor + time.sleep (0.5) + lcd_byte(DISPLAY_LINE_2 - 1, DISPLAY_CMD) + for i in range (0,8): + lcd_byte(0x14, DISPLAY_CMD) + time.sleep(0.5) + break + lcd_byte(0x0f, DISPLAY_CMD) #cursor blinky (als lade-anim) + lcd_byte (33, DISPLAY_CMD) + + #if len (sys.argv) > 1: + # mystring = sys.argv[1].ljust (8, " ") + # lcd_byte (DISPLAY_LINE_1, DISPLAY_CMD) + # lcd_string (mystring[0:8]) + # lcd_byte (DISPLAY_LINE_2, DISPLAY_CMD) + # lcd_string (mystring[8:16]) + + +def display_init(): + lcd_byte(0x33,DISPLAY_CMD) + lcd_byte(0x32,DISPLAY_CMD) + lcd_byte(0x28,DISPLAY_CMD) + #lcd_byte(0x0C,DISPLAY_CMD) #cursor off + lcd_byte(0x06,DISPLAY_CMD) + #lcd_byte(0x01,DISPLAY_CMD) #clear + +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) + +if __name__ == '__main__': + main() + diff --git a/usr/bin/monitor_luftinternet b/usr/bin/monitor_luftinternet new file mode 100755 index 0000000..047f91f --- /dev/null +++ b/usr/bin/monitor_luftinternet @@ -0,0 +1,116 @@ +#!/bin/bash + +while : ; do +setterm -inversescreen off +#0. fetch data: + #1. lsusb + dispchar a + usb=$(lsusb) + #2. ps + dispchar b + proc=$(ps ax) + +#1. check hardware + #1.1 check umts modem + echo -n "UMTS: " + dispchar c + if [[ $(echo "$usb" | grep "12d1:1506") ]] ; then + echo -n "OK" + else + echo "Not Found" + setterm -inversescreen + echo -e "\n\n*** Replug Modem ***\n\n" +disp "UMTS Fatal Error" #Modem Error: fatal! + sleep 5 #read -p "press enter" #while : ; do; done #halt exec + fi + if [[ $(echo "$usb" | grep "12d1:14fe") ]] ; then + echo -n "wrong mode" + usb_modeswitch -v 12d1 -p 14fe -V 12d1 -P 1506 -M +'55534243123456780000000000000011062000000100000000000000000000' +disp "UMTS Modeswitch" #Modem Warning: mode + continue + fi + #1.2 check wlan stick + echo -ne "\nWLAN: " + dispchar d + if [[ $(echo "$usb" | grep "0cf3:9271") ]] ; then + echo -n "OK" + else + echo "error" + setterm -inversescreen + echo -e "\n\n*** Replug WiFi ***\n\n" +disp "WiFi Fatal Error" #WiFi Error: fatal! + sleep 5 #read -p "press enter" #while : ; do; done #halt exec + fi +#2. check services + #2.1 check hostapd + echo -ne "\nhostapd: " + dispchar e + if [[ $(echo "$proc" | grep "hostapd" | grep -v "grep") ]] ; then + echo -n "OK" + else + echo -n "restarting" + #hostpad /etc/hostapd.conf & + service hostapd restart +disp "hostapd restart" #Service warning: hostapd + continue + fi + #2.2 check dnsmasq + echo -ne "\ndnsmasq: " + dispchar f + if [[ $(echo "$proc" | grep "dnsmasq" | grep -v "grep") ]] ; then + echo -n "OK" + else + echo -n "restarting" + service dnsmasq restart +disp "dnsmasq restart" #Service warning: dnsmasq + continue + fi + #2.3 check wvdial + echo -ne "\nwvdial: " + dispchar g + if [[ $(echo "$proc" | grep "wvdial" | grep -v "grep") ]] ; then + echo -n "OK" + else + echo -n "restarting" + killall dial + killall wvdial + #killall modem-manager + dial & #wvdial & +disp "wvdial restart" #Service warning: wvdial + continue + fi +#3. check conncection + #3.1 check ping + echo -ne "\nPING: " + dispchar h + if [[ $(ping google.com -c 4 -i 0.2) ]] ; then + echo -n "OK" + #3.1-2 check http + echo -ne "\nWGET: " + dispchar i + wget -q --tries=3 --timeout=5 http://google.com/generate_204 -O - &>/dev/null + if [[ $? -eq 0 ]] ; then + echo -n "OK" + #4 OK, get client list + clients=$(iw dev wlan0 station dump|grep Station|wc -l) + echo "\nClients: $clients" +disp "Luftinternet $clients" +#disp "Luftinternet :)" +#disp "Luftinternet $(iw dev wlan0 station dump|grep Station|wc -l)" + else + echo "Unknown Error" +disp "wget error unknw" #Unknown Error: wget! + fi + else + echo "ping error" +disp "ping error unknw" #ping error + fi + +echo -ne "\n\n" + +#break +dispchar + +dispprogress #sleep 10 #dispprogress is a python script that displays a cursor and waits approx 8sec +done + -- 2.39.3