[Solved] DietPi + Wifi Hotspot + radom generated WPA Key on bootup

Hi community,

I have already set up DietPi on a Raspi 3 b+, installed optimized Softwae: Wifi Hotspot, Chrome Kiosk mode, LLMP stack.

In addition I assembled a 7zoll touchsceen to it. I created a nice dashboard with some interesting information. So when I boot up, i want to generate a new Wifi Key and display it on the touchscreen (behind a button).

I placed a tiny script in rc.local:

# Filemanipulation
key=$(openssl rand -base64 15)
sed -i "s/SOFTWARE_WIFI_HOTSPOT_KEY=.*$/SOFTWARE_WIFI_HOTSPOT_KEY=$key/" /DietPi/dietpi.txt
sed -i "s/wpa_passphrase=.*$/wpa_passphrase=$key/" /etc/hostapd/hostapd.conf

# Restat hostapd service
service hostapd stop
service hostapd start

Bevor I have done it on reboot I tested it during runtime and it works pretty good. Even in the dashboard the new password showed up. Unfortunately when I really rebootet the pi, both config files where overwritten with “dietpihotspot”.

I really now get crazy because I don’t know where I can put the generated key. Can somebody please give me a hint? I assume those two files I maniplate are not the correct ones… but which are they?

I believe hostname is set with dietpi-config

Somewhere in /DietPi/dietpi.txt is where the hostname is statically set

P.S. Really AWESOME script! Thanks!!!

Hi WarHawk,

thanks for the quick replay. But my problem is regarding the acces point password. This is also set in /DietPi/dietpi.txt and /etc/hostapd/hostapd.conf. But unfortunately it seems to be overwritten after /etc/local.rc is executed on bootup…

Hi Community,

maybe there was a missunderstanding :thinking: . Isn’t it possible to update SSID and the wifi key (for the WIFI-Hotspot) without to make use of dietpi-config? I will just try it in a script. As stated above, on runtime it works perfect, but when I reboot the snippet wich I attached in rc.local seams to be working but after a short amount of time both files /DietPi/dietpi.txt and /etc/hostapd/hostapd.conf will be overwritten with the deafults (SSID: DietPi-HotSpot and Key:dietpihotspot). I would be happy if there is a solution for that.

Hi Community,

I solved the problem. I moved the sed statements and the service restart in an own shell skript.

sleep 120
# Filemanipulation
key=$(openssl rand -base64 15)
sed -i "s/SOFTWARE_WIFI_HOTSPOT_KEY=.*$/SOFTWARE_WIFI_HOTSPOT_KEY=$key/" /DietPi/dietpi.txt
sed -i "s/wpa_passphrase=.*$/wpa_passphrase=$key/" /etc/hostapd/hostapd.conf

# Restat hostapd service
service hostapd stop
service hostapd start

I need the delay for 120 sec so that I can manipulate the dietpy.txt and the hostapd.conf as well.

Then I inserted it into crontab

@reboot /path/to/newscript.sh

In addition I inserted following into the rc.local:

echo 1 > /sys/cass/backlight/rpi_backlight/bl_power
sleep 120
echo 0 > /sys/cass/backlight/rpi_backlight/bl_power

This will turn out the backlight of the touchscreen until the new wifi key is generated and can be displayed in the dashboard.

Maybe I can tweak the delay a bit…

This does the job for me…