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

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
User avatar
m3m0r3x
Posts: 4
Joined: Thu Jul 26, 2018 9:57 pm

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

Post by m3m0r3x »

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:

Code: Select all

# 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?
Last edited by m3m0r3x on Wed Aug 01, 2018 8:52 am, edited 1 time in total.
User avatar
WarHawk
Posts: 608
Joined: Thu Jul 20, 2017 8:55 am

Re: DietPi + Wifi Hotspot + radom generated WPA Key on bootup

Post by WarHawk »

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!!!!!!!
User avatar
m3m0r3x
Posts: 4
Joined: Thu Jul 26, 2018 9:57 pm

Re: DietPi + Wifi Hotspot + radom generated WPA Key on bootup

Post by m3m0r3x »

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...
User avatar
m3m0r3x
Posts: 4
Joined: Thu Jul 26, 2018 9:57 pm

Re: DietPi + Wifi Hotspot + radom generated WPA Key on bootup

Post by m3m0r3x »

Hi Community,

maybe there was a missunderstanding :? . 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.
User avatar
m3m0r3x
Posts: 4
Joined: Thu Jul 26, 2018 9:57 pm

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

Post by m3m0r3x »

Hi Community,

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

Code: Select all

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

Code: Select all

@reboot /path/to/newscript.sh
In addition I inserted following into the rc.local:

Code: Select all

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....
Post Reply