HTML Indicator Code

Discussion to talk about software related topics only.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: HTML Indicator Code

Post by tod »

If you want to have the NetBurner send back HTML code you ca do that and assign it with the deprecated (but still working) InnerHtml property. I believe I show how to do this in one of the AJAX demos. My preferred approach would be to just manipulate the style directly in a Javascript method. Going from memory it would look something like: (Assumes your Ajax returned a JSON object that you turned into jsObject and that the object has a field called status).

var the_node = $(theIdOfTheDivYouWantToChange) //$ is the Prototype library shortcut for document.GetElementById
if (jsObject.status ===0)
{
the_node.style.backgroundColor = "green";
}
else
{
the_node.style.backgroundColor = "red";
}
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

Nevermind, I found a stupid programming error.
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

No, maybe it wasn't a stupid programming error. I may have spoken too soon.

Tod-
I am having a problem with the AJAX code. I have added it to my existing code, largely unmodified, except for the specifics to make it do what I need it to do. The biggest change I have made is that I have shortened the refresh rate from 5 seconds to 1.5 seconds. I also have four browsers on four devices (two PC's (Firefox), two Android tablets) that are 'hitting' the NB for updates. It seems that after I have loaded or reloaded the page that has the AJAX code so many times (I have not figured out how many, yet), the NB crashes, like it has been overloaded. Hitting reset on the NB gets me going again for a while, until it is overloaded again. Any ideas?
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: HTML Indicator Code

Post by tod »

I can't really say. I have used the Ajax code on a very complicated projected that loaded hundreds of images and constantly sends data back and forth (typically to just one browser). I have also tested it doing callbacks as fast as every 100ms and it worked pretty flawlessly. If the NB is crashing, you might want to put it in the mode where it doesn't restart automatically and connect to the serial port so that you can see the register dump. Sometimes that will give you a good clue. Other times if you are overwriting memory the crash can happen well after the actual problem. The most likely culprit is overwriting a buffer. When you construct an Ajax response to send are you using ostringstream or writing into a preallocated char array? I don't remember how I wrote up the example, but ostringstream is much safer.

I also just noticed your other question about using Eclipse. I don't think the build system has ever worked properly regarding javascript files. What I do after modifying a .js file is I touch any .html file (typically I add then delete a space somewhere in the <Head> section). That lets the build system know something on the html section is dirty and it rebuilds it. This is much faster than doing a clean build every time.
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

I haven't figured out how to analyze this yet, but I do get a Trap Error, and the NB then reboots.

Trap occured
Vector=Access Error FMT =03 SR =2000 FS =0C
Faulted PC = 0200626C
D0:00000038 00000000 0000000A 00000000 00000021 2000C6B0 020D854D 02006278
A0:00000038 40000204 2000C650 0202AE0F 02019E94 02006230 050083D4 020D83C0
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: HTML Indicator Code

Post by tod »

Looks like you don't have smart traps enabled. If that is true add the call (I don't have the environment running right now - so I can't give you exact steps but you can start a new project with the wizard and it will allow you to select the smart trap checkbox and then you can just go copy and paste the code). With smart traps you get information on the running processes and its usually pretty obvious which one was active when it trapped. The Wiki has information on using WinAddr2Line to turn that hex info into source code line numbers. Sometimes it helps a lot other times your trap is a result of trashing memory and you don't see the trap until much later. Odds are good you have a buffer that is the wrong size or you're using something like printf and passing in a mismatch between a placeholder and a parameter. Something like using %d and passing in a float is a good way to cause a trap (which is why I like the typesafe C++ lib calls over the C ones).
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

I will be going back down to where the hardware is shortly. I did try to enable smarttraps, but when it crashed, it simply gave no information, rather than the usual trap screen. I found a spot in there where I may have been improperly closing the TCP port I was reading during the AJAX calls, and perhaps that was 'piling up'. I will go experiment with both that and the smarttraps today. I really do appreciate all of your help and insight!
User avatar
Chris Ruff
Posts: 222
Joined: Thu Apr 24, 2008 4:09 pm
Location: topsail island, nc
Contact:

Re: HTML Indicator Code

Post by Chris Ruff »

FYI

there is a default limit of 32 sockets in certain uses of them in the NB library. I fixed a problem a long time ago by limiting the amount of open sockets to the 32. you may be on to it

Chris
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

Well, I did fix the problem with closing the port, but that was apparently not it. Since enabling smart traps, I now get no crash info when it crashes. Also, sometimes it resets, and sometimes it just hangs, and needs a hard reset.

How do I limit the number of open sockets? I did try to limit the number of devices 'hitting' the NB, and my only observation was that it seemed to take a little longer to crash. Since it crashes seemingly randomly, it is hard to tell if that is really true. Sometimes it takes 60 seconds to crash, other times it may run for a couple of hours.
nemiro
Posts: 21
Joined: Mon Sep 06, 2010 10:51 am

Re: HTML Indicator Code

Post by nemiro »

OK, may have isolated part (or all of the problem). Inside my AJAX functioncall, I make a write a string via TCP to a device, and then receive a response. The response is then sent back to the HTML. If I leave everything else alone, but comment out the TCP calls, it seems to run fine. Is it possible that while the NB is handling a request to this function, that another device runs the functioncall at the same time? If so, do I need to add in some type of code that blocks the other device (like turning off an interrupt) while it is servicing the routine? I wonder if this could be the cause of the crashes?
Post Reply