First
Some time ago, took a little time to do the number of children learning problems of the small program
Home
Do a problem interface (topics are randomly generated every time, subtraction)
To record a problem.
Now the question is coming, how can we know at any time whether the homework is finished?
It's too hard to refresh every time you open the title record page.
So I made a Raspberry Pi + small LED light equipment, the basic functions are as follows:
LED flashing-Indicates that the job is being checked and the job is not completed today
Solid LED-Indicates that the job has been detected completed
Reset the LED status once a day
To prepare the item:
-Raspberry Pi
-Led light bead 1, resistor one (220 ohm or 1K can)
Wiring:
36th Foot (GPIO16) through a resistor (220 kohm or 1K), and then received the positive level of the LED
Led negative level to 34th foot (GND)
Program
Get a Package.json first.
{ "name":"Sl.math.raspi", "version":"0.0.1", "Dependencies":{ "Rpio2":"0.4.1", "moment":"2.18.1" }}
And then the Index.js main program.
/** * Job Detector * Flashing light-in check job * Solid-the day the job is completed*/varServer = require ("./curl");ConstGpio = require (__dirname+'/node_modules/rpio2/lib/index.js'). Gpio;varLED =NewGpio ( $);//Create P36 PinLed.open (Gpio.output, Gpio.low);//set to OUTPUT, default lowConsole.log ("Operating system startup ..."); Flashled (Ten);varURL ="Http://116.62.192.119:3001/check";//var url = "http://116.62.192.119: 3001/check?cdata=2017-8-10 ";varDelayt =30000; function Checkcurdayhw () {//check current day homework;server.download (URL, function (data) {data =json.parse (data); Flashled (Ten); if(Data && data.length >0) { //The day the job is completedConsole.log (data.length);Led.state =1; Console.log ("The day the job is completed"); Delayt= -* -* +;//1-hour detection}Else{Delayt= -* +;//30 sec DetectionConsole.log ("job not detected ..."+delayt+"seconds and then check ."); } setTimeout (function () {CHECKCURDAYHW ()}, Delayt); });} CHECKCURDAYHW ();/** * Flashing light function * @param times flashes*/function flashled (times) { for(vari =0; I < times; i++) {led.toggle (); //Toggle the level status of LEDsLed.sleep ( -);//wait 500ms} led.state=0;}//led.close ();//Process.exit (); //Exit Program
There is also a component cur.js
varHTTP = require ("http");//Utility function that downloads a URL and invokes//callback with the data.function Download (URL, callback) {http.Get(URL, function (res) {vardata =""; Res.on ('Data', function (chunk) {data+=Chunk; }); Res.on ("End", function () {callback (data); }); }). On ("Error", function () {Callback (NULL); });} Exports.download= download;
Copy 3 files to a self-built directory on the Raspberry Pi
Directory structure:
and execute it in the directory first.
NPM Install
Start running when finished
Node Index.js
If the environment is not good, please first read the previous 2 articles:
Raspberry Pi. Mounting System +NODE.JS+MONGODB Series Environment
Raspberry Pi. Installing the Samba environment
Raspberry Pi. Using node. js to control Gpio
Raspberry Pi. Using node. js to create a job checker