2025年4月6日日曜日

Nodejs :: cnako3 on linux / johnny-five&express&fbrtdb-Led制御

 # 必要な宣言

!「/home/fseigojp/node_modules/nadesiko3-sqlite3/nadesiko3-sqlite3.js」を取り込む。

#このフル記載が重要だった!

# ファイルを開く

「test.sqlite3」のSQLITE3開く。


# SQLを実行

『CREATE TABLE IF NOT EXISTS books(id, name)』を[]でSQLITE3実行。

『INSERT INTO books (id,name) VALUES(?,?)』を[1,"aaa"]でSQLITE3実行。


# SQLを実行して結果を得る

『SELECT * FROM books』を[]でSQLITE3全取得

それをJSONエンコードして表示。


以上をcnako3 test.nakoで実行できた
https://nadesi.com/v3/doc/index.php?nadesiko3-sqlite3%2FSQLite3&show 参照
-------------------------------------------------------------------------------
https://qiita.com/ryome/items/16659012ed8aa0aa1fac でexpress実習できたので
https://github.com/dgmd/johnny-five-express-sampleへすすむ。。。 一応うごいた
localhost:3000/led/on or offでled制御成功

const {Board,Led} = require("johnny-five"); 
// Load the node library that lets us talk JS to the Arduino
var board = new Board(); // Connect to the Arduino using that library

board.on("ready", function() { // Once the computer is connected to the Arduino
    // Save convenient references to the LED pin and an analog pin
    var LEDpin = new Led(13);
  
   var express = require('express'); // Load the library we'll use to set up a basic webserver
    var app = express(); // And start up that server

    app.get('/', function(req, res) { // what happens when we go to `/`
        res.send("Hello from `server.js`!"); // Just send some text
    });

    app.get('/hello', function(req, res) { // what ha1ppens when we go to `/hello`
        res.sendFile('hello.html', { root: '.' }); // Send back the file `hello.html` located in the current directory (`root`)
    });

    
    app.get('/led/off', function(req, res) { // what happens when someone goes to `/led/off`
        console.log("Someone told me to turn the led off…");
        LEDpin.off(); // Set the pin referred to by the `LEDpin` variable 'low' (off)
        res.send("Now the LED for pin 13 should be off."); // And tell the user that it should be off in the webpage
    });

    app.get('/led/on', function(req, res) { // what happens when someone goes to `/led/off`
        console.log("Someone told me to turn the led on…");
        LEDpin.on(); // Set the pin referred to by the `LEDpin` variable 'high' (on)
        res.send("Now the LED for pin 13 should be on.") // And tell the user that it should be off in the webpage
    });

    app.listen(3000, function() { // Actually turn the server on
        console.log("Server's up at http://localhost:3000!");
    });
});

0 件のコメント:

コメントを投稿