Difference between revisions of "Cellular Communication"

From HiveTool
Jump to: navigation, search
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The main goal for this is to have a hive sending data in areas not covered with network cable to house or outside WiFi range.
+
===Goal===
 +
To have a hive send data in areas not covered with network cable or outside WiFi range.
 
There is also a problem with sites without AC power. This is also covered in the section for Solar Panel.
 
There is also a problem with sites without AC power. This is also covered in the section for Solar Panel.
  
 +
===Equipment===
 
My setup for this is:
 
My setup for this is:
 
*Raspberry Pi
 
*Raspberry Pi
Line 11: Line 13:
 
*WiFi from Raspberry
 
*WiFi from Raspberry
  
 +
===Considerations===
 
There are several things to think about
 
There are several things to think about
 
#Is this the only hive to be connected to internet.
 
#Is this the only hive to be connected to internet.
Line 18: Line 21:
  
  
1. Only one hive connecting<br>
 
  
Connect USB modem to pi<br>
+
==Connecting only one hive==
Check that you can see the USB modem:<br>
+
 
$ lsusb<br>
+
===Connect USB modem to Pi===
Bus 001 Device 004: ID 0c45:7401 Microdia<br>
+
Check that you can see the USB modem:
Bus 001 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem<br>
+
$ '''lsusb'''
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter<br>
+
Bus 001 Device 004: ID 0c45:7401 Microdia
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub<br>
+
Bus 001 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br>
+
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
 +
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub
 +
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
<br>
 +
===Update to latest versions===
 +
$ '''sudo apt-get update'''
 +
<br>
 +
===Add program for connection to modem with disk partition===
 +
$ '''sudo apt-get install usb-modeswitch'''
 
<br>
 
<br>
Update to latest versions<br>
+
===Install PPP driver===
$ sudo apt-get update<br>
+
$ '''sudo apt-get install ppp'''
 
<br>
 
<br>
Add program for connection to modem with disk partition<br>
+
===Download and install Sakis3G application===
$ sudo apt-get install usb-modeswitch<br>
+
This is stable, and easy to configure. More info on www.sakis3g.com
 +
$ '''sudo wget "http://www.sakis3g.com/downloads/sakis3g.tar.gz" -O sakis3g.tar.gz'''
 
<br>
 
<br>
Install PPP driver<br>
+
===Unpack files===
$ sudo apt-get install ppp<br>
+
$ '''sudo tar -xzvf sakis3g.tar.gz'''
 +
Make file executable
 +
$ '''sudo chmod +x sakis3g'''
 
<br>
 
<br>
Download and install Sakis3G application, this is stable, and easy to configure, more info on www.sakis3g.com<br>
+
Copy file to /usr/local/bin
$ sudo wget "http://www.sakis3g.com/downloads/sakis3g.tar.gz" -O sakis3g.tar.gz<br>
+
$ '''sudo cp sakis3g /usr/local/bin'''<br>
Unpack files<br>
 
$ sudo tar -xzvf sakis3g.tar.gz<br>
 
Make file executable<br>
 
$ sudo chmod +x sakis3g<br>
 
 
<br>
 
<br>
Test connection (Use sudo, otherwise it maybe fails to open ports)<br>
+
===Test connection (Use sudo, otherwise it maybe fails to open ports)===
$ sudo ./sakis3g --interactive<br>
+
$ '''sudo ./sakis3g --interactive'''<br>
 
1. Connect with 3G<br>
 
1. Connect with 3G<br>
 
1. USB device<br>
 
1. USB device<br>
 
3. HUAWEI Mobile<br>
 
3. HUAWEI Mobile<br>
1. (internet) - (APN, maybe it differ at your mobile provider)<br>
+
1. (internet) - APNv (It may differ at your mobile provider)<br>
 +
 
 
E180 connected to Phonero (24201). - Connected to internet<br>
 
E180 connected to Phonero (24201). - Connected to internet<br>
 
<br>
 
<br>
 
Check connection information<br>
 
Check connection information<br>
 
<br>
 
<br>
Interface: P-t-P (ppp0)<br>
+
Interface: P-t-P (ppp0)
Connected since: 2016-01-18 14:39<br>
+
Connected since: 2016-01-18 14:39
Kilobytes received: 24<br>
+
Kilobytes received: 24
Kilobytes sent: 6<br>
+
Kilobytes sent: 6
Network ID: 24201<br>
+
Network ID: 24201
Operator name: Phonero<br>
+
Operator name: Phonero
APN: internet<br>
+
APN: internet
Modem: E180<br>
+
Modem: E180
Modem type: USB<br>
+
Modem type: USB
Kernel driver: option<br>
+
Kernel driver: option
Device: /dev/ttyUSB0<br>
+
Device: /dev/ttyUSB0
 
