Arduino/WiSield/Java Help?

Discussion about any of the included sketches (i.e. WebServer), or user-generated applications.

Arduino/WiSield/Java Help?

Postby jcbconway » Thu Aug 19, 2010 3:37 pm

Hello, i am new to the wisheild, and i have gotten all the sample sketches to work. i am having trouble finding documentation on how everything works with programing it. i understand that you have to set up a connection, and give it secure/non secure yata yata yata. what im confused about is
Code: Select all
void setup()
{
   WiFi.init();
}

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello World!! I am WiShield</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};

void loop()
{
   WiFi.run();
}
stuff like that. i know theat the Wfi.run(); and wifi.init(); are called from webserver.c and i can get how this simple version works. i do not get how stuff like this
Code: Select all
boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
  returnBuffer[0] = '\0';
  if (test)
  {
    strcat(returnBuffer, "On");
  }
  else
  {
    strcat(returnBuffer, "Off");
  }
}

void printStates()
{
        for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
        {
            boolToString(states[stateCounter], stateBuff);
           
            Serial.print("State of ");
            Serial.print(stateCounter);
            Serial.print(": ");
            Serial.println(stateBuff);
        }
}

void writeStates()
{
        //set led states
        digitalWrite(ledPin1, states[0]);
        digitalWrite(ledPin2, states[1]);
        digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {
 
  Serial.println("Page printing begun");
 
    printStates();
    writeStates();
   
  //check whether we need to change the led state
  if (URL[1] == '?' && URL[2] == 'L' && URL[3] == 'E' && URL[4] == 'D') //url has a leading /
  {
    ledChange = (int)(URL[5] - 48); //get the led to change.
   
    for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
    {
      if (ledChange == stateCounter)
      {
        states[stateCounter] = !states[stateCounter];
            Serial.print("Have changed ");
            Serial.println(ledChange);
      }
    }
   
    //after having change state, return the user to the index page.
    WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
    return true;
  }
 
  if (strcmp(URL, "/") == false) //why is this not true?
   {
      WiServer.print("<html><head><title>Led switch</title></head>");
   
      WiServer.print("<body><center>Please select the led state:<center>\n<center>");
      for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
      {
        numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 - 3 rather than 0 - 2
        numAsCharBuff[1] = '\0'; //strcat expects a string (array of chars) rather than a single character.
                                 //This string is a character plus string terminator.
       
        tmpStrCat[0] = '\0'; //initialise string
        strcat(tmpStrCat, "<a href=?LED"); //start the string
        tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
        tmpStrCat[13] = '\0'; //terminate the string properly for later.
   
        strcat(tmpStrCat, ">Led ");
        strcat(tmpStrCat, numAsCharBuff);
        strcat(tmpStrCat, ": ");
       
        boolToString(states[stateCounter], stateBuff);
        strcat(tmpStrCat, stateBuff);
        strcat(tmpStrCat, "</a> "); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
   
        WiServer.print(tmpStrCat);
      }

        WiServer.print("</html> ");
        return true;
   }
}

void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

  Serial.begin(9600);
  WiServer.init(sendPage);
  states[0] = false;
  states[1] = false;
  states[2] = false;
}

void loop(){
  // Run WiServer
  WiServer.server_task();

  delay(10);
}
works. i cannot find a place to reference anything. and async labs has been little to no help to me at all. also, i am wondering if it is possible, to eliminate the html/reload pags thing and have say, a live feed camera apended to a java program the you can drive the camera around through the program and not have to use a browser. i do beileive that tcp is involved? i would be in great dept if you could point me in the right direction and NOT the god damn async wiki ists completly useless and does not help me. please help, i am begging you.



An example of the begining of what i want to do:
I can simple plug a ping seansor into my arduno and plug it into the computer, then easly program my arduino to call a ping function and then read the value of the seansor, then through some conversion math i can convert that value to inches and serial print it and be able to see the distance the ping is reading on the serial monitor. then add the wisheild to the arduino and hook up the ping, and through some slightly more complex code be able to still see the ping distance over serial monitor, now just completly wirelessly. first off, how do i acomplish that and where do i start?
jcbconway
 
Posts: 1
Joined: Thu Aug 19, 2010 3:34 pm

Re: Arduino/WiSield/Java Help?

Postby GregEigsti » Fri Aug 20, 2010 4:43 am

As far as docs go there is the wiki, the uIP stack docs, the WiShield library code, the WiShield example code, the Arduino site's reference, C programming examples/tutorials, AVR library documentation and finally a wealth of Q&A and sample code on this forum. Its pretty much up to you to research the different references.

and async labs has been little to no help to me at all

What specifically have you asked and how have they failed you? That is odd, all the reports that I have heard claim that they are extremely helpful (and that has been my experience as well).

i am wondering if it is possible, to eliminate the html/reload pags thing and have say, a live feed camera apended to a java program the you can drive the camera around through the program and not have to use a browser. i do beileive that tcp is involved?

Yes it is.

then add the wisheild to the arduino and hook up the ping, and through some slightly more complex code be able to still see the ping distance over serial monitor, now just completly wirelessly. first off, how do i acomplish that and where do i start?

Try reading through the references that I mentioned and read through the example code that best meets your needs; also would not hurt to give the WiShield library code a read through.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to Sketches and Applications

Who is online

Users browsing this forum: No registered users and 1 guest