{"id":4081,"date":"2019-07-09T01:54:37","date_gmt":"2019-07-08T16:54:37","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=4081"},"modified":"2020-04-27T18:29:35","modified_gmt":"2020-04-27T09:29:35","slug":"__trashed","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=4081","title":{"rendered":"\u3010Python\u3011Pasori RC-S380\u3067\u5165\u9000\u5ba4\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u3053\u306e\u3068\u3053\u308d\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u3068\u30ea\u30a2\u30eb\u3092\u878d\u5408\u3055\u305b\u305f\u30b7\u30b9\u30c6\u30e0\u3092\u7d39\u4ecb\u3059\u308b\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u3044\u308b\u6d41\u308c\u3092\u53d7\u3051\u3066\u3001\u307e\u305f\u3072\u3068\u3064\u524d\u304b\u3089\u3084\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u305f\u5185\u5bb9\u3092\u601d\u3044\u51fa\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u308c\u306f\u3001\u4ee5\u524d\u898b\u3066\u300c\u3053\u308c\u306f\u3059\u3054\u3044\uff01\u300d\u3068\u601d\u3063\u305f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u304c\u5143\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/qiita.com\/saturday06\/items\/333fcdf5b3b8030c9b05\" target=\"_blank\" rel=\"noopener noreferrer\">WebUSB\u3067FeliCa\u306e\u4e00\u610f\u306aID\u3067\u3042\u308bIDm\u3092\u8aad\u3080<\/a><\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306f2017\u5e74\u306b\u6295\u7a3f\uff08\u66f4\u65b0\uff1f\uff1f\uff09\u3055\u308c\u305f\u3088\u3046\u306a\u306e\u3067\u5c11\u3057\u524d\u306e\u3082\u306e\u3067\u3059\u304c\u3001USB\u5f62\u5f0f\u306e\u975e\u63a5\u89e6\u30ab\u30fc\u30c9\u30ea\u30fc\u30c0\u3067\u30e6\u30cb\u30fc\u30af\u306aID\u3092\u53d6\u5f97\u3067\u304d\u308b\u3068\u306a\u308c\u3070\u3001QR\u30b3\u30fc\u30c9\u3092\u8aad\u307f\u53d6\u308b\u3088\u308a\u3082\u5229\u4fbf\u6027\u304c\u9ad8\u3044\u30b7\u30b9\u30c6\u30e0\u3092\u4f5c\u308c\u308b\u3093\u3058\u3083\u306a\u3044\u304b\uff01\uff1f\u3068\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u8ca1\u5e03\u3092\u8fd1\u3065\u3051\u308b\u3060\u3051\u306e\u300c\u30e9\u30af\u30e9\u30af\u5165\u9000\u5ba4\u30b7\u30b9\u30c6\u30e0\u300d\u304c\u7c21\u5358\u306b\u3064\u304f\u308c\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u9593\u30aa\u30f3\u30e9\u30a4\u30f3\u30b7\u30e7\u30c3\u30d7\u3067\u4ed5\u4e8b\u306e\u5099\u54c1\u3092\u8cfc\u5165\u3059\u308b\u969b\u306b\u3001\u3053\u306eUSB\u30ab\u30fc\u30c9\u30ea\u30fc\u30c0\u30fc\u3092\u767a\u898b\u3001\u3055\u3089\u306b2,000\u5186\u53f0\u3067\u58f2\u3063\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u601d\u308f\u305a\u30dd\u30c1\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\uff08100\uff05\u8208\u5473\u672c\u4f4d\u3067\u3059\u30fb\u30fb\u30fb\ud83d\ude02\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4087\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/entry_exit_1.jpg\" alt=\"\" width=\"640\" height=\"853\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/entry_exit_1.jpg 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/entry_exit_1-225x300.jpg 225w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u305b\u3063\u304b\u304f\u306a\u306e\u3067<code>Pasori RC-S380<\/code>\u3092\u4f7f\u3063\u3066\u7c21\u5358\u306a\u5165\u9000\u5ba4\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-417 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png\" alt=\"\" width=\"370\" height=\"220\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/04\/9-300x178.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p>\u5b9f\u884c\u74b0\u5883\uff1a Python 2.7, Ubuntu 18.04<\/p>\n<h1>\u30b3\u30fc\u30c9\u3092\u3064\u304f\u308b\u524d\u306b<\/h1>\n<p>\u5143\u3005\u306f\u5192\u982d\u306e\u8a18\u4e8b\u3068\u540c\u3058\u304f<code>WebUSB<\/code>\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3092\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u304c\u3001OS\u306b\u9650\u3089\u305a\u30d6\u30e9\u30a6\u30b6\uff08Google Chrome\uff09\u304b\u3089USB\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u5c11\u3057\u8907\u96d1\u306a\u8a2d\u5b9a\u3092\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u4eca\u56de\u306f\u30b7\u30f3\u30d7\u30eb\u306bPython\u306e\u307f\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u306e\u5b9f\u88c5\u5185\u5bb9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>IC\u30ab\u30fc\u30c9\uff08Felica\uff09\u3092\u4f7f\u3063\u3066\u5165\u5ba4\uff0f\u9000\u5ba4\u51e6\u7406\u304c\u3067\u304d\u308b<\/li>\n<li>\u6574\u5408\u6027\u304c\u3068\u308c\u306a\u3044\u5834\u5408\uff08\u5165\u5ba4\u3001\u3082\u3057\u304f\u306f\u9000\u5ba4\u306e\u9023\u7d9a\u5b9f\u884c\uff09\u306f\u30a8\u30e9\u30fc\u3092\u51fa\u3059<\/li>\n<li>\u5165\u5ba4\uff0f\u9000\u5ba4\u3057\u305f\u65e5\u6642\u306fMySQL\u306b\u4fdd\u5b58\u3059\u308b<\/li>\n<\/ol>\n<h1>Pasori\u306e\u63a5\u7d9a<\/h1>\n<p><code>Pasori<\/code>\u306e\u63a5\u7d9a\u306f\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002\u6b63\u76f4\u306a\u3068\u3053\u308d\u9014\u4e2d\u30cf\u30de\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u52a9\u304b\u308a\u307e\u3057\u305f\u3002\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\ud83d\ude0a\u2728<\/p>\n<p><a href=\"https:\/\/qiita.com\/75u2u\/items\/010b602605d087edd1ee\">Python \u3067 PaSoRi\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7 \u3068 FeliCa\u306e\u8aad\u307f\u53d6\u308a<\/a><\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u3082\u3057\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066<strong>\u300calready used\u300d<\/strong>\u3068\u8868\u793a\u3055\u308c\u305f\u5834\u5408\u3001<code>port100<\/code>\u304c\u3059\u3067\u306b<code>Linux<\/code>\u306e<code>nfc<\/code>\u30ab\u30fc\u30cd\u30eb\u30c9\u30e9\u30a4\u30d0\u30fc\u306b\u3088\u3063\u3066\u4f7f\u308f\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u539f\u56e0\u3067\u3059\u3002<\/p>\n<pre><strong>sudo python -m nfc<\/strong><\/pre>\n<blockquote><p>\uff08\u7701\u7565\uff09<br \/>\nfound usb:054c:06c3 at usb:001:040 but it&#8217;s already used &#8230;<\/p><\/blockquote>\n<p>\u305d\u3053\u3067\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c9\u30e9\u30a4\u30d0\u30fc\u3092\u30ab\u30fc\u30cd\u30eb\u304b\u3089\u958b\u653e\u3057\u3066\u3042\u3052\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>sudo modprobe -r port100<\/strong><\/pre>\n<p>\u3082\u3057\u304f\u306f\u3001\u6bce\u56de\u3053\u308c\u3092\u3084\u308b\u306e\u304c\u3081\u3093\u3069\u3046\u306a\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30d6\u30e9\u30c3\u30af\u30ea\u30b9\u30c8\u306b\u5165\u308c\u3066\u304a\u3051\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<pre><strong>sudo sh -c 'echo blacklist port100 &gt;&gt; \/etc\/modprobe.d\/blacklist-nfc.conf'<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u6700\u7d42\u7684\u306b\u6b21\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308c\u3070\u5b8c\u4e86\u3067\u3059\u3002<\/p>\n<pre>\uff08\u7701\u7565\uff09\r\n<strong>** found SONY RC-S380\/P NFC Port-100 v1.11 at usb:001:042<\/strong><\/pre>\n<h1>\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h1>\n<p><code>nfcpy<\/code>\u306f\u5148\u307b\u3069\u306e\u30da\u30fc\u30b8\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u304c\u3001<code>MySQL<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f<code>mysql-connector<\/code>\u3082\u5fc5\u8981\u3067\u3059\u306e\u3067<code>pip<\/code>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>pip install mysql-connector<\/strong><\/pre>\n<h1>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6e96\u5099<\/h1>\n<p>\u5fc5\u8981\u306b\u306a\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\uff13\u30c6\u30fc\u30d6\u30eb\u3067\u3059\u3002<\/p>\n<ul>\n<li>users\u3000\u30fb\u30fb\u30fb\u3000\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\uff08\u3053\u3053\u306b\u4e8b\u524d\u306b\u30ab\u30fc\u30c9\u306eID\u3092\u767b\u9332\u3057\u3066\u304a\u304f\uff09<\/li>\n<li>room_entries\u3000\u30fb\u30fb\u30fb\u3000\u5165\u5ba4\u30c7\u30fc\u30bf\uff08\u3044\u3064\u8ab0\u304c\u5165\u5ba4\u3057\u305f\u304b\u304c\u5206\u304b\u308b\uff09<\/li>\n<li>room_exits\u3000\u30fb\u30fb\u30fb\u3000\u9000\u5ba4\u30c7\u30fc\u30bf\uff08\u3044\u3064\u3060\u308c\u304c\u9000\u5ba4\u3057\u305f\u304b\u304c\u5206\u304b\u308b\uff09<\/li>\n<\/ul>\n<p>\u4eca\u56de\u306f<code>Python<\/code>\u306e\u8a18\u4e8b\u3067\u3059\u304c\u3001\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\u306f\u3044\u3064\u3082\u4f7f\u3044\u6163\u308c\u305f<code>Laravel<\/code>\u304c\u4fbf\u5229\u306a\u306e\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u3063\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\uff08users\u30c6\u30fc\u30d6\u30eb\uff09<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nclass CreateUsersTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n        Schema::create('users', function (Blueprint $table) {\r\n            <strong>$table-&gt;bigIncrements('id');\r\n            $table-&gt;string('name');\r\n            $table-&gt;string('email')-&gt;unique();\r\n            $table-&gt;timestamp('email_verified_at')-&gt;nullable();\r\n            $table-&gt;string('password');\r\n            $table-&gt;string('nfc_idm')-&gt;nullable();\r\n            $table-&gt;rememberToken();\r\n            $table-&gt;timestamps();<\/strong>\r\n        });\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('users');\r\n    }\r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4098\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_5.png\" alt=\"\" width=\"357\" height=\"337\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_5.png 357w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_5-300x283.png 300w\" sizes=\"auto, (max-width: 357px) 100vw, 357px\" \/><\/p>\n<p>\u305d\u3057\u3066<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u6b21\u306e\u3088\u3046\u306a\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002\u30c6\u30b9\u30c8\u3059\u308b\u3068\u304d\u306b\u306f<code>nfc_idm<\/code>\u3092\u5b9f\u969b\u306e\u30ab\u30fc\u30c9ID\u3078\u5909\u66f4\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4099\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_8.png\" alt=\"\" width=\"1024\" height=\"457\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_8.png 1024w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_8-300x134.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_8-768x343.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p><strong>\uff08room_entries\u30c6\u30fc\u30d6\u30eb\uff09<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nclass CreateRoomEntriesTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n        Schema::create('room_entries', function (Blueprint $table) {\r\n            <strong>$table-&gt;bigIncrements('id');\r\n            $table-&gt;unsignedBigInteger('user_id');\r\n            $table-&gt;dateTime('entered_at');\r\n            $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');<\/strong>\r\n        });\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('room_entries');\r\n    }\r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4097\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_6.png\" alt=\"\" width=\"353\" height=\"208\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_6.png 353w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_6-300x177.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/p>\n<p><strong>\uff08room_exits\u30c6\u30fc\u30d6\u30eb\uff09<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nclass CreateRoomExitsTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n        Schema::create('room_exits', function (Blueprint $table) {\r\n            <strong>$table-&gt;bigIncrements('id');\r\n            $table-&gt;unsignedBigInteger('user_id');\r\n            $table-&gt;dateTime('exited_at');\r\n            $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');<\/strong>\r\n        });\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('room_exits');\r\n    }\r\n}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4098\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_7.png\" alt=\"\" width=\"357\" height=\"337\" \/><\/p>\n<h1>\u5b9f\u969b\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h1>\n<p>\u3067\u306f\u3001<code>Pasori<\/code>\u304b\u3089\u5165\u9000\u5ba4\u51e6\u7406\u3092\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4eca\u56de\u306f\u300c\u5165\u5ba4\u300d\u3068\u300c\u9000\u5ba4\u300d\u306e2\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308b\u306e\u3067\u3001\u72ec\u81ea\u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066<code>entry.py<\/code>\u3068<code>exit.py<\/code>\u304b\u3089\u305d\u308c\u305e\u308c\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f\u72ec\u81ea\u30af\u30e9\u30b9<code>entry_exit.py<\/code>\u3067\u3059\u3002<\/p>\n<pre>#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nimport nfc\r\nimport binascii\r\nimport mysql.connector\r\nimport datetime\r\nimport signal\r\n\r\nclass manager:\r\n    NFC_READER_ID = 'usb:054c:06c3' # Pasori-380\r\n    DB_HOST = 'DB_HOST'\r\n    DB_DATABASE = 'DB_DATABASE'\r\n    DB_USERNAME = 'DB_USER'\r\n    DB_PASSWORD = 'DB_PASSWORD'\r\n    db = None\r\n    mode = None\r\n    def __init__(self, mode):\r\n        self.mode = mode\r\n        self.connect_to_mysql()\r\n        try :\r\n            <strong>while True:<\/strong>\r\n<strong>                print(\"\\n\" + '--- \u7d42\u4e86\u3059\u308b\u5834\u5408\u306f\u300cCtrl + C\u300d\u3092\u62bc\u3057\u7d9a\u3051\u3066\u304f\u3060\u3055\u3044 ---')<\/strong>\r\n<strong>                print('IC\u30ab\u30fc\u30c9\u3092\u8fd1\u3065\u3051\u3066\u304f\u3060\u3055\u3044\u3002')<\/strong>\r\n<strong>                clf = nfc.ContactlessFrontend(self.NFC_READER_ID)<\/strong>\r\n<strong>                clf.connect(rdwr={'on-connect': self.on_nfc_connect})<\/strong>\r\n<strong>                clf.close()<\/strong>\r\n        except:\r\n            print('[Error] Pasori\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002')\r\n            exit()\r\n\r\n    # nfc\r\n    <strong>def on_nfc_connect(self, tag):<\/strong>\r\n<strong>        idm = binascii.hexlify(tag.idm)<\/strong>\r\n<strong>        user = self.get_user(idm)<\/strong>\r\n<strong>        if user == None:<\/strong>\r\n<strong>            print('[Error] \u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002')<\/strong>\r\n<strong>            return True<\/strong>\r\n<strong>        mode_text = self.get_mode_text()<\/strong>\r\n<strong>        now = self.get_now()<\/strong>\r\n<strong>        self.insert_data(user)<\/strong>\r\n<strong>        return True<\/strong>\r\n\r\n    # DB\r\n    <strong>def connect_to_mysql(self):<\/strong>\r\n<strong>        try:<\/strong>\r\n<strong>            self.db = mysql.connector.connect(<\/strong>\r\n<strong>                    host=self.DB_HOST,<\/strong>\r\n<strong>                    database=self.DB_DATABASE,<\/strong>\r\n<strong>                    user=self.DB_USERNAME,<\/strong>\r\n<strong>                    passwd=self.DB_PASSWORD<\/strong>\r\n<strong>                )<\/strong>\r\n<strong>        except:<\/strong>\r\n<strong>            print('[Error] DB\u63a5\u7d9a\u5931\u6557\u3002')<\/strong>\r\n<strong>            exit()<\/strong>\r\n<strong>    def insert_data(self, user):<\/strong>\r\n<strong>        user_id = user[0]<\/strong>\r\n<strong>        user_name = user[1].encode(encoding='UTF-8')<\/strong>\r\n<strong>        mode_text = self.get_mode_text()<\/strong>\r\n<strong>        if self.is_duplicated(user_id) == True:<\/strong>\r\n<strong>            print('\u3059\u3067\u306b\u3010%s\u51e6\u7406\u3011\u306f\u5b8c\u4e86\u3057\u3066\u3044\u307e\u3059\u3002' % (mode_text))<\/strong>\r\n<strong>            return True<\/strong>\r\n<strong>        now = self.get_now()<\/strong>\r\n<strong>        query = ''<\/strong>\r\n<strong>        if self.mode == 'entry':<\/strong>\r\n<strong>            query = 'INSERT INTO room_entries (user_id, entered_at) VALUES(\"%s\", \"%s\")' % (user_id, now)<\/strong>\r\n<strong>        elif self.mode == 'exit':<\/strong>\r\n<strong>            query = 'INSERT INTO room_exits (user_id, exited_at) VALUES(\"%s\", \"%s\")' % (user_id, now)<\/strong>\r\n<strong>        cursor = self.db.cursor()<\/strong>\r\n<strong>        result  = cursor.execute(query)<\/strong>\r\n<strong>        self.db.commit()<\/strong>\r\n<strong>        print(now +': %s \u3055\u3093\u306e\u3010%s\u51e6\u7406\u3011\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002' % (user_name, mode_text))<\/strong>\r\n<strong>    def is_duplicated(self, user_id):<\/strong>\r\n<strong>        if self.mode == 'entry':<\/strong>\r\n<strong>            query = 'SELECT entered_at FROM room_entries WHERE user_id = \"%s\" ORDER BY entered_at DESC LIMIT 1' % (user_id)<\/strong>\r\n<strong>        elif self.mode == 'exit':<\/strong>\r\n<strong>            query = 'SELECT exited_at FROM room_exits WHERE user_id = \"%s\" ORDER BY exited_at DESC LIMIT 1' % (user_id)<\/strong>\r\n<strong>        cursor = self.db.cursor()<\/strong>\r\n<strong>        cursor.execute(query)<\/strong>\r\n<strong>        result = cursor.fetchone()<\/strong>\r\n<strong>        if result == None:<\/strong>\r\n<strong>            return False<\/strong>\r\n<strong>        last_accessed_at = result[0].strftime(\"%Y-%m-%d %H:%M:%S\")<\/strong>\r\n<strong>        if self.mode == 'entry':<\/strong>\r\n<strong>            query = 'SELECT COUNT(id) FROM room_exits WHERE user_id = \"%s\" AND exited_at &gt; \"%s\"' % (user_id, last_accessed_at)<\/strong>\r\n<strong>        elif self.mode == 'exit':<\/strong>\r\n<strong>            query = 'SELECT COUNT(id) FROM room_entries WHERE user_id = \"%s\" AND entered_at &gt; \"%s\"' % (user_id, last_accessed_at)<\/strong>\r\n<strong>        cursor.execute(query)<\/strong>\r\n<strong>        result = cursor.fetchone()<\/strong>\r\n<strong>        data_count = int(result[0])<\/strong>\r\n<strong>        return (data_count == 0)<\/strong>\r\n\r\n    # Getter\r\n    def get_user(self, idm):\r\n        query = 'SELECT id, name FROM users WHERE nfc_idm = \"%s\"' % (idm)\r\n        cursor = self.db.cursor()\r\n        cursor.execute(query)\r\n        return cursor.fetchone()\r\n    def get_mode_text(self):\r\n        if self.mode == 'entry':\r\n            return '\u5165\u5ba4'\r\n        elif self.mode == 'exit':\r\n            return '\u9000\u51fa'\r\n        return None\r\n    def get_now(self):\r\n        return datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")<\/pre>\n<p>\u30b3\u30fc\u30c9\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u4ee5\u4e0b\u306e\uff12\u3064\u3060\u3051\u3067\u3059\u3002<\/p>\n<ol>\n<li>Pasori\u306b\u63a5\u7d9a\u3057\u3066\u30ab\u30fc\u30c9\u304c\u8fd1\u3065\u304f\u306e\u3092\u5f85\u6a5f<\/li>\n<li>\u30ab\u30fc\u30c9\u304b\u3089ID\u304c\u53d6\u5f97\u3067\u304d\u305f\u3089\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u53c2\u7167\u3057\u3066\u5165\u5ba4\uff0f\u9000\u5ba4\u51e6\u7406\u3092\u3059\u308b<\/li>\n<\/ol>\n<p>\u91cd\u8981\u306a\u306e\u306f\u3001\u5165\u5ba4 or \u9000\u51fa\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u305f\u6642\u70b9\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u307e\u3067\u7d42\u4e86\u3057\u3066\u3057\u307e\u3046\u3068\u3001\u305d\u306e\u305f\u3073\u306b\u30b3\u30fc\u30c9\u5b9f\u884c\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u305f\u3081\u3001<code>while<\/code>\u6587\u3067\u6c38\u9060\u306b\u51e6\u7406\u3092\u7d9a\u3051\u3066\u3044\u308b\u90e8\u5206\u3067\u3059\u3002\uff08\u305d\u306e\u305f\u3081\u3001\u30b3\u30fc\u30c9\u3092\u7d42\u4e86\u3059\u308b\u306b\u306f<code>Ctrl+C<\/code>\u3092\u9577\u62bc\u3057\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff09<\/p>\n<p>\u30af\u30e9\u30b9\u306e\u6b21\u306f\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002<br \/>\n\u30fb\u30fb\u30fb\u3068\u306f\u3044\u3063\u3066\u3082\u3001\u307b\u3068\u3093\u3069\u30af\u30e9\u30b9\u306b\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u3066\u3044\u308b\u306e\u3067\u305d\u308c\u305e\u308c2\u884c\u3060\u3051\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\uff08entry.py\uff09<\/p>\n<pre><strong>import entry_exit\r\nentry_exit.manager('entry')<\/strong><\/pre>\n<p>\uff08exit.py\uff09<\/p>\n<pre><strong>import entry_exit\r\nentry_exit.manager('exit')<\/strong><\/pre>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u5b9f\u884c\u30b3\u30de\u30f3\u30c9\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u3042\u308b\u30d5\u30a9\u30eb\u30c0\u306b\u79fb\u52d5\u3057\u3066<code>sudo python entry.py<\/code>\u3067\u3059\u3002<\/p>\n<p>\u3046\u307e\u304f\u8d77\u52d5\u3067\u304d\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5f85\u6a5f\u4e2d\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4090\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_1.png\" alt=\"\" width=\"491\" height=\"70\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_1.png 491w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_1-300x43.png 300w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u72b6\u614b\u3067<code>Pasori<\/code>\u306b\u30ab\u30fc\u30c9\u3092\u8fd1\u3065\u3051\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4091\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_2.png\" alt=\"\" width=\"539\" height=\"81\" \/><\/p>\n<p>\u306f\u3044\uff01\u4e0a\u624b\u304fDB\u306b\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\n\u3067\u306f\u3001\u3053\u306e\u72b6\u614b\u3067\u3082\u3046\u4e00\u5ea6\u30ab\u30fc\u30c9\u3092\u8fd1\u3065\u3051\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4094\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_3.png\" alt=\"\" width=\"333\" height=\"38\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_3.png 333w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_3-300x34.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/p>\n<p>\u9000\u5ba4\u3059\u308b\u524d\u306b2\u5ea6\u3081\u306e\u5165\u5ba4\u51e6\u7406\u3092\u3057\u305f\u306e\u3067\u3001\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n<span style=\"font-size: 1rem;\">\u3067\u306f\u3001\u9000\u5ba4\u306e\u65b9\u3082\u3084\u3063\u3066\u307f\u307e\u3059\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4095\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_4.png\" alt=\"\" width=\"553\" height=\"34\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_4.png 553w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/07\/pasori_4-300x18.png 300w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/><\/p>\n<p>\u306f\u3044\u3001\u4eca\u5ea6\u306f\u5165\u5ba4\u2192\u9000\u5ba4\u306e\u6d41\u308c\u306a\u306e\u3067\u4e0a\u624b\u304f\u51e6\u7406\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\uff01<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u4eca\u56de\u4e45\u3057\u3076\u308a\u306b<code>Python<\/code>\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3084\u3063\u3071\u308a<code>Python<\/code>\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3044\u3044\u3067\u3059\u306d\u3002\u305f\u3060\u3001\u305f\u307e\u306b\u3044\u3061\u3044\u3061\u30a4\u30f3\u30c7\u30f3\u30c8\u3092\u52d5\u304b\u3057\u3066\u30c6\u30b9\u30c8\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u90e8\u5206\u306f\u3061\u3087\u3063\u3068\u30fb\u30fb\u30fb\uff08\u6c57\uff09\u3068\u306f\u306a\u308a\u307e\u3059\u3051\u3069\ud83d\ude02<\/p>\n<p>\u307e\u305f\u3001\u5b9f\u306f\u5f53\u521dwindows 10\u3067\u3082\u30c6\u30b9\u30c8\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u969b\u306b\u6642\u9593\u306e\u6d41\u308c\u3092\u611f\u3058\u308b\u8868\u793a\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u305d\u308c\u306f\u3001<strong>\u300cPython 2.7\u306f2020\u5e741\u6708\u3067\u30e1\u30f3\u30c6\u30f3\u30ca\u30f3\u30b9\u671f\u9593\u304c\u7d42\u308f\u308b\u300d<\/strong>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u3068\u306f\u3044\u3048\u3001\u7d50\u69cb<code>Python 2<\/code>\u3063\u3066\u3044\u308d\u3093\u306a\u5834\u6240\u306b\u6df1\u304f\u98df\u3044\u8fbc\u3093\u3067\u308b\u304b\u3089<code>Ubuntu<\/code>\u3068\u304b\u3082\u5168\u9762\u7684\u306b<code>Python 3<\/code>\u306b\u79fb\u884c\u3067\u304d\u308b\u306e\u304b\u3061\u3087\u3063\u3068\u7591\u554f\u3060\u3063\u305f\u308a\u3082\u3057\u307e\u3059\u3002<\/p>\n<p>\u3068\u306b\u3082\u304b\u304f\u306b\u3082\u3001\u4eca\u56de\u306f<code>Pasori<\/code>\u3092\u4f7f\u3063\u3066\u5165\u9000\u5ba4\u30b7\u30b9\u30c6\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u306e\u4fdd\u7ba1\u306b<code>MySQL<\/code>\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30a6\u30a7\u30d6\u3068\u306e\u9023\u643a\u3092\u3057\u305f\u3044\u5834\u5408\u306fAjax\u3067\u4e00\u5b9a\u6642\u9593\u3054\u3068\u306bDB\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3001\u5165\u5ba4\uff0f\u9000\u5ba4\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u304d\u305f\u3089<code>JavaScript<\/code>\u3067\u30da\u30fc\u30b8\u5909\u66f4\u3059\u308b\u3068\u3044\u3046\u6d41\u308c\u306b\u3059\u308c\u3070\u3001\u3088\u308a\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u306b\u8fd1\u3044\u30b7\u30b9\u30c6\u30e0\u7d71\u5408\u304c\u3067\u304d\u308b\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\uff08\u3082\u3057\u304f\u306f<code>Pusher<\/code>\u3068\u304b\u3067\u3059\u306d\uff09<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u3053\u308c\u3067\u307e\u305a\u9593\u9055\u3044\u306a\u304f<code>Pasori<\/code>\u306f\u5c01\u5370\u3067\u3059\u304c\u3001\u3044\u3064\u304b\u304a\u4ed5\u4e8b\u306e\u4f9d\u983c\u304c\u3042\u308b\u3088\u3046\u7948\u3063\u3068\u304d\u307e\u3059\uff08\u7b11\uff09<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-519 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/21.png\" alt=\"\" width=\"192\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/21.png 192w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/05\/21-180x300.png 180w\" sizes=\"auto, (max-width: 192px) 100vw, 192px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u3054\u4f9d\u983c\u304a\u307e\u3061\u3057\u3066\u307e\u3059\ud83d\ude0a\u2728\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u3053\u306e\u3068\u3053\u308d\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u3068\u30ea\u30a2\u30eb\u3092\u878d\u5408\u3055\u305b\u305f\u30b7\u30b9\u30c6\u30e0\u3092\u7d39\u4ecb\u3059\u308b\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u3044\u308b\u6d41\u308c\u3092\u53d7\u3051\u3066\u3001\u307e\u305f\u3072\u3068\u3064\u524d\u304b\u3089\u3084\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u305f\u5185\u5bb9\u3092\u601d\u3044\u51fa\u3057\u307e\u3057 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=4081\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Python\u3011Pasori RC-S380\u3067\u5165\u9000\u5ba4\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":4104,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[160],"class_list":["post-4081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-ic"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4081"}],"version-history":[{"count":10,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4081\/revisions"}],"predecessor-version":[{"id":7215,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4081\/revisions\/7215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/4104"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}