Passing of URL Parameters in Meta Tag

I am attempting to read the status of a pin and redirect the web page back to an ASP.Net webpage with the status as a parameter in the url string. I have ran into real issues trying to append the pin status value to the meta tag as shown below. If I remove the " + String(webval) + " the url string passes fine. If i add it back in, the page is never redirected.

Does anyone know how to append this value to the URL String? Any help would be greatly appreciated, thanks in advance.

#define DoorSwitch 3
Int webval=0;
webval=digitalRead(DoorSwitch);

WiServer.print("");
WiServer.print("");
WiServer.print("");
WiServer.print("");
WiServer.print("Test");
WiServer.print("");

The WiServer class derives from Print, doesn't it? That means that WiServer.print() knows how to print an int. Wrapping that int in a String instance is a waste of memory.

Split that statement into three separate statements.

Shouldn't there should be a \ in front of the ' before the REFRESH keyword?

It isn't clear why you are trying to embed the content inside the META tag. That usually isn't done.

Do you have a test page on the PC that tests the ASP,Net web page? What does that test page look like?

Try with these changes:

#define DoorSwitch 3

char webval = '0' + digitalRead(DoorSwitch);

WiServer.print("<html>");
WiServer.print("<head>");
WiServer.print("<meta HTTP-EQUIV='REFRESH\' content='0; url=http://192.168.2.158/iistest/default.aspx?DoorSwitch=");
WiServer.print(webval);
WiServer.print("></head>");
WiServer.print("Test");
WiServer.print("</html>");

WiServer.print("");
WiServer.print("");
WiServer.print("<meta HTTP-EQUIV='REFRESH' content='0; url=http://192.168.2.158/iistest/default.aspx?DoorSwitch=");
WiServer.print(webval);
WiServer.print(">");
WiServer.print("Test");
WiServer.print("");

Thanks for the quick response. If i simply add the WiServer.print(webval); below the meta tag, it simply prints a 1 before the word test in the body of the page ad appears as "1 Test" on the page and does not get included in the URL string being passed back to the ASP.Net web page.

To clarify what I am trying to do here, I am simply hitting the wiserver from a browser. In return, the wiserver will poll the uno and redirect the web page back to an ASP.NET page that will process the URL string and populate the status on the web page. i.e. url=http://192.168.2.158/iistest/default.aspx?DoorSwitch=1.

In theory, I should be able to check the status of my door from any web page by hitting the IP of the web server, and get redirected to my ASP.Net web page with the status in the url string.

In theory, I should be able to check the status of my door from any web page by hitting the IP of the web server, and get redirected to my ASP.Net web page with the status in the url string.

Sure. And what does the web page on the PC look like that you used to test the theory? The Arduino should serve up the same page.

PaulS:

In theory, I should be able to check the status of my door from any web page by hitting the IP of the web server, and get redirected to my ASP.Net web page with the status in the url string.

Sure. And what does the web page on the PC look like that you used to test the theory? The Arduino should serve up the same page.

What does it matter what the ASP.Net page looks like . All the Arduino needs to do is append the pin status to the url string and redirect the page, then its job is done. I already have it doing everything but appending the pin status value.

Sorry if the above post sounded harsh, it wasnt meant to be.

The ASP.Net page will handle the request on its page load by setting a string variable and assigning its value using the Request(DoorSwitch).

At the present moment, the page is pretty much blank, until I get the url string correct. Once the URL string is correct, I will add a textbox to be populated on page load, with the string as described above.

I suggest you test the url with a hard coded value and see if that works. If that works then test with a hard coded variable in the arduino code and see if that works being intergrated into the url. If that works then go back to testing your origional code. Do you print out to the serial monitor each step of developing the variable to send?

Hmm - from the "KISS" department:

char buf[] = "<meta HTTP-EQUIV='REFRESH' content=0; url=http://192.168.2.158/iistest/default.aspx?DoorSwitch=0>";

buf[95] = '0' + digitalRead(DoorSwitch);
WiServer.print("<html>");
WiServer.print("<head>");
WiServer.print(buf);
WiServer.print("</head>");
WiServer.print("Test");
WiServer.print("</html>");

Thanks for that, I had tried that earlier, but obviously didnt have something quite right. Can you explain why the 0 needs to be in the original declaration after the DoorSwitch =, and what the buf[95] = '0' + digitalRead(DoorSwitch); does?

It appears to work if you get the position right in the buf[95] statement. I now have an issue with the wiserver , when the page is accessed after the initial time, doesnt want to load for some reason.

Thanks again for your help.

What does it matter what the ASP.Net page looks like . All the Arduino needs to do is append the pin status to the url string and redirect the page, then its job is done. I already have it doing everything but appending the pin status value.

My point was that the problem is not Arduino specific. If you were to create a html file on your PC, with that exact same code in it, it should fail in the same way.

If it does, then pay with the file on the PC until you get something that works. Then, make the Arduino do the same thing.

If it doesn't, then the problem is with the Arduino, but I don't think that you will find that that is the case.

Can you explain why the 0 needs to be in the original declaration after the DoorSwitch =, and what the buf[95] = '0' + digitalRead(DoorSwitch); does?

Yuppers: The zero in the declaration is just a place-holder - and is replaced by either a zero or a one when the "buf[95] = " assignment is made.

digitalRead() returns an either zero or one numeric value which, when added to the character '0', converts the numeric value to its character equivalent.

Essentially, what the snippet does is read the switch right into the pre-formatted character array.

PaulS:

What does it matter what the ASP.Net page looks like . All the Arduino needs to do is append the pin status to the url string and redirect the page, then its job is done. I already have it doing everything but appending the pin status value.

My point was that the problem is not Arduino specific. If you were to create a html file on your PC, with that exact same code in it, it should fail in the same way.

If it does, then pay with the file on the PC until you get something that works. Then, make the Arduino do the same thing.

If it doesn't, then the problem is with the Arduino, but I don't think that you will find that that is the case.

Thanks for your help, I apologize if it came across harsh, it certainly wanst meant that way. To bad you cant hear tone of voice on a forum. :slight_smile:

The code below works great. I can now hit the IP of the wiserver from any web browser, and it will return the values (pin status) to my ASP.Net page. I can then use the Request(DoorSwitch) to read the value into the page load, and pass it to the form on the ASP.Net page.

This is by far the simplest method I have seen for returning values to a page that does not reside In memory on the wishield.

webval=digitalRead(DoorSwitch);
char buf[] = "";
buf[96]= '0' + digitalRead(DoorSwitch);

The Idea here is to use the incoming parameters to determine whether the user is requesting door status, or to toggle the current door status.

if (URL[1] == '?' && URL[2] == 'C' && URL[3] == 'L' && URL[4] == 'O' && URL[5] == 'S' && URL[6] == 'E')
{
// check to see what the current status of the door is, if close then return Status=Already Closed, else set relay status to high for .5 seconds, then set relay back to low

digitalWrite(RelayCircuit, 1);
delay(1000);
digitalWrite(RelayCircuit, 0);
WiServer.Print .....
}
if (URL[1] == '?' && URL[2] == 'O' && URL[3] == 'P' && URL[4] == 'E' && URL[5] == 'N' )
{
// check to see what the current status of the door is Open, if closed then return Status=Already Open, else set relay status to high for .5 seconds, then set relay back to low

digitalWrite(RelayCircuit, 1);
delay(1000);
digitalWrite(RelayCircuit, 0);
WiServer.Print ......
}

else
{
//Return Status if no parameters are passed to the shield
WiServer.print("");
WiServer.print("");
WiServer.print(buf);
WiServer.print("");
WiServer.print("test");
WiServer.print("");
return true;

}

webval=digitalRead(DoorSwitch);
   char buf[] = "<meta HTTP-EQUIV='REFRESH' content='5; url=http://192.168.2.158/iistest/default.aspx?DoorSwitch=0'>";
   buf[96]= '0' + digitalRead(DoorSwitch);

So, what is webval for?

So, what is webval for?

Ballast!

PaulS:

webval=digitalRead(DoorSwitch);

char buf[] = "";
   buf[96]= '0' + digitalRead(DoorSwitch);



So, what is webval for?

webval is just a variable for storing the pin status of the door. I guess it just did not get used.

buf[96]= '0' + digitalRead(DoorSwitch);
could also be written as
buf[96]= '0' + webval

else set relay status to high for .5 seconds,

delay there is 1 second

PaulS:
So, what is webval for?

Engineering margin, installed spare, easter egg to see if anybody is paying attention...

NI$HANT:

else set relay status to high for .5 seconds,

delay there is 1 second

Yes it is, I cut that from some old code I just hadn't updated.