deviceJS Control
This is the deviceJS part. It shares common knowledge with Node.js which provides us some useful module.
We create a TCP server in Ubuntu and it will listen to a designated port and wait for clients being active. Next, we bind the client script with the facial recognition. If the confidence exceeds the threshold, the return value is none and invalid. Otherwise, it would return a valid id and trigger the initiation of the client. Lastly, the server sends back a “Welcome” message and lights on the filament for 5 seconds representing the successful recognition of that particular person.
Fig.1. Diagram for deviceJS control
The most challenging one in this part is probably the communication between computer and virtual machine. Though in the same Local Area Network, the VM seems to have an entirely different private IP address with the host machine, meaning it is on a different subnet. We can access the network because my host is doing Network Address Translation. The IP is assigned by a DHCP running on the host. We solved it by using “Bridge connection” instead of NAT in the network configuration. With a bridged interface virtual machine will be directly connected to the network our host connects to, getting IP addresses from the DHCP server running on the network.
Meanwhile, the server should better listen to 0.0.0.0 rather than 127.0.0.1. When a server is told to listen on all-zero address, it means "listen on every available network interface".