Create mini WiFi Webapp server

This article illustrates how to create a WiFi Web application server to distribute local area contents for smartphones

WiFi adapter setup

/etc/network/interfaces

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0 

WiFi Access point with Hostapd

Install hostapd package:

~# apt-get install hostapd

Create a configuration file called hostapd.conf with the following contents:

#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=Arietta
channel=1

Launch Hostapd:

~# hostapd hostapd.conf &

DHCP Server

~# apt-get install isc-dhcp-server

Edit the /etc/default/isc-dhcp-server file and set the port to bind:

INTERFACES="wlan0"

Now configure our DHCP server is to specify subnetworks in its configuration file /etc/dhcp/dhcpd.conf.

Here is the example of the file:

ddns-update-style none;

option domain-name "acme.org";
option domain-name-servers 192.168.2.1;

default-lease-time 600;
max-lease-time 7200;

authoritative;

log-facility local7;

subnet 192.168.2.0 netmask 255.255.255.0 {
    range 192.168.2.50 192.168.2.100;
    option routers 192.168.2.1;
}

When the configuration is done, restart the dhcp server:

~# /etc/init.d/isc-dhcp-server restart

If the server is complaining about something, see the "/var/log/syslog" for more details.

FakeDNS

import socket

class DNSQuery:
  def __init__(self, data):
    self.data=data
    self.dominio=''

    tipo = (ord(data[2]) >> 3) & 15   # Opcode bits
    if tipo == 0:                     # Standard query
      ini=12
      lon=ord(data[ini])
      while lon != 0:
        self.dominio+=data[ini+1:ini+lon+1]+'.'
        ini+=lon+1
        lon=ord(data[ini])

  def respuesta(self, ip):
    packet=''
    if self.dominio:
      packet+=self.data[:2] + "\x81\x80"
      packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00'   # Questions and Answers Counts
      packet+=self.data[12:]                                         # Original Domain Name Question
      packet+='\xc0\x0c'                                             # Pointer to domain name
      packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04'             # Response type, ttl and resource data length -> 4 bytes
      packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
    return packet

if __name__ == '__main__':

  ###################################
  # Insert here the board IP address
  ###################################
  ip='192.168.2.1'

  print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip
  
  udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  udps.bind(('',53))
  
  try:
    while 1:
      data, addr = udps.recvfrom(1024)
      p=DNSQuery(data)
      udps.sendto(p.respuesta(ip), addr)
      print 'Risposta: %s -> %s' % (p.dominio, ip)
  except KeyboardInterrupt:
    print 'Fine'
    udps.close()

Related links

WIFI-2-IA
EUR 7.00


WiFi USB module (Internal Antenna)

OEM Small USB 2.0 IEEE 802.11 b/g/n Wi-Fi compliant module based on the RaLink RT5370N chip. It works at 3.3V and can be configured also in Access Point mode.

This model uses the internal PCB antenna. The operative range of this solution is limited to few meters (2-3 mt). If you need a greater distance evaluate the model with external antenna.

Don't use the WIFI-2-IA model with Arietta G25 board because it hangs the CPU. Use the WIFI-2 instead

| Product description || Datasheet |

WIFI-2
EUR 7.00


WiFi USB module

OEM Small USB 2.0 IEEE 802.11 b/g/n Wi-Fi compliant module based on the RaLink RT5370N chip. It works at 3.3V and can be configured also in Access Point mode.

This model requires an external antenna model AN-WIFI-01 or AN-WIFI-02.

| Product description || Datasheet |

AN-WIFI-01
EUR 3.50


WiFi pcb external antenna

WiFi PCB antenna with 11 cm cable and UMC 2mm connector to be plugged on WIFI-2 module.

| Antenna datasheet |

AN-WIFI-02
EUR 7.00


WiFi external antenna with SMA cable
  • RF cable with panel mountable SMA connector and UMC 2mm connector to be plugged on a WIFI-2 module.
  • WiFi rubber antenna

| Antenna datasheet | Cable datasheet |