B4R Question HTLM Query

daveinhull

Active Member
Licensed User
Longtime User
Hi

I'm trying to setup the ESP8266 as a mini webserver specificlaly to control a small deivce. Everything is generally working well.
But I have a problem in the following code.
Just a bit of background, the webpage has just a few controls on it (buttons and labels mainly) and one input time field. I'd like to set the default for this to what has been set previously and is stored in the ESP8266 (I have to do it this way rather than using the client as there could be multiple clients). I'm using the window.onload to do this (there may be other ways)

The first code snippet works fine, but the second doesn't. I suspect it is something to do with UTF-8 (I believe B4R uses) v. UTF-16 (I beleive HTML pages use)
Could someone confirm that it is to do with the UTF coding or offer any other cause/solution, and if it is to do with UTF coding, is there a routine anywhere that would convert from UTF-8 to UTF-16.

This works fine:
B4X:
            Astream.Write ("<script>")
            Astream.Write ("window.onload = function() {document.getElementById('FeedTime').value =""12:34"";}")
            Astream.Write ("</script>")

Bute this doesn't work:
B4X:
            Astream.Write ("<script>")
            Dim FeedTimeString as String = "12:34"
            Astream.Write ("window.onload = function() {document.getElementById('FeedTime').value = """).Write(FeedTimeString).Write(""";}")
            Astream.Write ("</script>")

Many thanks in advance
Dave
 

peacemaker

Expert
Licensed User
Longtime User
But try to see in the log the result of second line first.

Why not

B4X:
Astream.Write("window.onload = function() {document.getElementById('FeedTime').value = '")
Astream.Write(FeedTimeString)
Astream.Write("';}")
?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
In B4R strings are not recommended to use!
see this:
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
I do get that, but I was just trying to do a direct comparison between a constant string that the HTML expects and works, and a variable string set up as a constant that doesn't work.
Ultimately, the FeedTimeString would be replaced with a value, which would need to be in bytes as a variable.

Thanks for the reminder though.
Dave
 
Upvote 0

daveinhull

Active Member
Licensed User
Longtime User
Hi peacemaker,

Thanks, that did it. But, I'm sure I tried using single quotes, albeit in a single write.write.write format, without success. But, in trying to get it working, I may have messed something else up along the ways.
Nice just to be brought back down to earth, and think straight again after a simple prompt.

One can sometimes make things a whole lot more complicated than they need to be.

Thanks again
Dave
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…