Friday, July 17, 2015

Garden Robot Update 8

Quick update.  After WAY too long struggling how to get text info (like sensor readings) from the NXT to the webpage without refreshing, I looked into using Ajax in jquery and it turned out to be an EXTREMELY simple "get" command.  No need for Canvas text, no need to mess with the HTML (all of which, unfortunately, I tried.)  Basically, this in javascript:

$("#refresh").mousedown(function() {
    $.get('lightrefresh', function(data) {
    document.getElementById("lightlabel").innerHTML = ("Ambient Light:
" + data);
    });
    $.get('moisturerefresh', function(data) {
    document.getElementById("moisturelabel").innerHTML = ("Moisture Level:
" + data);
    });
});

(the key is the second argument to the $.get request, as "function(data)" will process whatever data you are getting back)

And in the .java file:

else if(uri.equals("lightrefresh")) {
    Log.w("HelloServer", "lightrefresh");    res = new Response(Response.Status.OK, MIME_PLAINTEXT, "999");}

else if(uri.equals("moisturerefresh")) {
    Log.w("HelloServer", "moisturerefresh");    res = new Response(Response.Status.OK, MIME_PLAINTEXT, "111");}

Of course, later, the "999" and "111" will be replaced with return values from the NXT as I discussed earlier.

To do:
1.  Continue to lay out the GUI.  (It looks so ugly now, I wonder how to make it look any better...?)
2.  Actually make it work with the NXT.  Put in the direct commands to control motors and get input values.
3.  Start to figure out some form of security...I really doubt I know enough to actually encrypt any data but I want at least a form of password-protection.  Like, really annoying password-protection.
4.  Start to design the actual thing...I certainly want some sort of CAD file, but I don't (currently) have SolidWorks, so I should probably look into MLCAD or something.  Or LDD, which I have used extensively in the past.
5.  Figure out where I can actually run this thing.  I need to talk to some people.