Pages: 1 [2] 3   Go Down
Author Topic: HTML Server Web Pin Control  (Read 3264 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are the files on the sdcard seen with different names? When I have a name like indexabc.html arduino loads it as indexh~1.htm and that's how I access it. Why is this happening?
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your SD card is probably formatted with a FAT file system, which cannot handle .html as a normal extension, since normal extensions back when FAT was invented were limited to 3 characters.  Files with more than 8 characters in the filename or three characters in the extension get this special treatment.

I'm guessing the tilde thing isn't happening to files that fit the 8.3 limit. 

You could name your file .htm and see if it helps.

-br
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That did help. Thank you.

Here is my problem. If I open this file on the sdcard of my phone it opens the webpage fine and displays the images perfectly fine. If I have the same exact file on the sdcard of my ethernet shield on the arduino it does not load the images. Why is this happening? Sorry to throw these html problems at you guys.

Here is what the serial monitor is displaying:

Code:
Free RAM: 831
Volume is FAT16

Files found in root:
INDEX.HTM      2012-12-19 18:06:36 1363

Files found in all dirs:
INDEX.HTM

Done
GET /INDEX.HTM HTTP/1.1
INDEX.HTM
Opened!
GET /favicon.ico HTTP/1.1
favicon.ico
« Last Edit: December 19, 2012, 06:36:22 pm by durkinnj » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is the file:// url.  There is a great difference between http:// and file:// urls.  The main issue here is that a file:// url is only valid on the device where the resource named by the url lives.

To fetch a resource like an image across the network, it needs to be on an http:// server and the referring HTML code needs to use the appropriate http:// url to fetch it.

-br
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I don't know if you've read any previous posts but the problem is that this local network is not connected to the internet in anyway (not even the client browser because it is connected to the arduino network only). So while I would love to have the images hosted elsewhere, I can't.

The only other solution I can think of is to have the image files on the client device and have the webserver point the client to look in its own directory for the files. I'm kind of stuck here :/

The only other way to go with this is to actually connect the arduino to the internet. I honestly do not know how to do this as a mobile application. I'll have to use a broadband device either usb or mobile hotspot and somehow connect the arduino to it but how?
« Last Edit: December 19, 2012, 06:46:41 pm by durkinnj » Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The web server does not have to be on the internet.  It can be on the phone, or a PC, on your local network.

-br
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you just work on serving an image. Post the html code of the page your arduino servs up. Does your server code include detecting when the image is requested?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.
« Last Edit: December 20, 2012, 09:04:59 am by durkinnj » Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For testing I suggest you try just sending the image to the browser when the server gets a request and skip all the other stuff. If you click on the below link IE will display the slider1.jpg file without any other html code required. start simple.

http://web.comporium.net/~shb/pix/slider1.jpg
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

zoomkat, I'm also modifying your code for my application. Here is what I've done so far:

Code:
//zoomkat 4-1-12
//simple button GET for servo and pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

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

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 80 }; // ip in lan
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
boolean engine = false;
String readString;

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  //enable serial data print
  Serial.begin(9600);
  Serial.println("server servo/pin 5 test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient 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;
          //Serial.print(c);
        }

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

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          if(engine == false){
          client.println("<a href='/?on'>ON</a>"); }
          else {
          client.println("<a href='/?off'>OFF</a>"); }

          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            myservo.write(40);
            digitalWrite(5, HIGH);    // set pin 5 high
            engine = true;
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            myservo.write(140);
            digitalWrite(5, LOW);    // set pin 5 low
            engine = false;
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

I'm trying to make it give an option of off when it's on and an option of on when it's off. What happens is if you press off it goes off but displays off again. Click it again, nothing happens except it changes back to on and then you can turn it on but then it displays on again until you click it one more time to change it to off again.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay I solved the problem but only on one browser. When I switch to another browser (firefox) and try to turn the pin off, it turns off for half a second and then turns right back on. I have no idea what's going on. Can someone take a look at my code and point me in the right direction?

Code:
//zoomkat 4-1-12
//simple button GET for servo and pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of "
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 80 }; // ip in lan
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
boolean engine = false; //engine status
String readString;

//////////////////////

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip);
  server.begin();

  //enable serial data print
  Serial.begin(9600);
  Serial.println("server pin 5 test 1.0"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient 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;
          //Serial.print(c);
        }

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

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(5, HIGH);    // set pin 5 high
            engine = true;
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(5, LOW);    // set pin 5 low
            engine = false;
            Serial.println("Led Off");
          }
         
                    ///////////////
          Serial.println(readString); //print to serial monitor for debuging

          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          //client.println("<META HTTP-EQUIV='refresh' CONTENT='5'>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          if(engine == false){
          client.println("<a href='/?on'>ON</a>"); }
          else {
          client.println("<a href='/?off'>OFF</a>"); }

          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();
         
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
//open serial monitor to see what the arduino receives
Did you? Are you going to keep us in suspense?
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 84
Posts: 3414
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to point out that indexOf("on") and indexOf("off") look for those particular characters in ANY word, not just the words "on" or "off".

examples:
long > on
onboard > on
one> on
office > off
offend > off

You should use a special character to not get it confused with anything else.
@#$%^&*<>?, one of these should be incorporated with the words on/off and also with the finding of the words. 
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Offline Offline
Full Member
***
Karma: 0
Posts: 125
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah thanks guys. Problem solved.
« Last Edit: December 20, 2012, 09:28:58 am by durkinnj » Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 84
Posts: 3414
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you tell us how you fixed it?

You should post the working code for other people to see.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Pages: 1 [2] 3   Go Up
Jump to: