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

EUR 7.00


WIFI-2-IA - WiFi USB module (Int. antenna)

OEM Small USB module

  • 2.4 gHz
  • USB 2.0
  • Power supply @ 3.3 Volt
  • IEEE 802.11 b/g/n Wi-Fi compliant
  • RaLink RT5370N chip
  • Internal PCB antenna. The signal coverage is limited to few meters due to the internal antenna. If you need a greater distance evaluate the model with external antenna (Part # WIFI-2)
  • Configurable as Access Point
  • Male strip soldered
  • Size 28x14mm

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

| Product description || Datasheet |

EUR 7.00


WIFI-2 - WiFi USB module (Ext. antenna)

OEM Small USB module

  • 2.4 gHz
  • USB 2.0
  • Power supply @ 3.3 Volt
  • IEEE 802.11 b/g/n Wi-Fi compliant
  • RaLink RT5370N chip
  • Requires an external antenna (Part# AN-WIFI-01 or AN-WIFI-02)
  • Configurable as Access Point
  • Male strip soldered
  • Size 28x14mm
| Product description || Datasheet |

EUR 2.00


AN-WIFI-01 - WiFi pcb external antenna

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

| Antenna datasheet |

EUR 7.00


AN-WIFI-02 - WiFi external antenna with SMA cable (Version FEMALE/MALE)

Antenna for WIFI-2 module

  • Rubber antenna with FEMALE SMA connector
  • RF cable with panel mountable MALE SMA connector and 2mm UMC connector with about 10 cm length cable

| Antenna datasheet | Cable datasheet |

Bruna Mandolino