<br>
 
<br>
 
After testing internet connection, disconnect modem from menu<br>
 
After testing internet connection, disconnect modem from menu<br>
 
<br>
 
<br>
Make your own connection command<br>
+
'''Make your own connection command'''<br>
 
<br>
 
<br>
'''$ sudo ./sakis3g connect<br>
+
$ '''sudo ./sakis3g connect'''<br>
'''Please select modem type by using OTHER variable, or by enabling interactive mode.<br>
+
Please select modem type by using OTHER variable, or by enabling interactive mode.<br>
 
         $ /home/pi/sakis3g --interactive "connect"
 
         $ /home/pi/sakis3g --interactive "connect"
  
 
Available options are:<br>
 
Available options are:<br>
USBMODEM        USB device<br>
+
'''USBMODEM        USB device'''<br>
 
BLUETOOTH      Bluetooth modem<br>
 
BLUETOOTH      Bluetooth modem<br>
 
CUSTOM_TTY      Custom tty...<br>
 
CUSTOM_TTY      Custom tty...<br>
  
 
Example:
 
Example:
        $ /home/pi/sakis3g OTHER="USBMODEM"
+
$ /home/pi/sakis3g OTHER="USBMODEM"
  
$ sudo ./sakis3g OTHER="USBMODEM" connect<br>
+
$ '''sudo ./sakis3g OTHER="USBMODEM" connect'''<br>
 
Please select USB modem by using USBMODEM variable, or by enabling interactive mode.<br>
 
Please select USB modem by using USBMODEM variable, or by enabling interactive mode.<br>
 
         $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "connect"
 
         $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "connect"
Line 90: Line 100:
 
0424:9512      BUSNUM=001<br>
 
0424:9512      BUSNUM=001<br>
 
0424:ec00      BUSNUM=001<br>
 
0424:ec00      BUSNUM=001<br>
12d1:1003      HUAWEI Mobile<br>
+
'''12d1:1003'''       HUAWEI Mobile<br>
 
1d6b:0002      DWC OTG Controller<br>
 
1d6b:0002      DWC OTG Controller<br>
  
Line 96: Line 106:
 
         $ /home/pi/sakis3g USBMODEM="0424:9512"
 
         $ /home/pi/sakis3g USBMODEM="0424:9512"
  
$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" connect<br>
+
$ '''sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" connect'''<br>
 
Please select APN by using APN variable, or by enabling interactive mode.
 
Please select APN by using APN variable, or by enabling interactive mode.
 
         $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "USBMODEM=12d1:1003" "connect"
 
         $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "USBMODEM=12d1:1003" "connect"
  
 
Available options are:<br>
 
Available options are:<br>
internet        (internet)<br>
+
'''internet        (internet)'''<br>
 
CUSTOM_APN      Custom APN… <br>
 
CUSTOM_APN      Custom APN… <br>
  
 
Example:
 
Example:
        $ /home/pi/sakis3g APN="internet"
+
$ /home/pi/sakis3g APN="internet"
  
$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" connect<br>
+
$ '''sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" connect'''<br>
 
E180 connected to Phonero (24201).<br>
 
E180 connected to Phonero (24201).<br>
$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" disconnect<br>
+
$ '''sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" disconnect'''<br>
 
Disconnected.<br>
 
Disconnected.<br>
 +
 +
== Connecting more hives to modem ==
 +
First is to find out if you want to use static or DHCP setup for your hives.<br>
 +
If you want to have static setup there is more information on this on other pages here<br>
 +
 +
'''DHCP setup
 +
'''<br>
 +
===Install software===
 +
'''$ sudo apt-get install hostapd isc-dhcp-server'''
 +
 +
===Select interfaces you will use Pi as a DHCP server===
 +
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?<br>
 +
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".<br>
 +
 +
'''$ sudo vi /etc/default/isc-dhcp-server'''
 +
 +
INTERFACES="'''eth0 wlan0'''"
 +
 +
===Set up DHCP service===
 +
'''$ sudo vi /etc/dhcp/dhcpd.conf'''
 +
 +
At the end put in the network setup you will use:
 +
 +
