XML questions
Shawna
Posts: 508
Well, I am not sure really to start on this one!
What I am trying to do, is get a variable from my prop to show up on a webpage when I click a button on the page...........................................
To be continued, I just had another thought.
What I am trying to do, is get a variable from my prop to show up on a webpage when I click a button on the page...........................................
To be continued, I just had another thought.
Comments
I have enabled this little piece of code to see if my get request is making it to the server. The get request is making it to the server.
I have modified the RenderDynamic function to look like this.
The "Render D Yes" is showing up in the PST window when I click the button on the webpage.
So, I am not sure where to go next.
Does the data sent out to the web browser from the prop have to be a string or can it be a raw value?
Here is my Html code also.
Here is my zipped project, any advice would be appreciated.
w5200 xml get function.zip
Thanks
Shawn
When I execute the program I get an A on my webpage which is correct.
If I try to modify the 65 I get garbage. Here is my filtering code.
PropVariable is initialized to 1001 when the prop boots.
I am not sure what I am doing wrong when I try and change the value in the dat section. I am pretty sure that the string for 1001 is blasting my dat section, but I do not know how to change that value any other way.
Also, and I know I already asked this question, but can data be sent to the web page from the prop that is in an unsigned integer format, or does it have to be in a string format.
Thanks
Shawn
Send strings do not send unsigned integers. XML and the HTTP protocol and are text based. Sending a literal number containing a zero will cause the XML parser (Client Browser) to blow up with an unexpected end of string error. There is also the risk of sending a value equal to one of the XML reserved characters like <>.
Take a look at the "xmlPinState" DAT section. This XML document reports encoded pin values, state (on/off), and the DIR register for pins [23..16] . It takes two ASCII bytes in the DAT section to represent a byte, $00. That means the XML nodes are fixed width and the nodes always expect a two byte value. Lets say we have a DIR value of 1. The <dir> node will contain <dir>01</dir> where 01 is a string.
For an unsigned integer, first figure out the bounds of the number. If 1001 is the largest possible value then 4 byte are required to store the string representing of "1001". If the number contains a decimal, off the top of my head, there are two approaches. Set up a fixed width node in the DAT section that contains the DOT where ya want it. Then byte fill the memory locations for the integer and fraction part of the number. Otherwise, send the integer and let the client JavaScript divide by 10^x. I'd follow the later approach as it moves processing to the client and it's much easier. The down side, this approach creates a dependency between the client and server. The client must know to divide 10^x
My original thought was to send an integer and let the JavaScript to the math on the client side. One reason I wanted to do this is that I thought it would save code space on the web server. Actually I thought I could do this using the xml format, but then I realized that the built xml file was all filled with strings.
Would I still use a get call from the webpage to request an integer?
I am not sure where to start looking to implement this approach.
Is there an example of sending an integer from the server to the client?
Thanks
Shawn
No, HTTP and XML are text based. While it is physically possible to send an integer on byte at a time, it will surly cause unexpected client side results.
Grab the latest files from the repo and take a look at WebServer_W5200. It contains the example mentioned in post #5.
You should not send an integer to the client!!! Use the Dec method, lifted from PST, to convert an integer to a string. Then byte move to the string to your XML document and send.
The BuildAndSendHeader method and converts the Content-Length header value from a int to a string. See latest code base.
https://code.google.com/p/propeller-w5200-driver/source/browse/trunk/#trunk%2F propeller-w5200-driver%3Fstate%3Dclosed
You guys have put so much code out there it is ridiculous . Thanks for all the effort.
Am I even shooting for the right code, I am trying to use the Webserver_W5200_RTC code?
All I want to try and do for now is serve up some html pages and dynamically display some variables from the prop.
Although I haven't got to my goal I am learning a lot, I did not and still do not know how to use dat sections effectively or how to deal with strings effectively but I am learning.
Thanks Again
Shawn
I am confused Mike. I downloaded all of the source code from the link in post #9. From looking at it, it looks like the same code that is in the zip code on the Parallax product page.
I understand this, actually I kind of came to this conclusion before you said this.
Then you said this, or maybe I am taking it out of context.
Ok, so I like the sound of this approach. But I am not sure how to implement it. I do not see an example of this in the Server W5200 RTC object. It looks like to me all of the examples in the Server W5200 RTC object end up writing strings to the DAT section and then it is sent to the socket as text (strings). It is quite possible that I am missing something but I do not see anything that sends out an integer.
So then you said this in post #8.
I thought that you said that you would send an integer and then let the client run the javascript on it to do a divide by 10. I understand that you cannot do this with xml.
I guess maybe I switched gears on you mid stream. I would really like to send unsigned integers to the webpage not using xml and let javascript do math on them. I thought I could do this using xml but I understand that I cannot.
So not to be bullheaded or stubborn, I will try to ask the question more clearly. Is there an example of sending an integer to the webpage not using xml.
I am sorry if I sound a little rude, I am not trying to be at all. I am struggling to put the pieces together and my communication skills suck.
Thanks Again
Shawn
You are correct I misspoke. Send a string representing the integer value like the code examples.
JavaScript can cast a string to an integer using parseInt(). Once converted to the value can be divided by 10.
It is possible but not with a browser and HTTP. In the code repo there is a zipped web site called W5200forQsDemo.zip. It contains a file called epin.htm which contains the client side JavaScript code examples. It does not have a parseInt() example but you should be able to figure that out by reading the w3schools example linked above.
Thank you for the thought, I would be very interested in seeing some example code if pick up a new board.
I am making acceptable progress on converting my integer variable to a string and then sending it to my html page. I am not quite there yet, but I am getting closer. I did miss speak in one of my previous posts. I said I wanted to send unsigned integers, but I really meant signed integers. I have some ideas on how to convert the unsigned and signed integers into strings and send them but I haven't investigated far enough on how the parseInt() command works in java. I want to do math on the values once the strings are converted back to integers.
I will have more questions eventually.
Thanks
Shawn
I have a spare Spinneret but no extra SD cards. If I blow out of work early enough - lots going on - I'll wire up an example. Otherwise, we're looking at this weekend.
Here is what the dat section looks like.
I am working on the integer to string filler now. It looks like it is all built into the server already I just need to figure out how to put it all together. I think I am pretty close. I am dealing with the neg sign now and I am hopeful I have it whooped, just need to try it. I am only using a single child xml file right now. I think the code above would have 20 children in it. I may be missing something with the terminology.
DAT
Filter: PRI RenderDynamic(id) | value
Convert Int to string
Some friendly advise, don't try to do too much at once. Pick a small problem and build code to solve the problem. IMO, building a large XML DAT section before understanding how to convert an integer to a string will cause confusion - too many moving parts.
I haven't had time to try it yet but I have looked it over a little. I did write a routine last night turning the integer into a string, but did not have a chance to test it. It looks similar to your code. My code may not work but I think I am on the right track.
This is great advice and I appreciate it. I have a tendency to run before I can walk. I think I understand the integer to string portion fairly well, I guess I will see tonight.
Thanks
Shawn
The example you put together in post #16 is excellent, thank you. I am still struggling with the javascript in the zip file but I am working my way through it.
Thanks Again
Shawn
Thanks
I don't understand what "this" method does?
I don't understand how the page elements are updated? Where is the link between the XML doc and the HTML DOM?
I have no idea what any of this JavaScript stuff is doing?
Shawn
This section of code appends the current date and time to the URL's query string to get around IE's aggressive caching scheme.
The snippet below converts XML to a string to be displayed in a textarea HTML element.
http://forums.parallax.com/showthread.php/149819-Spinneret-msrobots
I will have to read it a few more times.
Thanks
Shawn
http://parallax.msrobots.net/propeller-w5200-driver/Spinneret-msrobots/_README_Doc.htm
Is this the newest webserver code?
I have changed the xml file on the prop to hold 20 variables, and I have changed your html example to refresh 10 values on the screen when the get integer button is clicked.
I know you said watch it with the images but I have thrown a 6KB sized image on the screen also. I am using the w5200 which if I am not mistaken should be able to use 7 sockets to render files. So what I am thinking is that a 6KB sized image should not take more than 4 sockets for the server to spit it out.
The next thing I want to do is more of a java thing but if you don't mind me asking I would like to ask it here instead of joining a java forum, I think this info might be useful to other prop enthusiasts.
The image on my webpage, I would like to change the visible attribute on it depending on whether or not a particular child in my xml file is a 0 or a 1. I was going to do an image swapper but my digging into it so far has made me think it would be easier just to make the image visible or not visible.
This is my web page so far, try it out and tell let me no if the small picture shows up or not.
Oh ya, using internet exploder seems to lock up the server, I am not sure why yet, but I rarely use IE so I am not to concerned about that right now.
http://narnold79.dyndns-at-home.com:5000/
Also, what is the purpose of this code in the sint.html example you posted Mike? Is that just showing what the xml file is supposed to look like and it is commented out?
Thanks
Shawn
The next thing to figure out is how to get data from the web page to the web server. This should be interesting.
I think I understand all of the code here except for this part + "&value=" +. What does this do? pin and value are both values extracted from the two text boxes pinId and pinValue.
Edit: Correct me if I am wrong please. I think I have determined that the "&value=", is the string that the render dynamic routine uses to pull the proper value out of the get command. This is also what the ?led=" string is for, it holds the pin number. There are 2 variables in this get command and ?led=" and "&value=" are kind of like the identifiers for where the values start.
Edit: I am not sure what is going on with the code tags, I am not sure why it is in a table.
Thanks
Shawn
Sending data to a web server using a query string (HTTP GET) is a fundamental method in the HTTP protocol.
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
http://en.wikipedia.org/wiki/Query_string
http://www.w3schools.com/tags/ref_httpmethods.asp
What I want to do now goes kind of like this.
I set up a wamp server on a computer running in the basement.
I have a prop down stairs running my furnace. Attached to the prop is a wiznet board.
I want my website to be on my wamp server.
When I click a button on my website I want the wiznet board to spit out some data in an xml format to be displayed on the web page.
This seems like it should be doable.
I'm trying to do this with the example Mike posted in post #16.
I'm using Webserver 5200 object and I made the changes from post 16.
I put the Html file on my wamp server.
I modified the html file to include the complete url of the wiznet.
Smile I have to get back to work I will finish this post tonight.
Thanks
Shawn