3

This might be a weird problem. I just fired up my B model and plugged in a WiPi. I connected to the network and I could reach the Pi via SSH in seconds. But when I disconnect it's unreachable:

failed to connect to 192.168.1.105/192.168.1.105 (post 22):connect failed: EHOSTUNREACH (No route to host)

If I check the Pi it is running well, only the SSH is unreachable. And after a reboot I can reach it only once again.

What can cause this and how could I solve it?

2
  • Do you have a keyboard / screen connected to the Pi ? If you do, try and ping a computer FROM the Pi, and then see if you can acccess the Pi again over SSH
    – Lawrence
    Jul 3, 2013 at 1:23
  • Yes I have, but I can't connect to a network now :\ Jul 3, 2013 at 10:18

2 Answers 2

1

Its because wifi-drivers of r-pi couldn't reconnect automatically.

Add this to your rc.local https://github.com/dirttech/SmartMeter/blob/master/wifi_drop.sh

You can also see this blog for further referrals..

http://luvrajan07.wordpress.com/

4
  • Maybe this helped, but now, I can not connect to a WiFi network :) Jul 3, 2013 at 10:18
  • what do you mean by "can not connect"? or you are using ethernet or else now? Jul 3, 2013 at 10:28
  • I'm using a WiFi adaptor (WiPi) and I can scan for available networks, but I can not connect to mine. Jul 3, 2013 at 11:01
  • I looked for the internet, but only thing I fount is this article. I followed it, but when I try to ping, it prints: "No connection" Jul 3, 2013 at 11:03
4

Since my Pi is stationary at home and uses only one WiFi network, I wrote some scripts to make it automatically reconnect upon lost WiFi connections.

#!/bin/bash                                   

TESTIP=192.168.1.1                            

ping -c4 ${TESTIP} > /dev/null                

if [ $? != 0 ]                                
then                                          
    logger -t $0 "WiFi seems down, restarting"
    ifdown --force wlan0                      
    ifup wlan0                                
else                                         
    logger -t $0 "WiFi seems up."            
fi                                                                    

You can put this script under /usr/local/bin and add the following line to the system wide /etc/crontab:

*/5 * * * * root /usr/local/bin/testwifi.sh

This will check every five minutes if the connection is still up, and restart it, if the router cannot be pinged. If you dislike all the syslog messages, you can comment them out in the script.

My corresponding /etc/network/interfaces looks like this (I uninstalled all the network managers):

auto lo                                                                                  

iface lo inet loopback                                                                   
iface eth0 inet static                                                                   
        address 192.168.3.42                                                             
        netmask 255.255.255.0                                                            

auto wlan0                                                                               
iface wlan0 inet dhcp                                                                    
      pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B
      post-down killall wpa_supplicant ; rmmod 8192cu ; modprobe 8192cu                  

iface default inet dhcp

This is for my WiFi dongle, which uses the 8192cu driver. If yours uses a different one, you need to adjust the above script.

You need to adjust the TESTIP to an IP of your liking (e.g. your Router), and you need to provide /etc/wpa_supplicant/wpa_supplicant.conf. An example config looks like this:

network={
    ssid="myssid"
    psk=12345
}

There are many more configuration options for WiFi networks. So if it does not work, you may have to read a bit about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.