Also when I follow the instruction from Wifi Attachment Manual v1.3 to load the code below to my Controller. I get 10.1.10.120 IP when I connect the wifi to my controller.
Code: Select all
#include <Wire.h>
#include <EEPROM.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <NokiaLCD.h>
#include <ReefAngel.h>
/*********************************************************************************************************************************************************************************/
/*
If your network uses WEP authentication, please change the following defines:
WLAN_AUTH MODE
WLAN_WEP_KEY
WLAN_WEP_NUM
WLAN_SSID
If your network uses WPA1 or WPA2 authentication, please change the following defines:
WLAN_AUTH MODE
WLAN_WLAN_PHRASE
WLAN_SSID
*/
/*********************************************************************************************************************************************************************************/
/*
WLAN_AUTH MODE
Wireless Authentication Mode
0 Open (Default)
1 WEP-128
2 WPA1
3 Mixed WPA1 & WPA2-PSK
4 WPA2-PSK
5 Not Used
6 Adhoc, Join any Adhoc network
*/
#define WLAN_AUTH_MODE 4 //WPA2-PSK authentication mode
/*
WLAN_WEP_KEY
Wireless WEP Key for WEP-128 authentication mode
*/
#define WLAN_WEP_KEY "112233445566778899AABBCCDD" //WEP-128 key - change if using WEP-128 authentication mode
/*
WLAN_WEP_NUM
Wireless WEP Key to be used for WEP-128 authentication mode
*/
#define WLAN_WEP_NUM 1 //WEP-128 key to be used - change if using WEP-128 authentication mode
/*
WLAN_PHRASE
Wireless Passphrase for WPA1 or WPA2 authentication mode
*/
#define WLAN_PHRASE "testing" //WPA1 or WPA2 pass phrase - change if using WPA1 or WPA2 authentication mode
/*
WLAN_SSID
Wireless SSID to associate with
*/
#define WLAN_SSID "testing" //change to your SSID
/*********************************************************************************************************************************************************************************/
void setup()
{
int waitbutton=false;
int status=false;
char conn[5];
int connindex=0;
char ip[17];
int ipindex=0;
unsigned long lastmillis;
ReefAngel.Init(); // Initialize
ReefAngel.LCD.Clear(255,0,0,131,131); // Clear screen
ReefAngel.LCD.DrawText(0xE0, 255, 40, 5,"Wifi Setup"); // Draw text
ReefAngel.LCD.DrawText(0xE0, 255, 25, 45,"Press Joystick"); // Draw text
ReefAngel.LCD.DrawText(0xE0, 255, 32, 65,"to continue"); // Draw text
ReefAngel.LCD.Clear(0,0,15,131,15); // Clear screen
do
{
if (ReefAngel.Joystick.IsButtonPressed()) waitbutton=true;
}
while (!waitbutton);
ReefAngel.LCD.Clear(255,0,16,131,131); // Clear screen
delay(1000);
Serial.end();
delay(100);
Serial.begin(9600);
delay(100);
Serial.println("exit"); // exit setup mode
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
delay(100); // wait .1 sec
Serial.print("$$$"); // enter setup mode
delay(300); // wait .3 sec
Serial.println("set u b 57600"); // set baud 57600
delay(100); // wait .1 sec
Serial.println("save");
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
// Serial.print("join ");
// Serial.println(WLAN_SSID);
// delay(750); // wait 1 sec
// Serial.flush(); // Flush incoming serial
Serial.println("reboot");
delay(500); // wait .5 sec
Serial.flush(); // Flush incoming serial
Serial.end();
delay(100);
Serial.begin(57600);
delay(100);
setupwifistart:
Serial.println("exit"); // exit setup mode
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
delay(100); // wait .1 sec
Serial.print("$$$"); // enter setup mode
delay(300); // wait .3 sec
Serial.println("show c"); // request connection status
delay(100); // wait .1 sec
lastmillis=millis();
do // flush serial until get 8, which is always constant on the connection status value.
{
if (Serial.available()>0) conn[0] = Serial.read();
if (conn[0] == '8')
{
connindex++;
status=true;
}
if (millis()-lastmillis>2000) goto setupwifistart;
}
while (!status);
status=false;
lastmillis=millis();
do // Acquire 4 bytes of data representing the connection status
{
if (Serial.available()>0) conn[connindex++] = Serial.read();
if (connindex > 3)
{
conn[4]=0;
Serial.flush(); // Flush incoming serial
ReefAngel.LCD.DrawText(0, 255, 10, 25,"Status:"); // Draw text
ReefAngel.LCD.DrawText(0, 255, 90, 25,conn); // Draw text
status=true;
}
if (millis()-lastmillis>2000) goto setupwifistart;
}
while (!status);
if (conn[2]=='3') // check if wifi attachment is already setup
{
ReefAngel.LCD.DrawText(0, 255, 10, 35,"Already Setup"); // Draw text
ReefAngel.LCD.DrawText(0, 255, 10, 45,"Exiting..."); // Draw text
Serial.println("exit"); // exit setup mode
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
}
else
{
if (WLAN_AUTH_MODE==1)
{
//ReefAngel.LCD.DrawText(0, 255, 10, 35,"set wlan key "); // Draw text
//ReefAngel.LCD.DrawText(0, 255, 90, 35,WLAN_WEP_KEY); // Draw text
Serial.print("set w k "); // set wlan wep key
Serial.println(WLAN_WEP_KEY);
delay(1000); // wait 1 sec
Serial.flush(); // Flush incoming serial
//ReefAngel.LCD.DrawText(0, 255, 10, 45,"set wlan num "); // Draw text
//ReefAngel.LCD.DrawText(0, 255, 90, 45,WLAN_WEP_NUM); // Draw text
Serial.print("set w n "); // set wlan wep key number
Serial.println(WLAN_WEP_NUM);
delay(1000); // wait 1 sec
Serial.flush(); // Flush incoming serial
}
if (WLAN_AUTH_MODE==2 || WLAN_AUTH_MODE==3 || WLAN_AUTH_MODE==4)
{
//ReefAngel.LCD.DrawText(0, 255, 10, 35,"set wlan phrase "); // Draw text
//ReefAngel.LCD.DrawText(0, 255, 10, 45,WLAN_PHRASE); // Draw text
Serial.print("set w p "); // set wlan passphrase for WAP1/WAP2
Serial.println(WLAN_PHRASE);
delay(1000); // wait 1 sec
Serial.flush(); // Flush incoming serial
}
//ReefAngel.LCD.DrawText(0, 255, 10, 55,"set wlan ssid "); // Draw text
//ReefAngel.LCD.DrawText(0, 255, 10, 65,WLAN_SSID); // Draw text
Serial.print("set w s "); // set wlan ssid
Serial.println(WLAN_SSID);
delay(1000); // wait 1 sec
Serial.flush(); // Flush incoming serial
//ReefAngel.LCD.DrawText(0, 255, 10, 75,"set ip localport 80"); // Draw text
Serial.println("set i l 2000"); // set ip port
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
//ReefAngel.LCD.DrawText(0, 255, 10, 85,"set comm close 0"); // Draw text
Serial.println("set c c 0"); // set comm close to nothing
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
//ReefAngel.LCD.DrawText(0, 255, 10, 95,"set comm open 0"); // Draw text
Serial.println("set c o 0"); // set comm open to nothing
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
//ReefAngel.LCD.DrawText(0, 255, 10, 105,"set comm remote 0"); // Draw text
Serial.println("set c r 0"); // set comm remote to nothing
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
Serial.println("set c i 3"); // set comm idle to 3
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
Serial.println("set c s 2048"); // set comm IP packet size to 2048
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
Serial.println("set s p 0"); // set system printlvl 0
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
// ReefAngel.LCD.DrawText(0, 255, 10, 75,"set wlan channel 0"); // Draw text
// Serial.println("set wlan channel 0"); // set scan channel
// delay(750); // wait 1 sec
// Serial.flush(); // Flush incoming serial
// ReefAngel.LCD.DrawText(0, 255, 10, 85,"set wlan join 1"); // Draw text
// Serial.println("set wlan join 1");
// delay(750); // wait 1 sec
// Serial.flush(); // Flush incoming serial
// ReefAngel.LCD.DrawText(0, 255, 10, 95,"set wlan auth "); // Draw text
// //ReefAngel.LCD.DrawText(0, 255, 60, 95, WLAN_AUTH_MODE); // Draw text
// Serial.print("set wlan auth ");
// Serial.println(WLAN_AUTH_MODE);
// delay(750); // wait 1 sec
// Serial.flush(); // Flush incoming serial
Serial.println("save");
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
// Serial.print("join ");
// Serial.println(WLAN_SSID);
// delay(750); // wait 1 sec
// Serial.flush(); // Flush incoming serial
Serial.println("reboot");
delay(500); // wait .5 sec
Serial.flush(); // Flush incoming serial
}
getipstart:
Serial.println("exit"); // exit setup mode
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
delay(100); // wait .1 sec
Serial.print("$$$"); // enter setup mode
delay(300); // wait .3 sec
Serial.println("get ip"); // request connection status
delay(100); // wait .1 sec
for (int a=0; a<2; a++)
{
status=false;
lastmillis=millis();
do // flush serial until get 8, which is always constant on the connection status value.
{
if (Serial.available()>0) conn[0] = Serial.read();
if (conn[0] == 'I')
{
connindex++;
status=true;
}
if (millis()-lastmillis>2000) goto getipstart;
}
while (!status);
}
for (int a=0; a<2; a++) if (Serial.available()>0) conn[0] = Serial.read();
status=false;
do // Acquire 4 bytes of data representing the connection status
{
if (Serial.available()>0) ip[ipindex++] = Serial.read();
if (ip[ipindex - 1] == '\r')
{
ip[--ipindex]=0;
Serial.flush(); // Flush incoming serial
ReefAngel.LCD.DrawText(0, 255, 10, 115,ip); // Draw text
status=true;
}
if (ipindex > 16) ipindex=16;
if (millis()-lastmillis>2000) goto getipstart;
}
while (!status);
Serial.println("exit"); // exit setup mode
delay(100); // wait .1 sec
Serial.flush(); // Flush incoming serial
endline:
delay(100);
}
void loop()
{
}