function datetimeBel($timestamp)
{
$date = date_create($timestamp, timezone_open(‘Etc/GMT’));
date_timezone_set($date, timezone_open(‘Europe/Brussels’));
return date_format($date, ‘d/m/Y H:i:s’);
}
Source: https://howchoo.com/pi/raspberry-pi-display-rotation
Open file
sudo nano /boot/config.txt
Rotate the display
display_rotate=0 # Normal (landscape)
display_rotate=1 # 90 degrees (portrait, upside down)
display_rotate=2 # 180 degrees (landscape)
display_rotate=3 # 270 degrees (portrait, upside down)
display_rotate=0x10000 # horizontal flip
display_rotate=0x20000 # vertical flip
Rotate touch input
lcd_rotate=0 # default (normal landscape)
lcd_rotate=1 # 90 degrees (portrait, upside down)
lcd_rotate=2 # 180 degrees (landscape)
lcd_rotate=3 # 270 degrees (portrait, upside down)
Reboot the device
Maak een script aan sudo nano start.sh
#!/bin/sh
sleep 10
cd /
cd home/pi/
sudo python ip.py &
cd /
Wijzig de rechten sudo chmod 775 start.sh
sudo crontab -e
Voeg volgende lijn toe @reboot sudo sh /home/pi/start.sh >/home/pi/logs/cronlog 2>&1
Maak een log file
mkdir logs
chmod 775 logs
Ubuntu opstartscript
# TomTech Productions IP
import time, os
import requests, socket, uuid
## INSERT YOUR KEY AND MAIL HERE ##
domain = "" #company domain
mail = "tom.schelles@live.be" #your email
## INSERT YOUR KEY AND MAIL HERE ##
url = 'https://ttpm.be/data/online/post.php'
mac = uuid.getnode()
def get_lan_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
return s.getsockname()[0]
while(1):
lan = get_lan_address()
name = socket.gethostname()
myobj = {'lan' : lan, 'mac': mac, 'name': name, 'domain': domain, 'mail': mail }
try:
x = requests.post(url, data = myobj)
if (x.text == "reboot"):
os.system("shutdown -t 0 -r -f")
if (x.text == "lock"):
os.system("shutdown -l")
if (x.text == "shutdown"):
os.system("shutdown -t 0 -s -f")
except:
print('NO CONNECTION TO SERVICE')
#update gegevens lokaal om de 10 seconden
time.sleep(30)
source: https://bloggerbrothers.com/2016/12/27/boot-your-pixel-based-pi-into-chromium-kiosk/
Install following software
sudo apt-get install -y x11-xserver-utils unclutter
Create a new file
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Copy this code into the file
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash
#@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences
@chromium-browser --incognito --noerrdialogs --kiosk tomtechproductions.be/example
@unclutter -idle 0.1 -root
Mount share at boot
Save credentials at a local place where only you have rights
Install cifs-utils
sudo apt-get install cifs-utils
Create directory
sudo mkdir -p /mnt/srv-ttp-nas
An easy way to backup files to a local share
The example backup’s the files from the /var/www/html directory
#change to website folders
cd /var/www/html/
#find all subsites
for D in *; do
if [ -d "${D}" ]; then
echo "Generating backup for $D > " `date +%Y-%m-%d_%H-%M-%S`-${D} # your processing here
tar -zcvf "/mnt/srv-ttp-nas/server/"`date +%Y-%m-%d_%H-%M-%S`-${D}.tar.gz ${D}
fi
done
#remove stale files
find /mnt/srv-ttp-nas/server/* -mtime +14 -exec rm {} \;
Add crontab to run backup every night at 3
sudo crontab -e
0 3 * * * /home/tom/backup_files.sh
Preview of data on share
I created an easy way to backup all mysql databases
/mnt/srv-ttp-nas/ is a location on a local NAS
#!/bin/sh
sleep 10
DB_USER="username"
DB_PASS="password"
BACKUP_DIR = "/mnt/srv-ttp-nas/bu/databases"
#find all databasses and backup them
databases=`mysql --user=$DB_USER --password=$DB_PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
echo "Dumping database: $db"
mysqldump $db -u $DB_USER -p --password=$DB_PASS | gzip > "/mnt/srv-ttp-nas/databases/"`date +%Y-%m-%d_%H-%M-%S`-$db.sql.gz
done
#remove files older than one month
find /mnt/srv-ttp-nas/databases/* -mtime +31 -exec rm {} \;
The power of this script is that if you add a new database this will automaticly be added.
Add to crontab to backup every 6 hours.
sudo crontab -e
0 0,6,12,18 * * * /home/tom/backup.sh
Preview of data on share
Enable unsafe apps
First we have to enable unsafe apps to connect to gmail.
https://myaccount.google.com/security
SMTP settings
smtp.gmail.com
SSL vereist: ja
TLS vereist: ja (indien beschikbaar)
Verificatie vereist: ja
Poort voor SSL: 465
Poort voor TLS/STARTTLS: 587
Download the correct software from Ubiquiti.
Change the name from the downloaded file to fwupdate.bin
Open WinSCP and connect to the AP using SCP protocol.
Copy the fwupdate.bin file to /tmp folder.
Close WinSCP and open Putty. Connect to the AP using ssh.
Issue the command syswrapper.sh upgrade2 & after this your session will close automatic and the AP will start the upgrade.