Technology

RPI – Buster – IoT – miniserver

Download buster:
https://downloads.raspberrypi.org/raspbian_lite_latest

Unzip
Burn Image
sudo su

  • raspi-config
    change timezone
    change memory split –> 128
    expand sd
    reboot

apt update
apt upgrade
apt install mc
apt install ntp
apt-get install realvnc-vnc-server

  • raspi-config
    enable VNC Server
apt-get install python-pip
pip install pymodbus
pip install requests
pip install paho-mqtt

sudo aptget install apache2 y
sudo a2enmod rewrite
sudo service apache2 restart
aptget install mariadbserver mariadbclient phpmysql y
aptget install phpmyadmin y
  • Automatic Configuration? – Choose [*]apache2 with your Spacebar, hit Tab then Enter
  • Configure database for phpmyadmin with dbconfig-common? – Choose Yes
  • phpMyAdmin application password – [enter new password] [confirm new password] this is for logging into the phpMyAdmin web interface

 

php.ini
#Tells PHP whether the short form (<? ?>)
short_open_tag = On

#Tell the timezone
date.timezone = “Asia/Jakarta”

#config upload file and post
upload_max_filesize = 20M
post_max_size = 20M

#increase the exec time from 30 to 120
max_execution_time = 120

#increase the mem limit from 128M to 256M
memory_limit = 256M

Technology

Kiosk – copy paste

The other account will be used to manage the system and any kiosk changes remotely via SSH. If you SSH into this machine as the kiosk user, you’ll end up running duplicate scripts.

Add Users To sudoers

I chose to add the 2 users to the sudoers file so I wouldn’t get prompted for passwords all the time. Run visudo and at the bottom add

1
2
kiosk ALL=(ALL) NOPASSWD: ALL
obrienlabs ALL=(ALL) NOPASSWD: ALL

Install Required Packages

We’ll need to install some software to accomplish this.

  • Chromium is the Chrome browser but with much more options.
  • Unclutter removes the mouse cursor from the screen, giving it a clean look.
  • xdotool can manipulate on screen elements using a virtual keyboard. We use it to change tabs in Chromium.
1
sudo apt-get install -y chromium-browser unclutter xdotool

Setup Auto Login

Now we can setup the auto login process. We need the user Kiosk to auto login on every reboot.

sudo nano /etc/lightdm/lightdm.conf and add:

1
2
3
4
5
[SeatDefaults]
autologin-user=kiosk
autologin-user-timeout=0
user-session=ubuntu
greeter-session=unity-greeter

Then run sudo mkdir /etc/lightdm/lightdm.conf.d && sudo nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf and add:

1
2
[SeatDefaults]
autologin-user=kiosk

Setup kiosk.sh Script

Now that we are auto logged in, let’s run our script.

Run sudo mkdir /home/kiosk/.config/autostart && sudo nano /home/kiosk/.config/autostart/kiosk.desktop and add:

1
2
3
4
5
[Desktop Entry]
Type=Application
Name=Kiosk
Exec=/home/kiosk/kiosk.sh
X-GNOME-Autostart-enabled=true

Installing the kiosk.sh script is as simple as copying the code below. This script will be launched every time the kiosk user logs in (even with SSH), so be sure to tailor it to your needs!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Run this script in display 0 - the monitor
export DISPLAY=:0
# Hide the mouse from the display
unclutter &
# If Chromium crashes (usually due to rebooting), clear the crash flag so we don't have the annoying warning bar
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/kiosk/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/kiosk/.config/chromium/Default/Preferences
# Run Chromium and open tabs
/usr/bin/chromium-browser --window-size=1920,1080 --kiosk --window-position=0,0 http://google.com http://bing.com &
# Start the kiosk loop. This keystroke changes the Chromium tab
# To have just anti-idle, use this line instead:
# xdotool keydown ctrl; xdotool keyup ctrl;
# Otherwise, the ctrl+Tab is designed to switch tabs in Chrome
# #
while (true)
  do
    xdotool keydown ctrl+Tab; xdotool keyup ctrl+Tab;
    sleep 15
done
Then make the script executable by running chmod +x kiosk.sh

As you can see Chromium runs in Kiosk mode. This means it’ll go full screen and take minimal input from the keyboard and mouse (if one was plugged in). In this example, Chromium will auto load Google and Bing in 2 tabs, and xdotool will cycle between the tabs every 15 seconds. I’m also performing some Chrome clean up in case the system reboots without closing Chrome. This will remove the nag bar.

Managing the system after it’s setup

To manage the system after it’s setup, you’ll need to find the IP of the device, and SSH into it using the OTHER USER you setup. Do not SSH in as user kiosk, or you’ll end up opening another Chromium instance, as well as kiosk.sh which will end up changing the tabs in more frequent intervals since xdotool will be called twice as fast.

Other things you can add to kiosk.sh are running x11vnc and autossh to automatically setup an SSH tunnel from the system to your centralized server, allowing you to SSH into the device and even VNC to the monitor without needing to know the IP. Very useful!

If you make any changes and want to log Kiosk out without rebooting, I’ve found that this command works. This will kill the kiosk.sh script and restart the Windows service which will log out and log in the kiosk user.

1
sudo killall kiosk.sh && sudo service lightdm restart
Technology

MySQL Optimization

Your mySQL very high CPU load over 100%… just skip-name-resolve=1

[mysqld]

skip-name-resolve=1
Solution Problem: #1265 Data truncated for column ….

// remove STRICT_TRANS_TABLES, ….. in my.cnf

 

// optimize large DB

max_allowed_packet = 1M
thread_cache_size = 8
myisam-recover-options = BACKUP
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
innodb_file_per_table = 1
myisam_sort_buffer_size = 64M
read_rnd_buffer_size = 8M
read_buffer_size = 2M
sort_buffer_size = 2M

## ini rekomendasi dari mysqltunner
#innodb_buffer_pool_size = 4G
#innodb_log_file_size = 1024M
table_open_cache = 4096
join_buffer_size = 256k
query_cache_type = 1
query_cache_limit = 4M
query_cache_size = 128M

slow_query_log = ON
long_query_time = 5
key_buffer_size = 512M
sql_mode=NO_ENGINE_SUBSTITUTION