Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var pyshell = require('python-shell');
  2. var fs = require('fs');
  3. let _uid = '';
  4. let _pwd = '';
  5.  
  6.  
  7. if (process.argv[2] == null) {
  8.     console.log("IP parameter can't empty");
  9.     process.exit();
  10. }
  11. var socket = require('socket.io-client')('http://' + process.argv[2] + ':8000');
  12.  
  13. socket.on('clientTest', function (data) {
  14.     console.log('data :', data);
  15. });
  16.  
  17. socket.on('idToJetson', function (data) {
  18.     console.log('data: ', data);
  19.     let options = {
  20.         mode: 'text',
  21.         args: [data.id]
  22.     };
  23.     pyshell.PythonShell.run('../get_id_from_clientjs.py', options, function (err) {
  24.         if (err) throw err;
  25.     });
  26.     _uid = data.uid;
  27.     _pwd = data.pwd;
  28. });
  29.  
  30. function intervalFunc() {
  31.     try {
  32.         let content = fs.readFileSync('test.txt', 'utf8');
  33.         if (content != '') {
  34.             console.log(content);
  35.             socket.emit('faceRecogn', {
  36.                 result: content,
  37.                 uid: _uid,
  38.                 pwd: _pwd
  39.             });
  40.             fs.writeFile('test.txt', '', function () {});
  41.             _uid = '';
  42.             _pwd = '';
  43.         }
  44.     } catch (e) {
  45.         console.log('Error:', e.stack);
  46.     }
  47. }
  48. setInterval(intervalFunc, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement