Sparcade: Edison as a Web Server for Browser Games
Configure the Edison
We need to configure the Edison to act as an access point before we can program it with the server and game.
Install XDK
Follow these instructions to install the Intel® XDK.
Flash the Latest Firmware
Follow the Edison firmware flashing guide to update to the latest firmware.
Connect to the Edison
Plug a USB cable into the OTG port of the Edison. Follow these instructions to set up USB networking on your host computer.
Use an SSH program (e.g., PuTTY) or the built-in SSH terminal of the XDK to connect to the Edison. Note that the default IP address of the Edison on the USB network is 192.168.2.15.
Configure WiFi
Once logged into the Edison over SSH (username: root, no password), run the command:
configure_edison --setup
Follow the onscreen instructions to set a password (highly recommended!), change the Edison's name (e.g., "sparcade"), and connect to the internet via WiFi.
Configure Hostapd
Hostapd is a Linux utility capable of turning WiFi network cards into access points. Luckily, the Edison has Hostapd installed by default. All we have to do is configure it. Back up the original hostapd.conf file, and modify a new one:
mv /etc/hostapd/hostapd.conf.bak
vi /etc/hostapd/hostapd.conf
In the vi text editor, press 'i' to edit text and insert the following (you can copy the text and press 'shift' + 'insert' together to paste into vi):
interface=wlan0
ssid=sparcade
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
Save and exit by pressing 'esc', type :wq
, and press 'enter'.
Configure Hosts
The hosts file lets us map names to IP addresses without having to rely on a DNS server. We want to associate the name "sparcade" and "sparcade.local" with our own IP address, which is 192.168.42.1 by default.
Backup the original hosts file and edit a new one:
mv /etc/hosts /etc/hosts.bak
vi /etc/hosts
Add the following:
127.0.0.1 localhost.localdomain localhost sparcade.local sparcade
192.168.42.1 sparcade.local sparcade
Save and exit.
Configure DHCP
The Edison uses udhcp as a lightweight DHCP server for access point (AP) mode. This service hands out IP addresses to clients that connect to its AP. We'll want to configure the udhcp daemon so that sparcade.local is associated with the AP's IP address (192.168.42.1). It's a bit of a cheat, since we aren't running a full DNS server to associate website names with IP addresses.
Edit the configuration file:
vi /etc/hostapd/udhcpd-for-hostapd.conf
Scroll down to the bottom of the file, and add the following:
opt subnet 255.255.255.0
opt hostname sparcade
opt domain local
opt dns 192.168.42.1
Save and exit.
Install Dnsmasq
We will also use another tool, dnsmasq, to help associate the server name ("sparcade.local") with the Edison's WiFi IP Address (192.168.42.1). Install it with the following commands:
wget http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.45.tar.gz
tar xvf dnsmasq-2.45.tar.gz
cd dnsmasq-2.45
make install
Configure dnsmasq with:
vi /etc/dnsmasq.conf
Enter the following:
no-resolv
interface=wlan0
Save and exit.
Set Dnsmasq to Run on Boot
Because we manually compiled and installed dnsmasq, there is nothing that tells it to run whenever the Edison boots. To do that, we need to create a systemd service.
vi /lib/systemd/system/dnsmasq.service
Copy in the following:
[Unit]
Description=DHCP and DNS caching server.
After=network.target
[Service]
ExecStart=/usr/local/sbin/dnsmasq -k --conf-file=/etc/dnsmasq.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Save and exit. To register the service (so it runs on boot), enter the commands:
systemctl daemon-reload
systemctl enable dnsmasq.service
Disable Default Server
Finally, we want to disable the web server that the Edison runs whenever it enters into AP mode. To do that, run:
systemctl disable edison_config.service
And now we can restart the Edison:
reboot
Set Edison as Access Point
Once the Edison has finished booting back up, turn on AP mode. Do that by holding the PWR button (on the side of the Base Block) for two to seven seconds (I recommend counting to 4).