mysql - LED Switch REST API -


I want to get help with my LED Switch REST API. I have made my own ASI and when I type in the URL, I am able to lighten my LED: Localhost: 3030/7/1 to light And localhost: 3030/7/0 to lights . But when I start my turn on and off manually without keying URL , my whole rest is enabled to start the API, but when I click my switch, someone The LEDs are not light.

This is my switch_rest_api.js

  var express = expected ('Express'); Var path = requirement ('path'); Var bodyParser = is required ('body-parser'); Var gpio = Requirement ('P-GPIO'); Var app = express (); Var mysql = Required ('mysql'); App.use (bodyParser.json ()); App.set ('port', process.env.PORT || 3030); Var conn = mysql.createConnection ({host: 'localhost', user: 'user', password: 'password', database: 'rest_api'}); App.get ('', function (req, res) {var pin = req.params.pin; gpio.open (pin, 'input', function (mistake) {if (pin === '12') {/ / Set pin 12 to speed up the LED GPIO light (12, 1, to turn on the function) {if throwing (mistake); other {gpio.open (pin, 'output', function (Mistake)} {gpio.write (7, 1, function) {conn.query ('sensor sensor log (sensor, log time, sensor value) value (1, current_temstamp (), 1)', function (Mistake) {If (mistake) becomes a mistake; {Console.log ("MySQL database Archive randomly ");}}); res.send (200); gpio.close (7);}); gpio.write (11, 1, function) (conn.query ('sensor sensor log in (SensorID, logtime, sensor value) value (2, current_timemstamp (), 1) ', function (mistake) {if (err) throw error; Else {console.log ("store in MySQL database successfully")}} ); Res.send (200); gpio.close (11);}); gpio.write (13, 1, function) (conn.query ('sensor sensor log (sensor id, logtime, sensor value) Value (3, current_temstamp (), 1) ', function (mistake) {i F (err) throw Err; Else {console.log ("store mysql successfully in database");}}); Res.send (200); Gpio.close (13);}); }); Console.log ("switch is on"); } Res.send (200); Gpio.close (12); }); }}); }); Var server = app.listen (app.get ('port'), function () {console.log ('listen at port% done', server.address (). Port);});  


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -