Go Down

Topic: LinkSprite CuHead Wifi WiShield Robot UDP TCP Control (Read 9124 times) previous topic - next topic

DanK42

Greetings All,

I'm trying to implement WiFi in a teleoperative robot build.  I have the following:

2 Sabertooth 25x2 Motor Controllers (in servo mode, though I would prefer serial but couldn't swing that)
Linksprite CuHead Wifi (WiShield Compatible)
Linear Actuator (relay driven)
Wireless Cams for vision (seperate WiFi from arduino)

I would like to control the robot via a joystick connected to a laptop connected to the robot via wifi.  I'm pretty stumped on employing UDP or TCP and I've had compile issues with the UDP and TCP samples on the async website.  I have succesfully setup the WiServer app and I also have control over the robot using the PSX library and direct wired control to the Arduino, so the robot works and is all connected appropriately. 

This robot needs to be more or less ready to go in the next couple days for a competition and I could really use some assistance.  My C skills are minimal, so a big part of the problem is producing a program on the PC and as I said the example would not compile for me. 

It would be really great if someone with a some robot code using the wishield could perhaps pass on some code I could hack to my needs.

I really try not to bite off more than I can chew with promises of functional code, but indeed the wishield took me by surprise.  Please help...thanks in advance...cheers :-)...

PaulS

Quote
I'm pretty stumped on employing UDP or TCP and I've had compile issues with the UDP and TCP samples on the async website.

Perhaps if you showed some code and some compiler output, we could help you get a sample working. It would be easier to build on that than to try to cut/paste some code for a different wi-fi shield.
The art of getting good answers lies in asking good questions.

DanK42

Sorry about that.  Here is the robot code, I just have on/off control now and will need to shift to analog speed control on the motor controllers.

Code: [Select]


#include <Psx.h>                                          // Includes the Psx Library
#include <Servo.h>

#define dataPin 2
#define cmndPin 3
#define attPin 4
#define clockPin 5

#define LEDPin 13

Servo Drive;
Servo Steer;
Servo Swing;

Psx Psx;                                                  // Initializes the library

unsigned int data = 0;                                    // data stores the controller response

void setup()
{
  Psx.setupPins(dataPin, cmndPin, attPin, clockPin, 10);  // Defines what each pin is used
                                                          // (Data Pin #, Cmnd Pin #, Att Pin #, Clk Pin #, Delay)
                                                          // Delay measures how long the clock remains at each state,
                                                          // measured in microseconds.
                           
                           
  Drive.attach(10);
  Steer.attach(11); 
  Swing.attach(6);

  pinMode(13, OUTPUT);   
  pinMode(12, OUTPUT);
}

void loop()
{
  data = Psx.read();                                      // Psx.read() initiates the PSX controller and returns
                                                          // the button data

   if (data & psxUp)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Drive.writeMicroseconds(1700);  // Forward
  }
  else
  {
  Drive.writeMicroseconds(1500);  // Stop
  }
  if (data & psxDown)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Drive.writeMicroseconds(1300);  // Backward
  }
  else
  {
  Drive.writeMicroseconds(1500);  // Stop
  }
if (data & psxLeft)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Steer.writeMicroseconds(1700);  // Left
  }
  else
  {
  Steer.writeMicroseconds(1500);  // Stop
  }
  if (data & psxRight)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Steer.writeMicroseconds(1300);  // Right
  }
  else
  {
  Steer.writeMicroseconds(1500);  // Stop
  }
if (data & psxTri)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Swing.writeMicroseconds(1200);  // Swing Forward
  }
  else
  {
  Swing.writeMicroseconds(1500);  // Stop
  }
  if (data & psxX)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  Swing.writeMicroseconds(1800);  // Swing Backward
  }
  else
  {
  Swing.writeMicroseconds(1500);  // Stop
  }
if (data & psxR1)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  digitalWrite(13, HIGH);   // Slide Up
  }
  else
  {
  digitalWrite(13, LOW);   // Stop
  }
  if (data & psxR2)                                       // If the data anded with a button's hex value is true,
                                                          // it signifies the button is pressed. Hex values for each
                                                          // button can be found in Psx.h
  {
  digitalWrite(12, HIGH);   // Slide Down
  }
  else
  {
  digitalWrite(12, LOW);   // Stop
  }
}


