Run Sesame on Sony's PaSoRi (RCS370)

background

The day of the 2nd "Let's make something using each person in the laboratory for one day!" Articles of other members are here. The first article of mine is here.

Sesame is attached to the key of the laboratory, but it is very troublesome to open and operate the application on the mobile phone every time it is opened and closed. I wish I could open it with Suica or Felica from Apple pay.

The image is like this. image.png

The image is from the article here. Thank you very much.

Advance preparation

https://www.otwo.jp/blog/raspi_sesame_1/ http://www.otwo.jp/blog/raspi_sesame_2/ See this area.

--Raspberry Pi: The guy who was lying in the lab (probably Raspberry Pi3). --Sesame: Installed at the entrance of the laboratory. --NFC Reader: RCS370. Borrowing the personal belongings of the teacher in the laboratory (why do you have it ...)

I tried it with Raspberry Pi (failure)

nfcpy: 1.0.3 python2: 2.7.16 python3: 3.7.3

Install nfcpy with pip. It was said that it also supports python3, so the policy is to use python3.

$ pip3 install nfcpy

At the same time clone the source from github. ʻTry running examples / tagtool.py`.

$ python3 tagtool.py
[nfc.clf] searching for reader on path usb
[nfc.clf] no reader available on path usb
[main] no contactless reader found on usb
[main] no contactless reader available

I get an error.

Check Official Documents or Qiita Articles It seems that you need to specify the USB path using the device ID. If you look it up with lsusb,

$ lsusb
(abridgement)
Bus 001 Device 025: ID 054c:02e1 Sony Corp. FeliCa S330 [PaSoRi]
(abridgement)

The device ID is displayed. I'm worried that it's 330 instead of 370, but it seems that the driver used is the same, so it's okay.

Specify the USB path and try running.

$ python3 tagtool.py
[nfc.clf] searching for reader on path usb:054c:02e1
[nfc.clf.rcs956] input/output error while waiting for ack
[main] no contactless reader available

That? After a lot of research, it seems that I haven't been able to communicate well with the device with the specified path ...

Try various things

Work resumed after a pizza break. In the first place, there is no example of success with RCS370 & Raspberry Pi & nfcpy. I started this article and changed 370 to 380 and it worked! The system is here and there ...

Although the tension dropped, I didn't want to give up yet, so I drank Monster and continued the investigation.

This article uses Debian and RCS370. You can check if nfcpy is installed properly with python -m nfc in the first place. I will try it for the time being.

This is the 1.0.3 version of nfcpy run in Python 3.7.3
on Linux-4.19.57-v7+-armv7l-with-debian-10.0
I'm now searching your system for contactless devices
ERROR:nfc.clf.rcs956:input/output error while waiting for ack
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs
Sorry, but I couldn't find any contactless device

I get an input / output error. Even if the versions of python and nfcpy were combined with the reference article, it did not change.

The content of the error is the same as this article. Hmm ...

I tried various versions of nfcpy and python, but I still can't ... This is a mess ...

My conclusion

RCS370 & Raspberry Pi & nfcpy doesn't work!

Raspberry Pi recognizes that the RCS370 is plugged into the USB port. Well, you can use RCS380.

I tried it on a MacBook Air (success)

nfcpy: 1.0.3 python3: 3.6.5

Still, I didn't want to give up, so I decided to try it on my personal computer (MacBook Air).

Similarly, clone nfcpy and run ʻexamples / tagtool.py`.

[nfc.clf] searching for reader on path usb
[nfc.clf] using Sony RC-S370/P RCS956v1.30 at usb:020:018
** waiting for a tag **
Type3Tag 'FeliCa Standard (RC-S???)' ID=Card ID(abridgement)

I was able to go.

Connection with Sesame

