Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Fixing Raspberry Pi WiFi dropping issue

Many of our Raspberry Pi projects needs remote accessibility. This means you spends lot of time using either VNC or SSH to access the Raspberry Pi. Unfortunately, when wifi connectivity drops and failed to re-connect your whole world stops right? On such situations, physically accessing the RPi and doing the restart is really a pain.



Writing checkwifi.sh


You can just copy paste this script into "/usr/local/bin/checkwifi.sh"

ping -c4 192.168.1.1 > /dev/null
 
if [ $? != 0 ] 
then
  echo "No network connection, restarting wlan0...!"
  /sbin/ifdown 'wlan0'
  sleep 5
  /sbin/ifup --force 'wlan0'
fi

What we are trying to do is, we are restarting the wireless interface. First it tries to ping a given IP with `ping` command.

Then `$?` represents the exit code of the previous command. In our case, previous command is `ping`. If `ping` command fails will output a different exit code(not 0). Then the code part inside the `if` will be executed. It will turn off, wait 5 seconds and re-start the wireless interface `wlan0`.

And make sure you have necessary execute permissions for the script.

sudo chmod 775 /usr/local/bin/checkwifi.sh

Adding a Cron Job


Open up the cron tab editor by `crontab -e` and add the following lines to the bottom of the file.
*/5 * * * * /usr/bin/sudo -H /usr/local/bin/checkwifi.sh >> /dev/null 2>&1

This script will run every 5 minutes with sudo permission. And the script's output is redirected to /dev/null hence won't clog your sys logs.

Done

Everything is done! now restart your RPi and enjoy!

Setting JAVA_HOME on Raspberry Pi

The new Raspbian build comes with Java 1.8 pre-installed. You can check the current java version by issuing following command;

java -version


java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

In order to set environment variable "JAVA_HOME"; you can set it on ~/.bashrc file.

nano ~/.bashrc


then add the following into the end of file and save changes.

export JAVA_HOME="/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt"
export PATH=$PATH:$JAVA_HOME/bin

Then on you next login you can try out this;

export

which should ideally print;

declare -x JAVA_HOME="/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt"
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin"

Compiling ARM1176 for QEMU Raspberry Pi Emulation Kernel

This is referred from this forum post and optimized for Mac OSX users. This blog post will show you how to compile a QEMU-ready Linux kernel for the ARM1176JZF-S CPU used by the Raspberry Pi. If you want to skip all of this and just have a kernel you can use, you can download 3.18 kernel here.


1. Preparing the development environment

Installing brew

First you need to have a package manager. HomeBrew is a good choice(for more info. refer this post). Or you can use any other such as "macport".
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing libcurses5 library

libncurses5-dev
brew install homebrew/dupes/ncurses
brew link --force ncurses

Installing crosee-compiler tools

You can download pre-compiled cross-compiler tools for MAC OSX from this blog.
After the installation add the binaries to your path.
echo "/usr/local/linaro/arm-linux-gnueabihf-raspbian/bin" >> /etc/paths

2. Preparing the Linux Kernel

Installing Git

Installing any package on homebrew is simple as "brew install <package_name>".
brew install git

Download the source

Download linux source from raspberrypi linux repository.
git clone https://github.com/raspberrypi/linux.git

3. Configure the Kernel

Then we need to configure the kernel accordingly:
cd linux
make ARCH=arm versatile_defconfig
make ARCH=arm menuconfig

Specify the cross-compiler:

General Setup --->
    Cross-compiler tool prefix
        (arm-linux-gnueabihf-)

Note: Do not forget the '-' at the end of this string.
Note: When you select an option make sure you don't see 'M', but '*' (you may need to press space twice).

Select the right CPU options:

System Type --->
    [*] Support ARM V6 processor
    [*] ARM errata: Invalidation of the Instruction Cache operation can fail
    [*] ARM errata: Possible cache data corruption with hit-under-miss enabled

Enable support for hard-float binaries:

Floating point emulation  --->
    [*] VFP-format floating point maths

Enable ARM EABI:

Kernel Features --->
    [*] Use ARM EABI to compile the kernel
    [*] Allow old ABI binaries to run with this kernel

Enable QEMU's disk support:

Bus Support --->
    [*] PCI Support
Device Drivers --->
    SCSI Device Support --->
        [*] SCSI Device Support
        [*] SCSI Disk Support
        [*] SCSI CDROM support
        [*] SCSI low-lever drivers --->
        [*] SYM53C8XX  Version 2 SCSI support

Enable devtmpfs:

    Device Drivers --->
        Generic Driver Options--->
            [*] Maintain a devtmpfs filesystem to mount at /dev
            [*] Automount devtmpfs at /dev, after the kernel mounted the root

Enable the important file systems:

    File systems -->
        <*> Ext3 journalling file system support
         <*> The Extended 4 (ext4) filesystem

Enable tmpfs:

File systems --->
    Pseudo filesystems--->
        [*] Virtual memory file system support (former shm fs)

Enable the event interface:

Device Drivers --->
    Input device support--->
        [*] Event interface

Adding RaspberryPi Logo into Kernel:

Device Drivers --->
    Graphics Support --->
        Console display driver support --->
            [ ] Select compiled-in fonts
                [*] Bootup logo (optional)

Exit, saving the configuration.

4. Compiling the Kernel

make ARCH=arm
mkdir ../modules
make ARCH=arm INSTALL_MOD_PATH=../modules modules_install

Troubleshooting

Error 1:
scripts/mod/modpost.c:1465:7: error: use of undeclared identifier 'R_386_32'
        case R_386_32:

Create a new file elf.h and paste this code from the opensource.apple.com.

nano /usr/local/include/elf.h

In the same file append these...

#define R_386_NONE 0
#define R_386_32 1
#define R_386_PC32 2
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_REL32 3
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6

Error2:

/usr/local/include/elf.h:45:10: fatal error: 'elftypes.h' file not found
#include "elftypes.h" /* In lieu of Solaris <sys/elftypes.h> */

create a new file elftypes.h and paste this code from  the opensource.apple.com.

nano /usr/local/include/elftypes.h

Error 3:

xargs: illegal option -- r

This is because BSD xargs doesn't have the same options as GNU xargs. Install GNU xargs from macports (It should show up earlier in your search path)

# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
brew install findutils

Replace all files using 'xargs' to 'gxargs'. (Use a sublime or any texteditor).

5. Copy compiled Kernel

Copy the compiled kernel to your working directory:

cp arch/arm/boot/zImage ../

Done! You should name have a QEMU-bootable linux kernel and modules in your work directory.