Difference between revisions of "CometMeWindLoggingProject"

Jump to navigationJump to search
Line 98: Line 98:

== Installing a USB Modem presenting as an Ethernet card ==
== Installing a USB Modem presenting as an Ethernet card ==
Tested working modem: 05c6:9025 Qualcomm, Inc. Qualcomm HSUSB Device with 14.07, 3.10.49 ([[User:AlonLevy|AlonLevy]] ([[User talk:AlonLevy|talk]]) 12:42, 19 June 2015 (UTC))
# opkg install kmod-usb-net-cdc-ether
# opkg install kmod-usb-net-cdc-ether
# create an interface called UMTSETHER using the new ethernet interface (eth1 sould be)

== Installing the flashair card ==
== Installing the flashair card ==

Revision as of 12:42, 19 June 2015


This project started as a means to copy data from a sd accessible device to the interwebs.

The sd carrying device (SCD) logs data every set amount of seconds about wind direction, power, and battery voltage. The problem was getting that data from the SCD to a website.

<diagram missing here: SCD->Flashair->OpenWRT->3G->Website>


Installing the router

Setup of a new Barrier Breaker (14.07) flashed router (tested with TL-WR703N and MR-3020)

Setup notes:

  1. Use a usb hub to connect the dongle because of https://dev.openwrt.org/ticket/16733


  1. Start with an empty SLboat_Mod TP-LINK TL-WR703N / 14.07 installed MR-3020/MR-3040
  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 unset, with telnet enabled. Login via telnet, set password. 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 (not required for 14.07, just for previous SLboat_Mod)
    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 (14.07: type UMTS), for cellcom APN is internetg, the rest is empty (no username, no password). For MF-180 choose /dev/ttyUSB2, make sure you rebooted after the opkg step (if you don't there will be no ttyUSB{0,1,2} available)
    2. (check) MF-180: led will blink green. solid red means problem in config.
    3. move it to "wan" zone
    4. 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
    5. mkdir /root/.ssh
    6. chmod 700 /root/.ssh
    7. 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.
  24. setup dynamic dns
    1. create an account at duckdns.org
    2. follow wrt instructions
      1. opkg install ddns-scripts luci-app-ddns
      2. update configuration via luci: services->dynamic dns. The config file:
        1. config service 'duckdns'
        2. option enabled '1'
        3. option domain '<the domain>'
        4. option username 'NA'
        5. option password '<the token>'
        6. option force_interval '72'
        7. option force_unit 'hours'
        8. option check_interval '10'
        9. option check_unit 'minutes'
        10. option update_url 'http://www.duckdns.org/update?domains=[DOMAIN]&token=[PASSWORD]&ip=[IP]'
        11. option interface 'umts'
        12. option ip_source 'interface'
        13. option ip_interface '3g-umts'
  25. setup constant ip for cellcom:
    1. change APN to statreal in /etc/config/network or via luci

Installing a USB Modem presenting as an Ethernet card

Tested working modem: 05c6:9025 Qualcomm, Inc. Qualcomm HSUSB Device with 14.07, 3.10.49 (AlonLevy (talk) 12:42, 19 June 2015 (UTC))

  1. opkg install kmod-usb-net-cdc-ether
  2. create an interface called UMTSETHER using the new ethernet interface (eth1 sould be)

Installing the flashair card

What is the Flashair

It is a SDIO card that is also an Access Point. We use the 16 GB class 10 card.

Configuration of the Flashair card

The card contains a SD_WLAN/CONFIG file (guide), it needs to be edited to contain the following:


Setup on the remote server


rsync for flashair

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

  • sd & wireless card combo (wifisd, flashair)
  • http server on port 80, with whole filesystem contents.
  • Files are stored at: SD CARD/CSVFILES/LOG
  • (development on ethernet,
  • periodically connect to a remote server via ssh

Data flow overview

  • communication:
    • flashair -> openwrt wr703n w/ 3g modem -> host-on-cloud
  • communication paths
    • logger [sd slot]-> flashair sd card [flashair wifi]<-> openwrt [usb socket]-> usb extension cable 10m (hub + 2x5m) [usb socket]-> 3g modem [gsm]->[internet]->[ssh]-> host on cloud
  • physical
    • logger
      • flashair sd card
    • TL-WR703N
      • power adapter
      • usb extension 5 m
        • hub
          • usb extension 5 m
            • 3g modem

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:
    • (incorrect) 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.



dropbear (minimal disk space implementation):


Copying is done 1 per minute with a cronjob

  • * * * * /root/pushlog

Wireless connection as client on openwrt

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.


That's what we currently use, supported well with openwrt.

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 Card 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



D3: http://tonygarcia.me/slides/d3chartintro/

Or maybe python: https://github.com/ContinuumIO/Bokeh Also see this completely unrelated post on python becoming the defacto language for scientific data processing

Buying List

TODO: where are the eyecards


Using docker