subnet 192.168.42.0 netmask 255.255.255.0 {
 +
  range 192.168.42.10 192.168.42.50;
 +
  option broadcast-address 192.168.42.255;
 +
  option routers 192.168.42.1;
 +
  default-lease-time 600;
 +
  max-lease-time 7200;
 +
  option domain-name "local";
 +
  option domain-name-servers 8.8.8.8, 8.8.4.4;
 +
 +
===Put in static address on the interfaces===
 +
'''$ sudo vi /etc/network/interfaces'''
 +
 +
source-directory /etc/network/interfaces.d<br>
 +
 +
auto lo<br>
 +
iface lo inet loopback<br>
 +
'''up iptables-restore < /etc/iptables.ipv4.nat'''<br>
 +
<br>
 +
iface eth0 inet manual<br>
 +
<br>
 +
'''iface eth0 inet dhcp<br>
 +
iface eth0 inet static<br>
 +
address 192.168.42.1<br>
 +
netmask 255.255.255.0<br>
 +
gateway 192.168.42.1'''<br>
 +
 +
allow-hotplug wlan0<br>
 +
#iface wlan0 inet manual<br>
 +
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf<br>
 +
''' iface wlan0 inet static<br>
 +
  address 192.168.42.2<br>
 +
  netmask 255.255.255.0<br>
 +
'''
 +
allow-hotplug wlan1<br>
 +
iface wlan1 inet manual<br>
 +
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf<br>
 +
 +
 +
===Set up WiFi as a access point===
 +
 +
'''$ sudo vi /etc/hostapd/hostapd.conf'''
 +
 +
interface='''wlan0'''
 +
driver=rtl871xdrv
 +
ssid='''Pi_AP'''
 +
hw_mode=g
 +
channel=6
 +
macaddr_acl=0
 +
auth_algs=1
 +
ignore_broadcast_ssid=0
 +
wpa=2
 +
wpa_passphrase='''Raspberry'''
 +
wpa_key_mgmt=WPA-PSK
 +
wpa_pairwise=TKIP
 +
rsn_pairwise=CCMP
 +
 +
'''$ sudo vi /etc/default/hostapd<br>
 +
''' DAEMON_CONF="/etc/hostapd/hostapd.conf"<br>
 +
 +
'''$ sudo vi /etc/sysctl.conf'''<br>
 +
At the end put in this line<br>
 +
net.ipv4.ip_forward=1<br>
 +
<br>
 +
'''$ wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
 +
'''<br>
 +
--2015-12-11 20:58:59--  http://adafruit-download.s3.amazonaws.com/adafruit_host<br>                                                                                                                                                           
 +
'''$ sudo unzip adafruit_hostapd_14128.zip<br>'''
 +
Archive:  adafruit_hostapd_14128.zip<br>
 +
  inflating: hostapd<br>
 +
'''$ sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG<br>'''
 +
'''$ sudo mv hostapd /usr/sbin<br>'''
 +
'''$ sudo chmod 755 /usr/sbin/hostapd<br>'''
 +
'''$ sudo service hostapd start<br>'''
 +
'''$ sudo service isc-dhcp-server start<br>'''
 +
Job for isc-dhcp-server.service failed. See 'systemctl status isc-dhcp-server.service' and 'journalctl -xn' for details.<br>
 +
 +
<br>
 +
 +
==Set up Firewall (iptables)==
 +
<br>
 +
'''$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE'''
 +
'''$ sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT'''
 +
'''$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT'''
 +
'''$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE'''
 +
'''$ sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT'''
 +
'''$ sudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT'''
 +
'''$ sudo iptables -A FORWARD -i ppp0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT'''
 +
'''$ sudo iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT'''
 +
'''$ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"'''

Latest revision as of 03:31, 12 March 2016

Goal

To have a hive send data in areas not covered with network cable or outside WiFi range. There is also a problem with sites without AC power. This is also covered in the section for Solar Panel.

Equipment

My setup for this is:

  • Raspberry Pi
  • HAT board
  • Weighing cells
  • 2 x DHT22 Temperatur / Humidity sensors
  • TSL2591 Lux sensor
  • Edimax E180 3G modem
  • WiFi from Raspberry

Considerations

There are several things to think about

  1. Is this the only hive to be connected to internet.
  2. If there is more that one, you need to set it up as a router.
  3. If there is only two hives a ethernet cable between would be the most power effeciant.
  4. If there is more than two, you need a ethernet hub or using wifi between hives (wifi use a lot of power)


Connecting only one hive

Connect USB modem to Pi

Check that you can see the USB modem:

$ lsusb
Bus 001 Device 004: ID 0c45:7401 Microdia
Bus 001 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E230/E270/E870 HSDPA/HSUPA Modem
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. LAN9500 Ethernet 10/100 Adapter / SMSC9512/9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


Update to latest versions

$ sudo apt-get update


Add program for connection to modem with disk partition

$ sudo apt-get install usb-modeswitch


Install PPP driver

$ sudo apt-get install ppp


Download and install Sakis3G application

This is stable, and easy to configure. More info on www.sakis3g.com

$ sudo wget "http://www.sakis3g.com/downloads/sakis3g.tar.gz" -O sakis3g.tar.gz


Unpack files

$ sudo tar -xzvf sakis3g.tar.gz

Make file executable

$ sudo chmod +x sakis3g


Copy file to /usr/local/bin

$ sudo cp sakis3g /usr/local/bin


Test connection (Use sudo, otherwise it maybe fails to open ports)

$ sudo ./sakis3g --interactive

1. Connect with 3G
1. USB device
3. HUAWEI Mobile
1. (internet) - APNv (It may differ at your mobile provider)

E180 connected to Phonero (24201). - Connected to internet

Check connection information

Interface: P-t-P (ppp0)
Connected since: 2016-01-18 14:39
Kilobytes received: 24
Kilobytes sent: 6
Network ID: 24201
Operator name: Phonero
APN: internet
Modem: E180
Modem type: USB
Kernel driver: option
Device: /dev/ttyUSB0


After testing internet connection, disconnect modem from menu

Make your own connection command

$ sudo ./sakis3g connect

Please select modem type by using OTHER variable, or by enabling interactive mode.

       $ /home/pi/sakis3g --interactive "connect"

Available options are:
USBMODEM USB device
BLUETOOTH Bluetooth modem
CUSTOM_TTY Custom tty...

Example:

$ /home/pi/sakis3g OTHER="USBMODEM"
$ sudo ./sakis3g OTHER="USBMODEM" connect

Please select USB modem by using USBMODEM variable, or by enabling interactive mode.

       $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "connect"

Available options are:
0424:9512 BUSNUM=001
0424:ec00 BUSNUM=001
12d1:1003 HUAWEI Mobile
1d6b:0002 DWC OTG Controller

Example:

       $ /home/pi/sakis3g USBMODEM="0424:9512"

$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" connect
Please select APN by using APN variable, or by enabling interactive mode.

       $ /home/pi/sakis3g --interactive "OTHER=USBMODEM" "USBMODEM=12d1:1003" "connect"

Available options are:
internet (internet)
CUSTOM_APN Custom APN…

Example:

$ /home/pi/sakis3g APN="internet"
$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" connect

E180 connected to Phonero (24201).

$ sudo ./sakis3g OTHER="USBMODEM" USBMODEM="12d1:1003" APN="internet" disconnect

Disconnected.

Connecting more hives to modem

First is to find out if you want to use static or DHCP setup for your hives.
If you want to have static setup there is more information on this on other pages here

DHCP setup

Install software

$ sudo apt-get install hostapd isc-dhcp-server 

Select interfaces you will use Pi as a DHCP server

  1. On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
  2. Separate multiple interfaces with spaces, e.g. "eth0 eth1".

$ sudo vi /etc/default/isc-dhcp-server

INTERFACES="eth0 wlan0"

Set up DHCP service

$ sudo vi /etc/dhcp/dhcpd.conf

At the end put in the network setup you will use:

subnet 192.168.42.0 netmask 255.255.255.0 {
 range 192.168.42.10 192.168.42.50;
 option broadcast-address 192.168.42.255;
 option routers 192.168.42.1;
 default-lease-time 600;
 max-lease-time 7200;
 option domain-name "local";
 option domain-name-servers 8.8.8.8, 8.8.4.4;

Put in static address on the interfaces

$ sudo vi /etc/network/interfaces

source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback
up iptables-restore < /etc/iptables.ipv4.nat

iface eth0 inet manual

iface eth0 inet dhcp
iface eth0 inet static
address 192.168.42.1
netmask 255.255.255.0
gateway 192.168.42.1

allow-hotplug wlan0
#iface wlan0 inet manual
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static
address 192.168.42.2
netmask 255.255.255.0
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


Set up WiFi as a access point

$ sudo vi /etc/hostapd/hostapd.conf
interface=wlan0
driver=rtl871xdrv
ssid=Pi_AP
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
$ sudo vi /etc/default/hostapd

DAEMON_CONF="/etc/hostapd/hostapd.conf"

$ sudo vi /etc/sysctl.conf
At the end put in this line
net.ipv4.ip_forward=1

$ wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
--2015-12-11 20:58:59-- http://adafruit-download.s3.amazonaws.com/adafruit_host
$ sudo unzip adafruit_hostapd_14128.zip
Archive: adafruit_hostapd_14128.zip

 inflating: hostapd

$ sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
$ sudo mv hostapd /usr/sbin
$ sudo chmod 755 /usr/sbin/hostapd
$ sudo service hostapd start
$ sudo service isc-dhcp-server start
Job for isc-dhcp-server.service failed. See 'systemctl status isc-dhcp-server.service' and 'journalctl -xn' for details.


Set up Firewall (iptables)


$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
$ sudo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
$ sudo iptables -A FORWARD -i ppp0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -A FORWARD -i wlan0 -o ppp0 -j ACCEPT
$ sudo iptables -A FORWARD -i ppp0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$ sudo iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT
$ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"