WIFI Issue

Basic / Standard Reef Angel hardware
Post Reply
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

WIFI Issue

Post by Rey »

I am having trouble detecting my WIFI on Tera Term VI using serial port connection.

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()
{
}

Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: WIFI Issue

Post by rimai »

You are all set with the wifi setup if you are getting the ip address.
Regarding the Tera Term, make sure to use baud 57600.
9600 baud is only for when you get it for the first time or you did factory reset.
Roberto.
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

but the 10.1.10.120 is not my home network IP Subnet. How do I change the IP to what I want? BTW, thank you for the cable I received it today.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: WIFI Issue

Post by rimai »

Oh, so maybe it is reminescent of old settings.
Make sure to change the WLAN_PHRASE and WLAN_SSID to your own wifi, on the code you posted above.
Is your router setup to WPA2-PSK authentication?
Roberto.
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

I changed the WLAN_PHRASE and WLAN_SSID to what my WPA2-PSK is using, but I still get the 10.1.10.120:2000 on the controller screen when I connect the wifi to it.
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: WIFI Issue

Post by rimai »

Try doing factory reset and start from scratch
Roberto.
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

I did a factory reset on the wifi and re-did all the steps. Now the IP is 0.0.0.0:2000
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: WIFI Issue

Post by rimai »

It is not picking up the ip address.
Something is not being setup correctly.
Let's try a different way.
https://github.com/davemolton/Graphical-Wifi-Utility
Download and use the graphical utility that Dave created.
Roberto.
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

Awesome!! That tool works. Thank you.
Image
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

Is it possible to set a Static IP instead of DHCP?
Image
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: WIFI Issue

Post by rimai »

In Tera Term, you can use these commands:

Code: Select all

set ip dhcp 0
set ip address <addr>
set ip netmask <value>
set ip gateway <addr>
Try that and see if that works for you.
Roberto.
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

editing this post:

I re-installed my Tera Term and I am able to connect to my wifi, but I can not type in any commands. All I see is a continuosly

GET /r99 HTTP/1.1
Host: 10.10.10.10:2000
Connection: Keep-Alive
Image
dmolton
Posts: 182
Joined: Tue Mar 22, 2011 11:08 am

Re: WIFI Issue

Post by dmolton »

I was never able to send commands over wifi either. I always had to have the adapter plugged into the computer and connect over serial/usb. The wifi utility you downloaded has an advanced tab that works just like teraterm. Just type a command in the text box and press <return> to send it.. I forget the details now, but I think you start sending commands by typing $$$ and then be sure to type "save" when finished... Just another option..
Rey
Posts: 36
Joined: Wed Sep 07, 2011 7:56 pm

Re: WIFI Issue

Post by Rey »

Both Tera Term and Dave's wifi tool works now. I forgot to type $$$ before i send a command. Thank you all.
Image
Post Reply