Access your home network behind 3G Dongle from outside. Huawei 3131 API included.
3G modems typically do not have public IP address you can connect to from outside. Also operators may have NAT/Firewall solutions that cut down always-on tcp connections that are not regularly used.
This solution enables you to send sms to Huawei 3G dongle, which opens a reverse SSH tunnel to a "cloud" server with public IP address. Cloud server port 2222 is used to route ssh connections to your pi. You can then connect with ssh to your home network thru the "cloud" server.
- sms to your Huawei phone number. Content: "open"
- wait 15 seconds and access your pi with ssh via your cloud server
- ssh -p 2222 pi_username@your.cloudserver.com
- this ssh connection would contact your pi
- Raspberry Pi, (tested also in Mac):
- clone this repository to your pi
- Python 2.7 (included in Raspbian)
- Python libraries: BeautifulSoup, requests (sudo pip install BeautifulSoup, requests)
- Huawei 3131 modem set to connect automatically (HiLink mode).
- plug the modem to your pc and navigate in your browser to http://hi.link and set this there
- while there send sms to your phone to check the phone number of dongle
- usb-modeswitch library installed (sudo apt-get install usb-modeswitch)
- A cloud server with public IP address running open ssh
- most unix and linux distros have it
- You need to create public ssh key in pi: cd ~/.ssh, ssh-keygen -t rsa
- copy it to your cloud server
- ssh-copy-id id_rsa.pub user@host
- Python script can now connect your cloud server without password
- allow port forwarding in cloud server open ssh settings file
- Connect the 3G dongle to powered USB hub. Pi's USB interface does not provide enough power.
- In pi check with command lsusb that 3G modem has switched from storage mode to modem mode. It should show ID 12d1:14db:
- Bus 001 Device 013: ID 12d1:14db Huawei Technologies Co., Ltd.
- Mine worked by just installing usb-modeswitch.
- There are several guides to set this manually if it does not work off-the shelf
- In pi the Huawei 3131 emulates eth port, eth1. You need to get IP address from operator before the script starts to work.
- add following to /etc/network/interfaces
- allow-hotplug eth1
- iface eth1 inet dhcp
- After reboot check if device has ip address by. This also shows Huawei is emulating eth1 port:
- ifconfig eth1
eth1 Link encap:Ethernet HWaddr 58:2c:80:13:92:63
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
- Once all this is setup you can test sms by running "python pi_sms.py". Send sms to your dongle and see if it gets printed to console.
- pi_sms.py implements python api to send and receive sms thru the Huawei 3131. Api uses the web server of the 3131, not tty. The 3131 web api is described here:
(Daemon = background process)
-
change the paths to point to your install location in script file
-
chmod 755 client.py
-
copy the 3G-tunnel.sh script to etc/init.d (sudo needed)
-
chmod it again
-
sudo update-rc.d 3G-tunnel.sh defaults
-
More straightforward alternative would be to use Python supervisor library
Script copied from: