|
CLASS DOCUMENTS
REPORTS & ASSIGNMENTS
CLASS CONTENT
USING THIS SITE
registered authors login here You are: (logout) For more on PMWiki, see pmwiki.org |
SH T11-Flash Loggerby Keunyoung Oh This Flash code makes to a HTTP GET/POST request to a Perl script that reads a mySQL database. It connects a SHT11 temperature and humidity sensor to a mySQL database and to a Flash-based visualization of the resulting data.
//perl-flash logger
//by Kay oh 2005 fall
serverPath = "http://itp.nyu.edu/~[yourID]/cgi-bin";
genVarObj = new LoadVars();
serverScript = serverPath+"/flash_perl1.pl";
genVarObj.load(serverScript);
this.createEmptyMovieClip("line_mc", 1000);
line_mc.lineStyle(5, 0xFF00FF, 100);
var tempvar = 0;
var id = setInterval(refreshContents, 500);
var myHumid;
genVarObj.onLoad = function() {
currentTime = localFormatDateTime(); // Get current time
textContents.text = "Last Checked: " + currentTime + "\n"; //<--show time
tempTxt.text = myHumid/10; //<-- show the humidity
mynewname = "myHumid"; //<-- passed by perl
myHumid = genVarObj[mynewname];
_root.test._alpha = 100 - myHumid/7;
_root.line_mc.moveTo(-5*tempvar, 400);
_root.line_mc.lineTo(-5*tempvar, 800-myHumid);
_root.line_mc._x +=5;
tempvar++;
}
function refreshContents()
{
genVarObj.load(serverScript);
_root.genvar.text = genVarObj;
}
// Returns current time in MM/DD/YYYY HH:MM:SS
function localFormatDateTime()
{ // Create general date var for showing current time
var myDate = new Date();
// Put current date in MM/DD/YYYY format
localDate = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear();
// Get the hours and format
localHours = myDate.getHours();
if (length(localHours)<2)
{ localHours = "0"+localHours;
}
// Get the minutes and format
localMins = myDate.getMinutes();
if (length(localMins)<2)
{ localMins = "0"+localMins;
}
// Get the seconds and format
localSecs = myDate.getSeconds();
if (length(localSecs)<2)
{ localSecs = "0"+localSecs;
}
// Remove date obj we just created to free up memory
delete myDate;
// Return the formatted datetime
return(localDate + " " + localHours + ":" + localMins + ":" + localSecs);
}
|