Go Down

Topic: WiFi Program not starting (Read 482 times) previous topic - next topic

Postholes

I am trying to get a rugged circuits yellowjacket to host a WiServer that will allow me to control a robot through a web interface with a wireless connection. However it is getting stuck and I am not even getting the print lines in the:

boolean sendPage()
function.

I've been playing with this and some example code and I can't quite figure out what is wrong with this. Any help would be appreciated.

I have all of the appropriate libraries that are being referenced, well servo and string are both arduino. With other demo programs I've used using #include <WiServer.h> works fine.

Thanks,
Postholes

Code: [Select]

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

#define WIRELESS_MODE_ADHOC   2

// Variable Declaration ======================================================
#define lasers 8
#define solenoid 12
#define range 9 // Just in case we need to use Analog then use pin A5
#define elevation 10

// pins for motor speed and direction
int speed1 = 5, speed2 = 6, direction1 = 4, direction2 = 7;

// starting speed and rotation offest
int startSpeed = 70, rotate = 30;

// initial speeds of left and right motors
int left = startSpeed, right = startSpeed;

// Elevation Variable
int eleValue;

// Servo Declaration and initialization
Servo eleServo;

// Range finder variables
unsigned int timeNow;
long pwmRange, inch;
boolean firingRange = false;
int fullSteamAhead = 7;

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = { 10,1,1,5};   // IP address of WiShield
unsigned char gateway_ip[] = { 192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[] = { 255,0,0,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = { "PingTheBot"};      // 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_ADHOC;

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

/* boolean states[3]; //holds led states */
boolean states[7]; // holds states for left, forward, right, laser, fire, stop, elevation up, elevation down
int stateCounter; //used as a temporary variable

char tmpStrCat[512];
char numAsCharBuff[2];
char ledChange;

// Range finding function
boolean findRange()
{
boolean goStopValue = false;

pwmRange = pulseIn(range, HIGH);

// 147uS per inch according to datasheet
inch = pwmRange / 147;

if ((inch <= fullSteamAhead) && (millis() - timeNow) > 250)
{ // If sensor reads something at or closer than 7 inches, send all stop
timeNow = millis();
goStopValue = false;
firingRange = false;
return goStopValue;
}
else
{
goStopValue = true;
if (goStopValue && (inch < 60))
{
firingRange = true;
}
return goStopValue;
}

return goStopValue;
}

// Turn left function
void turnLeft()
{
left = rotate;
right = 0;
analogWrite(speed2, right);
analogWrite(speed1, left);
}

// Turn Right function
void turnRight()
{
right = rotate;
left = 0;
analogWrite(speed2, right);
analogWrite(speed1, left);
}

// Forward Function
void forward()
{
if (findRange())
{
left = startSpeed;
right = startSpeed;
analogWrite(speed1, left);
analogWrite(speed2, right);
}
else
{
left = 0;
right = 0;
analogWrite(speed1, left);
analogWrite(speed2, right);
}
}

// laser function
void laser()
{
digitalWrite(lasers, HIGH);
}

// fire weapon function
void fireWeapon()
{
if (firingRange)
{
digitalWrite(solenoid, HIGH);
delay(250);
digitalWrite(solenoid, LOW);
}
}

// stop funtion, instead of just stopping this puts robot in near reset state
void stopRobot()
{
eleValue = 20;
analogWrite(speed1, 0);
analogWrite(speed2, 0);
digitalWrite(lasers, LOW);
eleServo.write(eleValue);
}

// Elevation up function
void elevationUp()
{
int eleValueMax = 80;
if (eleValue < eleValueMax)
{
eleValue = eleValue + 10;
}
else
{
eleValue = 80;
}
eleServo.write(eleValue);
}

// elevation down function
void elevationDown()
{
int eleValueMin = 20;
if (eleValue > eleValueMin)
{
eleValue = eleValue - 10;
}
else
{
eleValue = 20;
}
eleServo.write(eleValue);
}

// reads states and calls proper function. Takes integer ledChange
// sets all states != ledChange to false.
void writeStates(int pinChange)
{
// turn off all states but the one user updated
int i;
for (i = 0; i < 7; i++)
{
if (i != pinChange)
{
states[i] = false;
}
}


//  set States or call functions to run to handle robot control
switch (pinChange)
{
case 0:
turnLeft();
break;
case 1:
forward();
break;
case 2:
turnRight();
break;
case 3:
laser();
break;
case 4:
fireWeapon();
break;
case 5:
stopRobot();
break;
case 6:
elevationUp();
break;
case 7:
elevationDown();
break;
}
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL)
{
// Test print begin =======================================
Serial.println("boolean sendPage Being page printing");
// test print end =======================================

Serial.println("Page printing begun");

//printStates();
writeStates(ledChange);

if (URL[1] == '?' && URL[2] == 'R') // R0 = left, R1 = forward, R2 = right, R3 = laser, R4 = fire, R5 = stop, R6 = elevation up, R7 = elevation down
{
ledChange = (int)(URL[3] - 48);

// Write the states to the board
writeStates(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)
{
WiServer.print("<html><head><title>Predator Bot</title></head>");

WiServer.print("<body><center>Select the control state to change:<center>\n<center>");
// R0 = left, R1 = forward, R2 = right, R3 = laser, R4 = fire, R5 = stop, R6 = elevation up, R7 = elevation down
tmpStrCat[0] = '\0';
strcat(tmpStrCat, "<a href=?R0>Left</a>");
strcat(tmpStrCat, "<a href=?R1>Forward</a>");
strcat(tmpStrCat, "<a href=?R2>Right</a>");
strcat(tmpStrCat, "<a href=?R3>Lasers</a>");
strcat(tmpStrCat, "<a href=?R6>Elevation Up</a>");
strcat(tmpStrCat, "<a href=?R7>Elevation Down</a>");
strcat(tmpStrCat, "<a href=?R4>Fire Weapon</a>");
strcat(tmpStrCat, "<p></p><p><h1><a href=?R5>Stop</a></h1></p>");
WiServer.print(tmpStrCat);

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

void setup()
{
// Set pins to proper values
pinMode(speed1, OUTPUT);
pinMode(speed2, OUTPUT);
pinMode(direction1, OUTPUT);
pinMode(direction2, OUTPUT);
pinMode(lasers, OUTPUT);
pinMode(solenoid, OUTPUT);
pinMode(elevation, OUTPUT);
pinMode(range, INPUT);

// set default elevation for servo
eleValue = 20;

// set up servo for elevation control
eleServo.attach(elevation);
eleServo.write(eleValue);

// set motor direction to forward
digitalWrite(direction1, HIGH);
digitalWrite(direction2, HIGH);

// set speed of both motors
analogWrite(speed1, left);
analogWrite(speed2, right);

// begin serial output
Serial.begin(9600);

// Test printing ===============================================
Serial.println("Setup running, WiServer.Init next command");
// End test printing ===============================================

// WiServer Initialization
WiServer.init(sendPage);

// Test printing =======================================
        Serial.println("WiServer.init(sendPage) happened");
// end test printing =======================================

// Set all states to false during initial setup
int i;

for (i = 0; i < 7; i++)
{
states[i] = false;
}

// Initially set time values
timeNow = millis();
}

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

delay(10);
}

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy