var express = require('express');
var app = express();
var http = require('http').Server(app);
var {PythonShell} = require('python-shell');
const io = require('socket.io')(http);
const PORT = process.env.PORT || 3000;
app.get('/' , function(req, res){
res.sendFile(__dirname+'/index.html');
});
io.on('connection',function(socket){
socket.on('message',function(msg){
console.log('message: ' + msg);
io.emit('message', msg);
var pyshell = new PythonShell('com.py');
pyshell.send(msg);
pyshell.on('message', function(data) {
console.log('ret:' + data);
});
});
});
http.listen(PORT, function(){
console.log('server listening. Port:' + PORT);
});
webとの受け渡しようのプログラムができました。
2020年2月7日金曜日
ラズパイ(IOT・46)
今度は、Node.js側にメッセージが届いたら、
Pythonへメッセージをパラメータとして送れるように
app.jsのプログラムを調整します。
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