IoT Bytes

Bits and Bytes of IoT

Raspberry Pi 3 Built-in WiFi Module with piCore

Pradeep Singh | 1st Sep 2017

wifi

1. Prerequisites:

Before beginning with this article, you should have piCore up and running on your Raspberry Pi. If you need help with piCore installation you can go through the following article –

piCore (Tiny Core) Linux on Raspberry Pi

2. Hardware and Software Details:

Most of the piCore configurations are very specific to the hardware and software versions. Following are the details of piCore and Raspberry Pi, I am using for this article –

2.1 piCore Image – I am using “piCore-9.0.3.zip” piCore image downloaded from the following url –

http://distro.ibiblio.org/tinycorelinux/9.x/armv6/releases/RPi/

2.3 Hardware – I am using Raspberry Pi 3 with built-in WiFi module.

3. Install Linux Packages:

To the WiFi module work you need to install the Firmware for built-in module and the CLI based wifi utility –

3.1 Install firmware for built-in wifi module using the “tce-load –wi firmware-rpi3-wireless.tcz” command –

tc@box:/usr/local/bin$ tce-load -wi firmware-rpi3-wireless.tcz 
Downloading: firmware-rpi3-wireless.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
firmware-rpi3-wirele 100% |********************************************************| 248k 0:00:00 ETA
firmware-rpi3-wireless.tcz: OK
tc@box:/usr/local/bin$

3.2 Install CLI based wifi tool module for piCore using the “tce-load -wi wifi.tcz” command –

tc@box:~$ tce-load -wi wifi.tcz
wifi.tcz.dep OK
wireless_tools.tcz.dep OK
wpa_supplicant.tcz.dep OK
readline.tcz.dep OK
Downloading: readline.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
readline.tcz 100% |********************************************************| 116k 0:00:00 ETA
readline.tcz: OK
Downloading: libnl.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
libnl.tcz 100% |********************************************************| 240k 0:00:00 ETA
libnl.tcz: OK
Downloading: wpa_supplicant.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wpa_supplicant.tcz 100% |********************************************************| 364k 0:00:00 ETA
wpa_supplicant.tcz: OK
Downloading: wireless-4.9.22-piCore-v7.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wireless-4.9.22-piCo 100% |********************************************************| 2544k 0:00:00 ETA
wireless-4.9.22-piCore-v7.tcz: OK
Downloading: libiw.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
libiw.tcz 100% |********************************************************| 16384 0:00:00 ETA
libiw.tcz: OK
Downloading: wireless_tools.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wireless_tools.tcz 100% |********************************************************| 40960 0:00:00 ETA
wireless_tools.tcz: OK
Downloading: wifi.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wifi.tcz 100% |********************************************************| 8192 0:00:00 ETA
wifi.tcz: OK
tc@box:~$

4. Reboot Raspberry Pi:

Reboot your Raspberry Pi so that piCore can detect built-in WiFi module by installing the firmware and expose the wlan0 interface. You can use “sudo reboot” command to reboot the system.

5. Connect to WiFi Network:

After system boot up run WiFi CLI interface using the “sudo /usr/local/bin/wifi.sh” command. You will be prompted with a list of available WiFi Networks. Select your WiFi SSID and enter the password associated with that.

tc@box:~$ sudo /usr/local/bin/wifi.sh 
Found wifi device wlan0
Standby for scan of available networks...
Set to try a few times to obtain a lease.
Sorting

Select Wifi Network
    ESSID                 Enc Qual Channel Type 
 1. TP-LINK_POCKET_3020_6EFD56   on 70 11 WPA
 2. JOKER                  on 70 11 WPA
 3. koshln                 on 60   1 WPA
 4. Bagla                  on 46 11 WPA
 5. Tarazan                on 43   1 WPA
 6. HP-Print-65-Officejet 4630   off 42   6 
 7. khatrias               on 41   6 WPA
 8. stoury                 on 40   1 WP
 9. Sargun                 on 40   1 WPA
10. RAJ                    on 39   6 WPA
11. getit248               on 32 11 WPA

Enter selection ( 1 - 14 ) or (q)uit: 2
Enter password for JOKER (8 to 63 characters): myfunnypass
Sending credentials to requested access point JOKER..
deleting routers
adding dns 8.8.8.8
adding dns 94.206.20.134
adding dns 94.206.181.22
tc@box:~$

With this, you should be connected to your WiFi network. You can check the configuration of your “wlan0” interface using “ifconfig wlan0” command –

tc@box:~$ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr B8:27:EB:90:31:C8 
inet addr:192.168.1.105 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:2086 (2.0 KiB) TX bytes:1028 (1.0 KiB)
tc@box:~$

The WiFi SSID and Password will be saved in “/home/tc/wifi.db” file, allowing you to reconnect to the same WiFi Network again without entering the password.

tc@box:~$ cat /home/tc/wifi.db 
JOKER myfunnypass WPA
tc@box:~$ 

6. Configure Auto-Connect at System Boot-up (Config Persistence):

6.1 To connect to the WiFi network automatically immediately after the system reboot execute the following command –

sudo echo '/usr/local/bin/wifi.sh -a 2>&1 > /tmp/wifi.log' >> /opt/bootlocal.sh

This command will add an entry to “/opt/bootlocal.sh” file, that will get executed as soon as the system comes up after the boot process.

tc@box:~$ sudo echo '/usr/local/bin/wifi.sh -a 2>&1 > /tmp/wifi.log' >> /opt/bootlocal.sh 
tc@box:~$ 
tc@box:~$ cat /opt/bootlocal.sh 
#!/bin/sh

# Start serial terminal
/usr/sbin/startserialtty &

# Set CPU frequency governor to ondemand (default is performance)
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

# Load modules
/sbin/modprobe i2c-dev

# Start openssh daemon
/usr/local/etc/init.d/openssh start

# ------ Put other system startup commands below this line
/usr/local/bin/wifi.sh -a 2>&1 > /tmp/wifi.log
tc@box:~$

6.2 After altering “/opt/bootlocal.sh” file, you need to save the changes. To do this you can execute the “filetool.sh -b” command.

tc@box:~$ filetool.sh -b
Backing up files to /mnt/mmcblk0p2/tce/mydata.tgz/
Done.
tc@box:~$ 

7. Reboot Raspberry Pi:

Reboot the Raspberry Pi using “sudo reboot” to test the configuration persistence.

Once the system boot process gets completed check “wlan0” configuration using the “ifconfig wlan0” command. You should notice that the wlan0 is now connected with WiFi network and has the IP Address assigned to it –

tc@box:~$ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr B8:27:EB:90:31:C8 
inet addr:192.168.1.105 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84 errors:0 dropped:3 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:6058 (5.9 KiB) TX bytes:1028 (1.0 KiB)
tc@box:~$

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: