CometMeWindLoggingProject

From TAMI
Revision as of 21:50, 11 November 2013 by AlonLevy (talk | contribs)
Jump to navigationJump to search

Redoing everything, step by step

  • Start with an empty SLboat_Mod TP-LINK TL-WR703N
  • remove ~/.ssh/known_hosts offending lines for ssh access
  • ssh into it. default password is ? by default it isn't set. set it and add ssh pub key via: http://192.168.1.1/cgi-bin/luci/;stok=050e6ecb7ab80178f16ec1b9aa83b690/admin/system/admin (just an example, stok will be different)
  • setup networking via host
    • If host is connected via wireless, and in the hackerspace, and host has IP of 192.168.1.239:
      • host: masquerade_via_wlp3s0 (see below)
      • host: sudo iptables -F (fixme)
      • wrt: route add default gw 192.168.1.239
      • wrt: echo nameserver 10.81.2.1 > /etc/resolv.conf
  • change hostname to melogger: admin/system/system
  • set timezone to Beirut: admin/system/system
  • opkg update
  • opkg install packages for gsm and lua:
    • opkg remove usb-uhci
    • opkg install usb-modeswitch usb-modeswitch-data comgt kmod-usb-serial kmod-usb-serial-option kmod-usb-acm luci-proto-3g luasocket luaposix
    • opkg install usb-ohci kmod-usb-serial-wwan
  • setup flashair card wireless as client
    • use wizard: scan, choose flashair, use password. called wwan (the default)
    • go to interfaces, select wwan, advanced, disable both "Use default gateway" and "Use DNS servers advertised by peer".
  • connect gsm dongle, insert sim
  • setup gsm networking
    • create new interface called umts
  • host: git clone git://gitorious.org/air-sd-logger/air-sd-logger.git
  • host: cd air-sd-logger
  • host: make update (assumes ip of router is 192.168.1.1)
  • test: run executable locally once.
  • setup cron job: FILLME
  • test cron job (check the output, setup time close to it, wait)

Helper: Masquerade script

#!/bin/bash
# symlink me to "masquerade_via_INTERFACE", i.e. masquerade_via_em1 if you are connected to ethernet, masquerade_via_wlp3s0 if wlp3s0 is your wireless interface name.
if [ $UID != 0 ]; then
    exec sudo $0
