Go Down

Topic: wifly outside lan (Read 903 times) previous topic - next topic

LMas

Hi everyone have a big problem to solve,
so i have server(spare laptop runing ubuntu server 10.04) running on my local lan which ip is 192.168.1.9(an no-ip address is lmasss.hopto.org) where i uploaded  tank.html but if i accsess my page using lmasss.hopo.org and try to move forward in responce from tank window i get error that my page 192.168.1.14(wifly all code similar to ethernet shield) is not accsesable.question is somhow to do so it still will send data from lmasss.hopo.org to 192.168.1.14 so i can control tank from outside of my lan?
Html page
Code: [Select]
<html>
<head>
<title>Arduino wi-fi tank</title>

<style>
html,body{font:normal 14px arial,helvetica;}
#content { width:600px;margin:100px auto;}
#response { font-family:Courier;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>

</head>
<body>
<div id="content">
<table>
<tr><td>&nbsp;</td><td><button rel="n">Fwd</button></td><td>&nbsp;</td></tr>
<tr><td><button rel="w">Left</button></td><td>&nbsp;</td><td><button rel="e">Right</button></td></tr>
<tr><td>&nbsp;</td><td><button rel="s">Back</button></td><td>&nbsp;</td></tr>
</table>

<div style="margin-top:20px;border-top:1px solid #ccc;padding-top:10px;">
<h3>Response from tank</h3>
<div id="response">
<iframe id="tank"></iframe>

</div>
</div>
</div>

<script>
$("button").click(function() {
//$("#response").load("http://192.168.1.14/?dir=" + $(this).attr("rel"));
$("#tank").attr("src", "http://192.168.1.14/?dir=" + $(this).attr("rel"));
});
</script>

</body>
</html>


arduino code
Code: [Select]
/*
* Web Server
*
* (Based on Ethernet's WebServer Example)
*
* A simple web server that shows the value of the analog input pins.
*/

#include "WiFly.h"
#include "Credentials.h"
#include <WString.h>

String readString = String(100);

long startTime;

Server server(80);

// set the output pins
int baseMotorEnablePin = 5;
int baseMotorPin1 = 6;                             
int baseMotorPin2 = 7;                           
int shoulderMotorEnablePin = 14;
int shoulderMotorPin1 = 15;                             
int shoulderMotorPin2 = 16;   
///////////////////////////////

void setup() {

  WiFly.begin();
  if (!WiFly.join(ssid, passphrase, WEP_MODE)) {
    while (1) {
      // Hang on failure.
    }
  }
 
    //set the SN754410 pins as outputs:
  pinMode(baseMotorPin1, OUTPUT);
  pinMode(baseMotorPin2, OUTPUT);
  pinMode(baseMotorEnablePin, OUTPUT);
  digitalWrite(baseMotorEnablePin, HIGH);
  pinMode(shoulderMotorPin1, OUTPUT);
  pinMode(shoulderMotorPin2, OUTPUT);
  pinMode(shoulderMotorEnablePin, OUTPUT);
  digitalWrite(shoulderMotorEnablePin, HIGH);
  //++++++++++++++++++++++++++++++++++++++++++++++//

  Serial.begin(9600);

  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  server.begin();
}

void loop() {
if(startTime!=0 && millis()-startTime>1500){
     moveStop();
}


Client client = server.available();
if (client) {
   // an http request ends with a blank line
   boolean current_line_is_blank = true;
   String cmd = ""; 
   int i = 0;
   
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       cmd += c;
       
       if (cmd == "GET /?dir=n")
       {
        //Serial.println("north");
        client.println("moving forward");
        moveForward();
            delay(100);
    client.stop();
       }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        }
        else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }


      }
    }

    delay(100);
    client.stop();
  }
}
void moveForward(){
  startTime=millis();
  digitalWrite(baseMotorPin1, LOW);   
  digitalWrite(baseMotorPin2, HIGH); 
  digitalWrite(shoulderMotorPin1, LOW);   
  digitalWrite(shoulderMotorPin2, HIGH);
 
}

void moveStop(){
  startTime=0;
  digitalWrite(baseMotorPin1, LOW);   
  digitalWrite(baseMotorPin2, LOW);
  digitalWrite(shoulderMotorPin1, LOW);   
  digitalWrite(shoulderMotorPin2, LOW);

}


zoomkat

If you are using a router, you will need to port foward incomming traffic to your arduino server.  You will need to run your arduino on a different port than your pc server, such as port 81. In your html page you would have something like below.

http://lmasss.hopo.org:81?dir=
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

LMas

#2
Mar 05, 2011, 01:28 am Last Edit: Mar 05, 2011, 02:08 am by LMas Reason: 1
thanx zoom for you fast replay so say i use port 8888 for arduino and do port forward , thats easy but what to do with html i totaly new to this :(

edit
just changed port to 8888 and in html file http://lmasss.hopto.org:888?dir= tryed o connect now says cant connect lmasss.hopto.org:8888

edit
restarted router and it worked

Thank you.

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