The CuHead is compatible with WiShield 1.0 according to CuteDigi.

The WiServer code and UDP code were the stock code available here:
http://www.asynclabs.com/wiki/index.php?title=AsyncLabsWiki

The UDP code compiled on the Arduino, but their sample UDP app didn't compile because of a inet/arpa file that I read is not on Windows compilers.

The WiServer app worked fine. 

I will have to get back to you with the specific output of the compiler.  Perhaps there is a UDP monitor program or some universal UDP app I could use?

DanK42

I feel kinda stupid but I really have no idea where to start with utilizing UDP.  Perhaps some could suggest a good alternative to UDP for robot control over WiFi.  My presumption is UDP or TCP are the best choices as a web interface would be too slow to respond. 

Or if some can give me a hand with sending and receiving a UDP packet from a PC. I looked at the example UDPapp for async:

Code: [Select]

/*
* UDP endpoint
*
* A simple UDP endpoint example using the WiShield 1.0
*/

#include <WiShield.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes

unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
WiFi.init();
}

void loop()
{
WiFi.run();
}


This example doesn't seem to have anything other than the WiFi setup, which I have been successful with.  I am able to connect to access point and use WiServer. 

Basically, I've never worked with transmitting data over UDP or TCP.  I've otherwise been successful with other Arduino libraries, but in this case I could really use a little push...if not a big one...thanks in advance...please help :-)...thanks again...

zoomkat

The link below has some simple tinkering to make a router bot. I use web based conrols so I can just use a browser as the GUI instead of having to learn very involved progrmming. Bottom is my simple web cam setup using servos (which are about to wear out) which uses a similar browser interface. The neat thing about web based control is that the bot can be controlled from most anywhere over the net.

http://www.lynxmotion.net/viewtopic.php?f=20&t=6343

http://web.comporium.net/~shb/wc2000-PT-script.htm
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

DanK42

That looks great glad to see that a web server will work!!

Now I'm a bit confused.

Is the html on your pc or on the arduino?

I'm using the wiserver library and starting with the wiserver example.

Code: [Select]
/*
* Web Server
*
* A simple web server example using the WiShield 1.0
*/

#include <WiShield.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes

unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

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


Do I put the html where the webpage info is at the end of this document?  I understand I can loose the ip references from the ethernet shield code and replace with wishield parameters.  Though those in the rest of the code are a bit confusing?  Any thoughts?  Meantime I'll keep hacking...

zoomkat

Quote
Is the html on your pc or on the arduino?


For testing purposes I just put the page html on my pc desktop. In a final setup the page html could be put in the arduino code such that if a request were made without a query_string, the html page would be returned. If the request had a query_string command, the command would be executed and a status 204 returned to the browser instead of the html page. 
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

DanK42

OK I think I'm getting it here.  For some reason I always pop up a new page that goes nowhere, but I am receiving commands in the serial monitor.  However, the arduino seems to crash periodically.  I had some code previously that crashed when I loaded the webpage and now it crashes when I click on a link.  Weird...

Code: [Select]
/*
* A simple sketch that uses WiServer to serve a web page
*/


#include <WiServer.h>
#include <Servo.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,42,7}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,42,254}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ssid"}; // max 32 bytes

unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"blah"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------

//Servo Drive;
Servo Steer;
Servo Swing;


// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
 
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("<HEAD><H3>Oakton Community College Lunabotics H.O.P.E.<BR> Web Control Page</H3><TITLE>HOPE</TITLE></HEAD>");
        WiServer.print("<BODY>");
        WiServer.print("Foward-*Stop*-Reverse<BR>");
        WiServer.print("<a href='http://192.168.42.7:80/F-F' target='inlineframe'>F-F</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-F' target='inlineframe'>S-F</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/X-FR' target='inlineframe'>STOP</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/F-R' target='inlineframe'>F-R</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-R' target='inlineframe'>S-R</a>|");
        WiServer.print("<BR><BR>Turn-L-*Stop*-Turn-R<BR>");
        WiServer.print("<a href='http://192.168.42.7:80/F-L' target='inlineframe'>F-L</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-L' target='inlineframe'>S-L</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/X-LR' target='inlineframe'>STOP</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/F-R' target='inlineframe'>F-R</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-R' target='inlineframe'>S-R</a>|");
        WiServer.print("<BR><BR>Turn-L-*Stop*-Turn-R<BR>");
        WiServer.print("<a href='http://192.168.42.7:80/F-L' target='inlineframe'>F-L</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-L' target='inlineframe'>S-L</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/X-LR' target='inlineframe'>STOP</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/F-R' target='inlineframe'>F-R</a>|");
        WiServer.print("<a href='http://192.168.42.7:80/S-R' target='inlineframe'>S-R</a>|");
         
        WiServer.print("</BODY>");   
        WiServer.print("</html>");
       
        // URL was recognized
        return true;
    }
    if (strcmp(URL, "/") == 0) {
   Serial.println(URL); // Print URL returned
     
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);

   //Drive.attach(10);
  Steer.attach(11); 
  Swing.attach(6);
 
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
  Serial.println("Serial Online"); // so I can keep track of what is loaded

}

void loop(){

  // Run WiServer
  WiServer.server_task();


  delay(10);
}

zoomkat

Your web page html does not include thr IFRAME that receives the data sent from the arduino such that the origional page does refresh. Note the iframe data bit bucket in the below html.

Code: [Select]

<HTML>
<HEAD>
<H3>Zoomkat's Routerbot<BR> Web Control Page</H3>
<TITLE>Zoomkat's Routerbot Control Page</TITLE>
</HEAD>
<BODY>

Foward-*Stop*-Reverse
<BR>

<a href="http://192.168.1.102:84/?-1000-2000" target="inlineframe">F-F</a>|
<a href="http://192.168.1.102:84/?-1450-1550" target="inlineframe">S-F</a>|
<a href="http://192.168.1.102:84/?-1500-1500" target="inlineframe">*-Stop-*</a>|
<a href="http://192.168.1.102:84/?-1550-1450" target="inlineframe">S-R</a>|
<a href="http://192.168.1.102:84/?-2000-1000" target="inlineframe">F-R</a>|
<BR>
<BR>
Turn-L-*Stop*-Turn-R
<BR>
<a href="http://192.168.1.102:84/?-1000-1000" target="inlineframe">F-L</a>|
<a href="http://192.168.1.102:84/?-1450-1450" target="inlineframe">S-L</a>|
<a href="http://192.168.1.102:84/?-1500-1500" target="inlineframe">*-Stop-*</a>|
<a href="http://192.168.1.102:84/?-1550-1550" target="inlineframe">S-R</a>|
<a href="http://192.168.1.102:84/?-2000-2000" target="inlineframe">F-R</a>|
<BR>
<IFRAME name=inlineframe
src="res://D:\WINDOWS\System32\shdoclc.dll/dnserror.htm" width=1
height=1> this will hold the html answer of the moves
</IFRAME>

</body>
</html>
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

DanK42

OK so things are coming along but for some reason, it seems there is some issue in sendmypage that causes things to not work.  Here is the code thus far:

Code: [Select]
/*
* A simple sketch that uses WiServer to serve a web page
*/


#include <WiServer.h>
#include <Servo.h>


#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,43,7}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,43,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Deep Thought"}; // max 32 bytes

unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"improbabilitydrive69"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------

Servo Drive;
Servo Steer;
Servo Swing;


// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("<HEAD><H3>Test<BR> Web Control Page</H3><TITLE>HOPE</TITLE></HEAD>");
        WiServer.print("<BODY>");
       WiServer.print("Foward-*Stop*-Reverse<BR>");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-F\" target=\"inlineframe\">F-F</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-F\" target=\"inlineframe\">S-F</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/X-FR\" target=\"inlineframe\">+-STOP-+</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-R\" target=\"inlineframe\">F-R</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-R\" target=\"inlineframe\">S-R</a>|");
         WiServer.print("<BR><BR>Turn-L-*Stop*-Turn-R<BR>");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-Lt\" target=\"inlineframe\">F-L</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-Lt\" target=\"inlineframe\">S-L</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/X-T\" target=\"inlineframe\">+-STOP-+</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-Rt\" target=\"inlineframe\">F-R</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-Rt\" target=\"inlineframe\">S-R</a>|");
        WiServer.print("<BR><BR>Swing-U-*Stop*-Swing-D<BR>");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-U\" target=\"inlineframe\">F-L</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-U\" target=\"inlineframe\">S-L</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/X-S\" target=\"inlineframe\">STOP</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/F-D\" target=\"inlineframe\">F-R</a>|");
        WiServer.print("<a href=\"http://192.168.43.7:80/S-D\" target=\"inlineframe\">S-R</a>|");
        //This holds the html answer of the moves
        WiServer.print("<IFRAME name=inlineframe src='res://D:\\WINDOWS\\System32\\shdoclc.dll/dnserror.htm' width=1 height=1></IFRAME>"); 
        WiServer.print("</BODY>");   
        WiServer.print("</html>");
        // URL was recognized
        return true;
    }

    //Drive Commands ------------------------------------------
    if (strcmp(URL, "/F-F") == 0) {
        Serial.println("Full Forward"); // so I can keep track of what is loaded
        Drive.writeMicroseconds(2000);  // Full Forward
    }
    if (strcmp(URL, "/S-F") == 0) {
        Serial.println("Slow Forward"); // so I can keep track of what is loaded
        Drive.writeMicroseconds(1700);  // Slow Forward
    }
    if (strcmp(URL, "/X-FR") == 0) {
        Serial.println("Stop Drive"); // so I can keep track of what is loaded
        Drive.writeMicroseconds(1500);  // Stop Drive
    }
    if (strcmp(URL, "/F-R") == 0) {
        Serial.println("Full Reverse"); // so I can keep track of what is loaded
        Drive.writeMicroseconds(1000);  // Full Reverse
    }
    if (strcmp(URL, "/S-R") == 0) {
        Serial.println("Slow Reverse"); // so I can keep track of what is loaded
        Drive.writeMicroseconds(1300);  // Slow Reverse
    }
    //Steer Commands -----------------------------------------
    if (strcmp(URL, "/F-Rt") == 0) {
         Serial.println("Full Right"); // so I can keep track of what is loaded
         Steer.writeMicroseconds(1000);  // Full Right
    }
    if (strcmp(URL, "/S-Rt") == 0) {
         Serial.println("Slow Right"); // so I can keep track of what is loaded
         Steer.writeMicroseconds(1300);  // Slow Right
    }
    if (strcmp(URL, "/X-T") == 0) {
         Serial.println("Stop Steer"); // so I can keep track of what is loaded
         Steer.writeMicroseconds(1500);  // Stop Steer
    }
    if (strcmp(URL, "/F-Lt") == 0) {
         Serial.println("Full Left"); // so I can keep track of what is loaded
         Steer.writeMicroseconds(1700);  // Full Left
    }
    if (strcmp(URL, "/S-Lt") == 0) {
         Serial.println("Slow Left"); // so I can keep track of what is loaded
         Steer.writeMicroseconds(2000);  // Slow Left
    }
    //Swing Commands -----------------------------------------
    if (strcmp(URL, "/F-U") == 0) {
         Serial.println("Full Up Swing"); // so I can keep track of what is loaded
         Swing.writeMicroseconds(1000);  // Full Up Swing
    }
    if (strcmp(URL, "/S-U") == 0) {
         Serial.println("Slow Up Swing"); // so I can keep track of what is loaded
         Swing.writeMicroseconds(1300);  // Slow Up Swing
    }
    if (strcmp(URL, "/X-S") == 0) {
         Serial.println("Stop Swing"); // so I can keep track of what is loaded
         Swing.writeMicroseconds(1500);  // Stop Swing
    }
    if (strcmp(URL, "/F-D") == 0) {
         Serial.println("Slow Down Swing"); // so I can keep track of what is loaded
         Swing.writeMicroseconds(1700);  // Slow Down Swing
    }
    if (strcmp(URL, "/S-D") == 0) {
         Serial.println("Full Down Swing"); // so I can keep track of what is loaded
         Swing.writeMicroseconds(2000);  // Full Up Swing
    }
    // URL not found
    return false;
}
void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  //Serial link for monitoring
  Serial.begin(57600);
  // Ask WiServer to generate log messages (optional)
  WiServer.enableVerboseMode(true);
  Serial.println("Serial Online"); // so I can keep track of what is loaded
  Serial.println("WiServer Online"); // so I can keep track of what is loaded

   //Drive.attach(10);
  Drive.attach(5);
  Steer.attach(6); 
  Swing.attach(9);
 

}

