Tiny Core Base > Raspberry Pi
Headless RPi Zero on new networks
(1/1)
hamak:
Hello there
Can anyone tell me if it is an easier way to do a headless connection to new wifi networks than this?
I made this today because I want to be able to create a wifi.txt file in the fat32 partition of PiCore
from any PC that contains the wifi SSID PASSWORD WPA, but I do not want
to mount and unmount /mnt/mmcblk0p1 if the network is OK!
This is tested with notepad and works great except for the mount unmount stuff
wifi.txt is the same format as wifi.db
SSID[TAB]PASSWORD[TAB]WPA
No space, only TAB's
this is the /opt/bootlocal.sh
--- Code: ---mount /dev/mmcblk0p1 /mnt/mmcblk0p1
if [ -f /mnt/mmcblk0p1/wifi.txt ]; then
cp /mnt/mmcblk0p1/wifi.txt /home/tc/wifi.db
rm /mnt/mmcblk0p1/wifi.txt
filetool.sh -b
sudo reboot
fi
umount /dev/mmcblk0p1 /mnt/mmcblk0p1
--- End code ---
I was thinking about checking for a hidden file on /home/tc/ but I think it is a messy code
--- Code: ---if [ ! -f /home/tc/.wifi ]; then
mount /dev/mmcblk0p1 /mnt/mmcblk0p1
fi
if [ -f /mnt/mmcblk0p1/wifi.txt ]; then
cp /mnt/mmcblk0p1/wifi.txt /home/tc/wifi.db
rm /mnt/mmcblk0p1/wifi.txt
touch /home/tc/.wifi
filetool.sh -b
sudo reboot
fi
umount /dev/mmcblk0p1 /mnt/mmcblk0p1
--- End code ---
The Critical Problem with this is that the .wifi will exist even if you change networks and then you have a problem! NO SSH!
as you see i still will perform a unmount even if this is not mounted and that is messy...
To find the new PiCore I run arp -a on windows and then ping with broadcast like example: 192.168.1.255 and run arp -a again to see what ip address is newin the list, but if you have ip scanner or something that will work too
Rich:
Hi hamak
--- Quote --- ... as you see i still will perform a unmount even if this is not mounted and that is messy...
--- End quote ---
You could test if the drive is mounted first. I think this should work:
--- Code: ---if ! grep -q /mnt/mmcblk0p1 /etc/mtab
then
umount /mnt/mmcblk0p1
fi
--- End code ---
/etc/mtab is a link to /proc/mounts which is a list of all currently mounted devices. grep returns a 0 (zero) if it finds the
search term. Placing the ! in front inverts the the return code so the if statement becomes true when grep succeeds.
hamak:
Yes thank you :-)
I think that solves one of the problems but I still need to stick with the first script to be able to connect and reconfigure the wifi on the fly.
Thank you Rich!
Navigation
[0] Message Index
Go to full version