January 24, 2013

Raspberry Pi with 3G and WiFi


Aim: To have a Wireless hotspot in the truck with 3G internet and vehicle tracking
Kit:
  • Raspberry Pi running Raspbian
  • Powered USB Hub
  • Huawei E170 3G Dongle
  • TP-Link TL-WN722N
After several false starts and 10's of hours trying to get various hardware working I settled on the above.

Wireless Setup

apt-get install hostapd dhcpd
nano /etc/hostapd/hostapd.conf

interface=wlan0
driver=nl80211
ssid=3GPi
hw_mode=g
channel=11
wpa=2
wpa_passphrase=xxxxxx
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
auth_algs=3
wmm_enabled=1
nano /etc/dhcp3/dhcpd.conf

subnet 10.10.0.0 netmask 255.255.255.0 {
        range 10.10.0.25 10.10.0.50;
        option domain-name-servers 202.37.101.1, 202.37.101.2;
        option routers 10.10.0.1;}
nano /etc/network/interfaces

auto lo

iface lo inet loopback

iface eth0 inet dhcp
 post-up iptables-restore </etc/network/iptables

allow-hotplug wlan0

iface wlan0 inet static 
  address 10.10.0.1 
  netmask 255.255.255.0 

  post-up /etc/init.d/hostapd start ; /etc/init.d/isc-dhcp-server start 
  down /etc/init.d/hostapd stop ; /etc/init.d/isc-dhcp-server stop
Permanently enable IP forwarding in /etc/sysctl.conf:
net.ipv4.ip_forward=1
nano /etc/network/iptables
*nat
:PREROUTING ACCEPT [2:208]
:INPUT DROP [2:208]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -i wlan0 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 4 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 12 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -s [MY IP AT HOME] -j ACCEPT
:OUTPUT ACCEPT [1:108]
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -o ppp0 -j ACCEPT
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o ppp0 -j MASQUERADE
COMMIT

Managed to get 2MB/s running through it using Plex on the iPad

Setting up 3G



wget "http://www.sakis3g.org/versions/latest/$ARCH/sakis3g.gz" # where $ARCH is either i386 or amd64
gunzip sakis3g.gz
chmod +x sakis3g
./sakis3g --interactive

I have had to make alot of changes to this since I added the GPS as the GPS module moves all the serial ports around. Here is the working config:


USBINTERFACE="0"
USBDRIVER="option"
USBMODEM="12d1:140c"
OTHER="USBMODEM"
MODEM="OTHER"
# Bus 001 Device 006: ID 12d1:140c Huawei Technologies Co., Ltd.
APN=CUSTOM_APN
#2degrees
CUSTOM_APN="direct"
APN_USER="vodafone"
APN_PASS="vodafone"

1 comment:

chuc2rk said...

can this auto connect 3G after reboot