Go Down

Topic: HTML Server Web Pin Control (Read 4054 times) previous topic - next topic

durkinnj

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?

billroy

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

durkinnj

#17
Dec 20, 2012, 12:23 am Last Edit: Dec 20, 2012, 12:36 am by durkinnj Reason: 1
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: [Select]
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

billroy

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

durkinnj

#19
Dec 20, 2012, 12:35 am Last Edit: Dec 20, 2012, 12:46 am by durkinnj Reason: 1
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?

billroy

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

zoomkat

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?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

durkinnj

#22
Dec 20, 2012, 01:10 am Last Edit: Dec 20, 2012, 03:04 pm by durkinnj Reason: 1
Thanks.

zoomkat

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
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

durkinnj

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

Code: [Select]
//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.

durkinnj

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: [Select]
//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="";

        }
      }
    }
  }
}

PaulS

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

HazardsMind

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. 
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

durkinnj

#28
Dec 20, 2012, 03:08 pm Last Edit: Dec 20, 2012, 03:28 pm by durkinnj Reason: 1
Ah thanks guys. Problem solved.

HazardsMind

Could you tell us how you fixed it?

You should post the working code for other people to see.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up