fi
BASE=`basename $0`
TARGET=${BASE#masquerade_via_}
echo 1 > /proc/sys/net/ipv4/ip_forward
echo masquerading anything to $TARGET
iptables -t nat -F
iptables -t nat -A POSTROUTING -o $TARGET -j MASQUERADE

Architecture

sd&wireless card combo (wifisd, flashair) http server on port 80, with whole filesystem contents.

Files are stored at: SD CARD/CSVFILES/LOG

192.168.0.1/24

openwrt on wrt701 connected to flashair, with 3g modem connected to internet (development on ethernet, 192.168.1.1/24)

periodically connect to a remote server via ssh

dropbear (minimal disk space implementation):

comet-me server is hosted weirdly, the root is at /, so you need to place the public keys in /.ssh/authorized_keys (permissions 700 for directory, 600 for file

Notes

Copying is done 1 per minute with a cronjob

  • * * * * /root/pushlog

The flashair client wireless connection was created with the "wizard" from the scanned access points and then manually set to

  1. ignore routes
  2. ignore dns

This is important since it takes precedence during name resolution since it appears *last*, i.e. the reverse of the usual name resolution order (as by glibc). This is a dnsmasq-ism. The actual resolv.conf is in /tmp/resolv.conf.auto I believe (writing from memory)

dropbear scp client doesn't have an option to set the user name, and since the user name contains an at sign (@) I used cat (8 bit clean when ssh is used without a pty, i.e. running a command, at least I hope - only tested text files..)

Secondly, ssh of dropbear needs an explicit identity to do public key authentication. The whole /root/pushlog is:

#/bin/sh
wget -o - -q http://192.168.0.1/CSVFILES/LOG | ssh -i ~/.ssh/id_rsa -l user@name example.com "cat > $HOME/LOG"

GDM/3G Modem with Antenna

One of the requirements is to have the modem in a cave, and the antenna external. One solution would be a long usb cable, but it looks like it would be less robust to random errors, so we are going with a long antenna.

Huawei 3131

Relatively new (2012), at Huawei

Final cart:

  • 15ft RG58 External Antenna Extension Coax RF Jumper Cable FME male to FME female
  • 5dbi 900MHz GSM Antenna cable with FME female magnetic
  • FME plug TO TS9 right angle connector with 15cm cable antenna HUAWEI ZTE adapter pigtail cable customize free shipping
    • plug == Male (pin in the middle).

Purchase links:

Reference

SMA, RPSMA

CRC9, TS9 - TODO

FME

SD Carc with Wifi

This is hopefully identical to what Noam has:

  • 4GB SD (Secure Digital) Eye-Fi card - Includes Wifi module that allows wireless data transfer to any wifi-enabled device - Easy setup and photo sharing with included software - Automatic file upload frees memory card space - Device compatibility with SDHC format - Included USB adapter - Class 4 Speed rating
    • 206 nis in plonter

openwrt setup

  • starting from OpenWrt_SLboat_Mod - second attempt. Thanks Yair!
  • wifi left for last, first setup usb gsm dongle
  • adding ssh key via system->administration menu item (/etc/config/somewhere FILLME)
  • using Huawei 3131
  • get working internet. since wifi is off got it via masquerade from laptop.
  • Installing extra packages per http://wiki.openwrt.org/doc/recipes/3gdongle
    • cannot see device (/sys/kernel/debug/usb/devices shows the device with (None) driver)
    • installing kmod-usb-net-cdc-ether (saw fedora use it)
  • installed modeswitch (needed too according to fedora)
  • Created /etc/usb_modeswitch.d/12d1:14db (copied from 14d1)
# Huawei E3131

TargetVendor=  0x12d1
TargetProduct= 0x14db

MessageContent="55534243123456780000000000000011062000000100000000000000000000"

3g (umts) setup

  • cdc_ether works, but now it isn't appropriate for all the gcom (serial) oriented howto's.
  • ifconfig -a shows eth1 with hw addr (static?) 58:2C:80:13:92:63
    • attempting to do ifconfig up does a reboot. not a good sign. maybe reuse my old stick for now.

switched back to cdc_acm using modem (ZTE190M ?)

  • logread for log debugging. Showing failure:
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: AT+CGDCONT=1,"IP","internet.rl"^M^M
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: OK
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]:  -- got it
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: send (ATD*99***1#^M)
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: expect (CONNECT)
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: ^M
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: ATD*99***1#^M^M
Sep  8 18:02:16 OpenWrt_SLboat_Mod local2.info chat[19013]: ERROR

This was fixed by seemingly removing and reinserting the dongle. So it had some state which I don't know how to query or reset yet. If I can figure it out I can add it to the chat script. In the debugging process verified it works on my main machine by "systemctl stop ModemManager; systemctl stop NetworkManager"; remove and reinsert dongle to my machine. use minicom to isue the above commands: one that isn't shown, and AT+CGDCONT=1,"IP","internet.rl" plus ATD*99***1# and got CONNECT 7200000 (maybe an extra zero there).

Networking setup on the OpenWRT

Two zones:

  • lan: contains umts + lan (yes, lan is the zone label and a network label)
  • wan: actually wrongly named, this contains just wwan (again wrongly named), the wireless flashair (Client mode) connection.

Zone firewall config - the masquerade is for using the internet connection (since I didn't have two) and can be turned off, but since it requires a lan connection to be effective it doesn't pose a security problem, so better leave it for convenience when debugging.

  • lan: Input accept, Output accept, Forward accept, Masquerade on, MSS clamping off.
  • wan: Input reject, Output accept, Forward reject, Masquerade off, MSS clamping off.

Networks: we have three, one bridge (pointless but there), pay attention:

  • LAN: bridge is br-lan, it contains the ethernet interface (eth0) only.
  • UMTS: contains 3g-umts.
  • WWAN: contains Client flashair. The client was created via the "scan" button on the interface.

A quick way to create all of these is just to ignore the above and dump the following files inside /etc/config:

/etc/config/network:

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config interface 'lan'
	option ifname 'eth0'
	option type 'bridge'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'

config interface 'umts'
	option proto '3g'
	option apn 'internet.rl'
	option username 'rl@3g'
	option password 'rl'
	option device '/dev/ttyUSB2'
	option service 'umts'

config interface 'wwan'
	option proto 'dhcp'
	option defaultroute '0'
	option peerdns '0'

Notice ttyUSB2! the modem I'm using comes up with 3 serial interfaces after usb modeswitch finishes turning it from a storage device to a modem, and only the third is usable as a modem (maybe the others are for firmware upload or a non AT interface or debugging).

/etc/config/wireless:

# cat /etc/config/wireless

config wifi-device 'radio0'
	option type 'mac80211'
	option hwmode '11ng'
	option macaddr '8c:21:0a:ee:f4:50'
	option htmode 'HT20'
	list ht_capab 'SHORT-GI-20'
	list ht_capab 'SHORT-GI-40'
	list ht_capab 'RX-STBC1'
	list ht_capab 'DSSS_CCK-40'
	option txpower '27'
	option country 'US'
	option disabled '0'
	option channel '6'

config wifi-iface
	option network 'wwan'
	option ssid 'flashair'
	option encryption 'psk2'
	option device 'radio0'
	option mode 'sta'
	option bssid 'E8:E0:B7:18:8B:DF'
	option key '<password here>'

Copying things over from SD to an ssh server somewhere

I would really like to use rsync, but for that I would need to have a sort of http filesystem. Barring that, poor man's rsync:

  • generate a list of files on card, and their dates in memory
  • for each file, record last time it was synced (/root/sdsync/file_name is an ascii file containing that time - or just touch it with that time, even better)
  • if that is older then current date of file then sync.
  • to optimize sync, do it in one go by using something like uuencode: (for file in files; uuencode file -) | ssh uudecode_all_files

Helpers

  1. cat /usr/bin/listsd
#!/bin/sh
wget -O - -q http://192.168.0.1/CSVFILES/LOG | grep -e '^wlansd\[' | sed -e 's/wlansd\[[0-9]*\]="//' | sed -e 's/";//'

Lua

Sync SD to Comet

https://gitorious.org/air-sd-logger/air-sd-logger/