void loop(){

  // Run WiServer
  WiServer.server_task();
 


  delay(10);
}


Any thoughts?  And thanks for all the help so far...

PaulS

Quote
it seems there is some issue in sendmypage that causes things to not work.

Bummer. What are the symptoms?

You have a lot of strings. You may be out of memory.
The art of getting good answers lies in asking good questions.

DanK42

Yeah I agree.  It seems like a memory thing.  If I comment out a good portion of the sendmypage it works fine.  If I comment out about 2/3 of the sendmypage code it works fine. Otherwise, the page just doesn't load, no ping or anything.  Though I do get the red wifi led on the CuHead.  However, it doesn't give any errors when compiling.  And in sections everything seems to work fine.  It definitely seems to be in relation to the sendmypage bit.  Any thoughts will be greatly appreciated.

zoomkat

You may be able to shorten the urls by removing the ip address. I think in some web page sources I've seen something like the bottom url. Possibly once a browser has downloaded a page, it can use a shortened url in the page that comes from the same server.

Code: [Select]
WiServer.print("<a href=\"http://192.168.43.7:80/S-Lt\" target=\"inlineframe\">S-L</a>|");

WiServer.print("<a href=\"/S-Lt\" target=\"inlineframe\">S-L</a>|");
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

DanK42

#13
May 24, 2011, 02:17 am Last Edit: May 24, 2011, 02:43 am by DanK42 Reason: 1
Thanks for all the help zoomcat!! I will try that..

Having read around a bit it definitely seems to be the problem.  Is it too many print statements or too much html all together?  what is the limit?  The compiler doesn't complain so how can i tell what is too much...is too much?  

zoomkat

Just looking at your server code, you should be able to get rid of all the if statements and just send the desired values in the html urls. In my web page I send the desired value strings and the server parses out the strings for each servo, converts the servo strings to a number, and uses that value with the servos. Below is my server test code that accepts values for two servos, but it could easily be three. It also makes testing easy as you can use a desktop web page for testing, then include it in the compiled code when it is ready. In the below example the two end servos would be moving and the center servo would be still.

<a href="http://192.168.1.102:84/?-1000-1500-2000" target="inlineframe">F-F</a>|

Code: [Select]

//zoomkat 10-22-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString, servo1, servo2;

Servo myservo1;  // create servo object to control a servo
Servo myservo2;
//////////////////////

void setup(){

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
myservo1.attach(7);
myservo2.attach(6);
Serial.println("bot21"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
}

//if HTTP request has ended
if (c == '\n') {

///////////////
Serial.println(readString);

//readString looks like "GET /?-1500-1500 HTTP/1.1"

      if (readString.length() >0) {
      Serial.println(readString);
           
      servo1 = readString.substring(7, 11);
      servo2 = readString.substring(12, 16);
     
      Serial.println(servo1);
      Serial.println(servo2);
     
      int n1;
      int n2;
     
      char carray1[6];
      servo1.toCharArray(carray1, sizeof(carray1));
      n1 = atoi(carray1);
     
      char carray2[6];
      servo2.toCharArray(carray2, sizeof(carray2));
      n2 = atoi(carray2);
     
      myservo1.writeMicroseconds(n1);
      myservo2.writeMicroseconds(n2);
     
      //myservo.write(n);
      readString="";
      }
  ///////////////////
 
  //now output HTML data header
  client.println("HTTP/1.1 204 Zoomkat");
  client.println();
  client.println();
  delay(1);
  //stopping client
client.stop();

/////////////////////
//clearing string for next read
readString="";
 
}}}}}
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up