[Request] Wifi settings change on boot Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
Ant

[Request] Wifi settings change on boot

Post by Ant »

Hello,

How can I change WiFi settings on a system running without monitor,keyboard, etc?
For example, WiFi radio made from RPi+DietPi worked fine in my house, then I give it to my friend (another wifi network). But he is not familiar with Linux and SSH, all he need is radio working with his Wifi spot.
Maybe he will give radio to someone else later, and I can not change ssid settings every time for every user.

So how can I program simple replace of /etc/network/interfaces file on boot, or there is another way exists?

(sorry for poor English, I'm russian)
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: [Request] Wifi settings change on boot

Post by Fourdee »

Ant wrote:Hello,

How can I change WiFi settings on a system running without monitor,keyboard, etc?
For example, WiFi radio made from RPi+DietPi worked fine in my house, then I give it to my friend (another wifi network). But he is not familiar with Linux and SSH, all he need is radio working with his Wifi spot.
Maybe he will give radio to someone else later, and I can not change ssid settings every time for every user.

So how can I program simple replace of /etc/network/interfaces file on boot, or there is another way exists?

(sorry for poor English, I'm russian)
Although you mentioned the system will be headless. For the sake of simplicity, when your friend runs the Pi for the 1st time, just plug a keyboard + Monitor in, then run

Code: Select all

dietpi-config 8 1
Select Wifi, then scan and connect, exit, job done :)

If you want to automate the modifications to your /etc/network/interfaces file on boot, you would need to create a script during boot phase that reads a file/settings from /boot (fat partition on sd), then modifies the /etc/network/interfaces file before network is loaded.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Ant

Re: [Request] Wifi settings change on boot

Post by Ant »

RPi is inside of radio case, with many soldered wires, and it's impossible to attach monitor to it.

I'm talking about automation. Where can I write command to execute bash script (python will be better) on system boot? I read about udev rules, created one (created additional file), but it does not works. Whether there are other ways to run my script? - I want to detect plugged usb stick, read file from it, and copy that file to /etc/network/
So, first run will be with wrong wifi settings, than I'm insert usb stick, replace interfaces file, and second start gonna be ok. Is it correct way?
Pilovali
Posts: 81
Joined: Sat Oct 03, 2015 7:11 pm
Location: The Netherlands
Contact:

Re: [Request] Wifi settings change on boot

Post by Pilovali »

You can also change the dietpi.txt in the root of the SDCard. It has WiFi settings there.
Ant

Re: [Request] Wifi settings change on boot

Post by Ant »

Dietpi.txt works on first boot, as I know
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: [Request] Wifi settings change on boot

Post by Fourdee »

Ant wrote:RPi is inside of radio case, with many soldered wires, and it's impossible to attach monitor to it.

I'm talking about automation. Where can I write command to execute bash script (python will be better) on system boot? I read about udev rules, created one (created additional file), but it does not works. Whether there are other ways to run my script? - I want to detect plugged usb stick, read file from it, and copy that file to /etc/network/
So, first run will be with wrong wifi settings, than I'm insert usb stick, replace interfaces file, and second start gonna be ok. Is it correct way?
There is a few ways to do what you need:
The easiest would be to add your script to /etc/rc.local. As this runs last, you would need to code a system that disconnects the wifi, changes /etc/network/interfaces and reconnects wifi (eg: ifdown wlan0 & ifup wlan0).

If you want to do this as as service, on wheezy, here is an example service: https://github.com/Fourdee/DietPi/blob/ ... pi-service. You would be best to run your script before $network. This way you can just modify the /etc/network/interfaces file

Jessie, you can use systemd. Here is an example service:
You would be best to run your script before network, i believe its network-pre.target. This way you can just modify the /etc/network/interfaces file. You can simply use ExecStart=/My/Script.sh

Code: Select all

cat << _EOF_ > /etc/systemd/system/dietpi-service.service
[Unit]
Description=DietPi Bootup and Shutdown Service
Before=network-pre.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/DietPi/dietpi/conf/dietpi-service start
ExecStop=/DietPi/dietpi/conf/dietpi-service stop
StandardOutput=tty

[Install]
WantedBy=multi-user.target
_EOF_
systemctl enable dietpi-service
systemctl daemon-reload
As for waiting for a USB device to be connected, you would need to run a while loop. Example:
https://github.com/Fourdee/DietPi/blob/ ... up#L41-L53. You would be best waiting for a UUID rather than /dev/sda
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2782
Joined: Tue Feb 06, 2007 1:36 pm

Re: [Request] Wifi settings change on boot

Post by Fourdee »

Ant wrote:Dietpi.txt works on first boot, as I know
Correct.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Post Reply