I did not invent this recipe, but there wasn't a single one that covered all aspects to get this (simple?) WiFi -> TCP -> Serial setup working. The following are merely telegraphic notes to be able to reproduce this installation _rapidly_. I will add in as many references inline as possible (when/if applicable).
Get one, any one... doesn't need to be a powerful one but having only 2 USB ports might cut you short (one port for the USB2Serial and one for the Wifi dongle leaves you portless if you want to, say, connect a USB joystick). so I got a B+.
I had a TRENDnet's TU-S9 lying around (and knew it works "out of the box" under linux so I used that...
Get one, NOT any one/model. Get one that will WORK FLAWLESSLY. I had issues with the cheapass one that came with the CANA Kit I bought (RT5370 chipset).
My original intent was to create an Ad-Hoc network, unfortunately, it seems this 'mode' is ill supported and proved to be very unstable. I tried setting it up with:
- Ralink RT5370 <-- sucks
- TRENDnet TEW-424UB <-- sucks less, I happened to have it lying around
- TP-Link TL-WN722N <-- proves to be _stable_ in AP mode (RPI is powered with a cigarette lighter 12V->5V 2A USB plug)
(Debian) For the time being, I will use the laziest approach: use the Debian installed on the card that comes with the RPI. This is super sub-optimal as there is a sift-load of junk included in those images.
Don't want to have to remember the IP of the SkyPi and networks stuff... We start by naming the RPI as SkyPi-EQ6 (just so we are consistent with the rest of this document), but only for the wlan0 interface (the RPI's "real" name will remain SkyPi when plugged via eth0)
vim /etc/hosts 127.0.1.1 SkyPi 192.168.168.1 SkyPi-eq6
Now let's install dnsmasq and perform a minimal configuration (find and uncomment/modify the lines described below)
apt-get install dnsmasq vim /etc/dnsmasq.conf
By default, all lines are comments, so simply add/modify the following lines:
interface=wlan0 dhcp-range=192.168.168.50,192.168.168.100,12h port=0 # we don't want/need DNS
Now restart the service:
root@SkyPi:~# /etc/init.d/dnsmasq restart [ ok ] Restarting DNS forwarder and DHCP server: dnsmasq.
We need to disable ifplugd, it does a bad job of managing wlan0's IP and, when cycled (ie:hostapd restart), the interface looses its IP (referring specifically to the AP mode with hostapd below). I got the hint from here.
INTERFACES="eth0" HOTPLUG_INTERFACES="eth0" ARGS="-q -f -u0 -d10 -w -I" SUSPEND_ACTION="stop"
The below configuration is inspired by this link which was quite useful. The only part missing is the "DISABLE ifplugd" above.
apt-get install hostapd vim /etc/hostapd/hostapd.conf
interface=wlan0 # trying mac80211 which is used by ath9k_htc TL-WN722N driver=mac80211 ssid=SkyPi-EQ6 hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 # NOTE: the passphrase has to be _at least_ 5 chars long wpa_passphrase=skypi-eq6 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
_NOTE_: tried this, with 3 different WiFi dongles and got very little success (very unstable)...
We _tried_ to set up an AdHoc network for the moment to mimic other products out there that allow anyone to connect to the scope (like...you're out in the wild, give me a @#$$% break you security zealot!).
auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 # iface wlan0 inet manual # wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf # iface default inet dhcp iface wlan0 inet static address 192.168.168.1 netmask 255.255.255.0 wireless-channel 1 wireless-essid SkyPi wireless-mode ad-hoc wireless-power off # let's not fall asleep while watching stars
NOTE: this obviously assumes you have a compatible USB to Serial adaptor (ie: TRENDnet's TU-S9)
This is the 'real magic' part that removes the serial wire. I got the quick hint from this thread on an astronomy blog. Quite literally: Install ser2net:
sudo apt-get install ser2net
Configure ser2net: At the bottom of /etc/ser2net.conf, add the following line:
4030:raw:10:/dev/ttyUSB0:9600 8DATABITS NONE 1STOPBIT
then start ser2net using
sudo service ser2net start
Some notes and outputs you might see.
Enable debug and restart dnsmasq: uncomment:
It works, but most devices need to be 'told' to look for it (ie: on your cell, disable/enable WIFI and it will show up). Everything indicates that it isn't working initially but the wireless _is_ up with the IP specified above:
root@SkyPi:~# ifdown wlan0 root@SkyPi:~# ifup wlan0 Error for wireless request "Set Mode" (8B06) : SET failed on device wlan0 ; Device or resource busy. root@SkyPi:~# ifplugstatus wlan0: unplugged lo: link beat detected eth0: link beat detected root@SkyPi:~# ifconfig eth0 Link encap:Ethernet HWaddr b8:27:eb:cf:71:49 inet addr:192.168.1.23 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:597750 errors:0 dropped:0 overruns:0 frame:0 TX packets:153587 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:540980151 (515.9 MiB) TX bytes:14085912 (13.4 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) wlan0 Link encap:Ethernet HWaddr 00:0f:60:03:06:94 inet addr:192.168.168.1 Bcast:192.168.168.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@SkyPi:~# iwconfig wlan0 wlan0 IEEE 802.11bgn ESSID:"SkyPi" Mode:Managed Frequency:2.412 GHz Access Point: Not-Associated Tx-Power=20 dBm Retry long limit:7 RTS thr:off Fragment thr:off Encryption key:off Power Management:on