[Official article](https://jp.candyhouse.co/blogs/how-to/suica%E3%81%A7%E3%82%BB%E3%82%B5%E3%83%9F%E3% 82% 92% E8% A7% A3% E9% 8C% A0-with-% E3% 83% A9% E3% 82% BA% E3% 83% 91% E3% 82% A4). I wanted to use Python3, so I play around with it.

nfc_card.py


# -*- coding: utf-8 -*-
import requests
import json
import binascii
import nfc
import time
from threading import Thread, Timer

# login CANDY HOUSE account and get token
url = "https://api.candyhouse.co/v1/accounts/login"
head = {"Content-type": "application/json"}
payload = {"email":"Account email address", "password":"Account password"}
response = requests.post(url, headers=head, data=json.dumps(payload))
token = response.json()["authorization"]

#Suica standby 1 cycle second
TIME_cycle = 1.0
#Suica standby reaction interval seconds
TIME_interval = 0.2
#Seconds to disable from touch to start the next standby
TIME_wait = 3

#Preparation for NFC connection request
# 212F(FeliCa)Set with
target_req_suica = nfc.clf.RemoteTarget("212F")
# 0003(Suica)
target_req_suica.sensf_req = bytearray.fromhex("0000030000")

print('Waiting for SUICA...')
while True:
    #Instantiate by connecting to an NFC reader connected to USB
    clf = nfc.ContactlessFrontend('usb')
    #Suica standby start
    # clf.sense( [Remote target], [Number of searches], [Search interval] )
    target_res = clf.sense(target_req_suica, iterations=int(TIME_cycle//TIME_interval)+1 , interval=TIME_interval)

    if target_res is not None: # != ->Change to is not

        #tag = nfc.tag.tt3.Type3Tag(clf, target_res)
        #It seems that the specifications have changed. ↓ then it worked
        tag = nfc.tag.activate_tt3(clf, target_res)
        tag.sys = 3

        #Take out IDm
        idm = binascii.hexlify(tag.idm)
        print('Suica detected. idm = ' + str(idm))

        if (idm == b'IC ID'):
            headers = {'X-Authorization':token,}
            response = requests.get('https://api.candyhouse.co/v1/sesames/Sesame serial number', headers=headers)

            status = response.json()["is_unlocked"]

            url_control = "https://api.candyhouse.co/v1/sesames/Sesame serial number/control"
            head_control = {"X-Authorization": token, "Content-type": "application/json"}

            #Close when open, open when closed
            if status:
                payload_control = {"type":"lock"}
            else:
                payload_control = {"type":"unlock"}

            response_control = requests.post(url_control, headers=head_control, data=json.dumps(payload_control))

            print(response_control.text)

        print('sleep ' + str(TIME_wait) + ' seconds')
        time.sleep(TIME_wait)
    #end if

    clf.close()

#end while

With the serial number, SESAME ID ([this](https://jp.candyhouse.co/blogs/how-to/api%E3%82%AD%E3%83%BC%E5%8F%96%E5%BE] % 97% E6% 96% B9% E6% B3% 95% E3% 81% A8% E3% 82% BB% E3% 82% B5% E3% 83% 9Fid% E3% 81% AE% E7% A2% BA Note that it is not% E8% AA% 8D% E6% 96% B9% E6% B3% 95)). I couldn't hit the API because I used SESAME ID here, so I spent about 30 minutes wasting time ...

Try using

--Inside the door inside

Lol Well, this time it can't be helped.

--Outside the door outside

Attach the NFC reader from the inside with cellophane tape (sorry for the teacher) and check if it can be opened with an IC card from the outside.

…open! However, it takes about 3 to 5 seconds after touching. Still "Remove mobile phone-> unlock-> open Sesame app-> wait for connection-> tap" Faster and easier! Goodness.

Mobile Suica installed in iPhone X also responds properly. But is it a little less responsive than an IC card?

Impressions and future

I thought it would be smooth, but it didn't. When communication and hardware are involved, the difficulty level rises a little. But I am satisfied that the laboratory will be more convenient.

Then I ordered the RCS380. Lol It seems that it will arrive soon, so I will mount it and attach it to the door. If it works with 380, I will write it again.

I want to meet this meeting about once a month. What will we make next?

Recommended Posts

Run Sesame on Sony's PaSoRi (RCS370)
Run Django on PythonAnywhere
Run mysqlclient on Lambda
Run OpenMVG on Mac
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Run Tensorflow 2.x on Python 3.7
Run unix command on python
Run IPython Notebook on Docker
Run YOLO v3 on AWS v2
Run CircuitPython on Seeeduino XIAO
Run FreeBSD on Linux + qemu
Run OpenVino on macOS Catalina
Run YOLO v3 on AWS