Connecting the NXT2WiFi Webserver to a WLAN
The simplest way to connect to the NXT2WiFi Mini-Webserver Module is via an Ad-hoc Network, also called WiFi Direct network where devices communicate only peer to peer (P2P). There is no base and no one gives permission to talk. But this method is limited to the fact you can only have access through a single browser enabled device to the NXT2WiFi at a time. To get around this limitation access to the NXT2WiFi Miniature Web Server Module via you Wireless Router/Modem is the answer.
A wireless local area network (WLAN) links two or more devices using some wireless distribution method (typically Wi-Fi), and usually providing a connection through an access point to the wider Internet. This gives users the mobility to move around within a local coverage area and still be connected to the network. To set-up WLAN access for your NXT2WiFi Miniature Web Server Module you will need a Wi-Fi Router or Wi-Fi Modem/Router.
In this tutorial I will go through the steps needed to set-up a WPA2 Security Protocol, also known as IEEE 802.11i-2004, and is the successor of WPA protocol, adds support for CCMP which is intended to replace TKIP encryption protocol. Mandatory for Wi-Fi–certified devices since 2006. We will set-up a WPA-Personal, also referred to as WPA-PSK (Pre-shared key) mode, it is designed for home and small office networks and doesn't require an authentication server. Each wireless network device authenticates with the access point using the same 256-bit key generated from a password or pass-phrase.
- Baud rate: 115200 baud
- Data bits: 8 data bit
- Stop bits: 1 stop bit
- Parity: none
- Flow Control: none
- Transmitted text: Append LF
In order to see the debug stream from the NXT2WIFI Sensor, issue the command $DBG1. Now every command you send from the computer or from the NXT will be shown in the terminal log as well. I personally found the Debug Stream vital during configuration of the NXT2WIFI Sensor.
We will begin by setting a a 'Custom Connection Profile' manually using the Serial Terminal. I found this method the quickest and most reliable method to set-up 'Custom Profiles'. Start by entering the following commands into the Terminal Program, one line at a time:
$WFKD – delete custom profile
$WFKE – check if CUSTOM profile exists, returns 1 if valid data exists, 0 if does not exist, If WFKE=1 is returned, reissue the
$WFKD command and check again.
$WFE?IPAD=192.168.0.100 – IP address of the NXT2WiFi
$WFE?DNS1=192.168.0.1 – NXT2WiFi Primary DNS server address
$WFE?DNS2=192.168.0.2 – NXT2WiFi Secondary DNS server address
$WFE?GWAY=192.168.0.1 – NXT2WiFi Secondary Gateway address
$WFE?NAME=NXT2WIFI – Netbios name or name you wish to call the NXT2WiFi Webserer
$WFE?SSID='Your_Network_Name' – Service Set Identification Name
$WFE?DHCP=1 – Dynamic Host Configuration Protocol (DHCP) Enabled: Automatic IP Addressing
'Your_Network_Password':'No. Characters in Password' – e.g.
$WFKS – save custom profile to permanent memory
Now we have created the new 'Custom Connection Profile', we need to see if it works. Issue the command
$WFC1 in the Serial Terminal which will load the 'Custom Connection Profile' and attempt to connect to you Wi-Fi Network. The first time you run the command, it will take a minute or so, while the Security is set-up. If all went to plan, you should see a similar Serial Terminal window as below.
The Next part of the Tutorial goes through setting up a RobotC and NXC code to connect to the 'Custom Connection Profile', from within you programs.
Save the 'WiFiConnect.h' code to RobotC's 'Includes' folder, so it is always available to the RobotC Compiler. When you wish to use the 'WiFiConnect.h'in a program, simply add:
#include "WiFiConnect.h" to the header section.
Save the 'WiFiConnect.nxc' code to 'C:\Program Files (x86)\LEGO Mindstorms\BricxCC\includes' so it is always available to the NXC Compiler. When you wish to use the 'WiFiConnect.nxc' in a program, simply add:
#include "WiFiConnect.nxc" to the header section.
Download the WiFiConnect Files: WiFiConnect.zip