Difference between revisions of "CometMeWindLoggingProject"

Jump to navigationJump to search
Line 26: Line 26:
## move it to "wan" zone
## move it to "wan" zone
## open ssh on wan zone by adding the following in /etc/config/firewall before the final 'include' line:
## open ssh on wan zone by adding the following in /etc/config/firewall before the final 'include' line:
config rule
### config rule
        option name  'accept ssh on wan'
###        option name  'accept ssh on wan'
        option src              wan
###        option src              wan
        option dest_port        22
###        option dest_port        22
        option target          ACCEPT
###        option target          ACCEPT
        option proto            tcp
###        option proto            tcp
## mkdir /root/.ssh
## mkdir /root/.ssh
## chmod 700 /root/.ssh
## chmod 700 /root/.ssh

Revision as of 08:19, 12 November 2013

Setup of a new TL-WR703N router with openwrt preinstalled

  1. Start with an empty SLboat_Mod TP-LINK TL-WR703N
  2. connect ethernet to laptop, laptop uses dhcp
  3. remove ~/.ssh/known_hosts offending lines for ssh access
  4. ssh into it. default password is ? by default it isn't set. set it and add ssh pub key via:;stok=050e6ecb7ab80178f16ec1b9aa83b690/admin/system/admin (just an example, stok will be different)
  5. setup networking via host
    1. If host is connected via wireless, and in the hackerspace, and host has IP of
      1. host: masquerade_via_wlp3s0 (see below)
      2. host: sudo iptables -F (fixme)
      3. wrt: route add default gw
      4. wrt: echo nameserver > /etc/resolv.conf
  6. change hostname to melogger: admin/system/system
  7. set timezone to Beirut: admin/system/system
  8. opkg update
  9. opkg install packages for gsm and lua:
    1. opkg remove usb-uhci
    2. opkg install usb-modeswitch usb-modeswitch-data comgt kmod-usb-serial kmod-usb-serial-option kmod-usb-acm luci-proto-3g luasocket luaposix
    3. opkg install usb-ohci kmod-usb-serial-wwan
  10. reboot. perhaps not required, but I had problems with uhci/ohci or this. Need to redo instructions to test this point.
  11. setup flashair card wireless as client
    1. use wizard: scan, choose flashair, use password. called wwan (the default)
    2. go to interfaces, select wwan, advanced, disable both "Use default gateway" and "Use DNS servers advertised by peer".
  12. connect gsm dongle, insert sim
  13. setup gsm networking
    1. create new interface called umts, for cellcom APN is internetg, the rest is empty (no username, no password)
    2. move it to "wan" zone
    3. open ssh on wan zone by adding the following in /etc/config/firewall before the final 'include' line:
      1. config rule
      2. option name 'accept ssh on wan'
      3. option src wan
      4. option dest_port 22
      5. option target ACCEPT
      6. option proto tcp
    4. mkdir /root/.ssh
    5. chmod 700 /root/.ssh
    6. dropbearkey -f /root/.ssh/id_rsa -t rsa
  14. copy over the public key to cometme server at /.ssh/authorized_keys
  15. test that you can ssh to cometme: ssh -l user -i /root/.ssh/id_rsa server
  16. host: git clone git://gitorious.org/air-sd-logger/air-sd-logger.git
  17. host: cd air-sd-logger
  18. host: make update (assumes ip of router is
    1. copies over main executable to /usr/bin/syncsdtocomet and config file to /root/config.lua
  19. test: run executable locally once.
    1. syncsdtocomet /root/config.lua
  20. setup cron job:
    1. echo '30 0 * * * /usr/bin/syncsdtocomet /root/config.lua > /root/syncsdtocomet.last.log' > /etc/crontabs/root
    2. /etc/init.d/cron start
    3. verify via logread that no parsing errors occured in /etc/crontabs/root
    4. verify symlink in /etc/rc.d
  21. test cron job (check the output, setup time close to it, wait)
    1. date 00:29
    2. logread -f
    3. wait 60 seconds
    4. ^C
    5. you should see a line: Nov 12 00:30:01 melogger cron.info crond[2727]: crond: USER root pid 2762 cmd /usr/bin/syncsdtocomet /root/config.lua > /root/syncsdtocomet.last.log
  22. verify everything is running after a reboot
    1. verify crond is running, there is an internet connection, and an sd card connection.
  23. verify everything is running without ethernet connection
    1. remove ethernet cable.
    2. reboot forcibly (remove power).
    3. wait 60 seconds.
    4. verify: modem is blinking green (ZTE 190), wrt led is solid blue.

Helper: Masquerade script

# 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
BASE=`basename $0`
echo 1 > /proc/sys/net/ipv4/ip_forward
echo masquerading anything to $TARGET
iptables -t nat -F


  • Modem should blink green when connected. It's two faulty modes are:
    • Solid Red. That means the sim didn't register. It is a sim problem, not an openwrt one. Try a different sim. Try sim in phone. Contact gsm provider if nothing works and you can reproduce in a phone.
    • Solid Green. Sim is registered but not in data mode. This is an openwrt configuration error. Try rebooting. Then use logread to look for ppd, or ps. Use ubus call network.interface.umts status for more details. Try removing usb-uhci and installing usb-uhci, and rebooting after.


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

Files are stored at: SD CARD/CSVFILES/LOG

openwrt on wrt701 connected to flashair, with 3g modem connected to internet (development on ethernet,

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)


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:

wget -o - -q | 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:





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


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:


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

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

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).


# 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


  1. cat /usr/bin/listsd
wget -O - -q | grep -e '^wlansd\[' | sed -e 's/wlansd\[[0-9]*\]="//' | sed -e 's/";//'


Sync SD to Comet