Code Monkey home page Code Monkey logo

zkconnect's Introduction

ZKConnect

ZK Connect is a python micro-service designed to work as a client to relay real-time attendance data from ZK Teco devices to an external API. It is designed to run using a service like Supervisor. I wrote it to work alongside with Laravel applications built at my workplace.

Requirements

  • python >= 3.5
  • pyzk == 0.9
  • requests == 2.25.1
  • pyyaml == 5.4.1

Supported Devices

This script uses pyzk library to communicate with devices, hence it should support any device supported by pyzk. However, it is explicitly tested with ZKTeco F18 and K40 models. If you get it working with more devices, let me know.

Usage

Dependency Install

After creating and activating a virtual environment for the script, install the required libraries by running:

pip install -r requirements.txt

Config File

A config.example.yaml file is provided in this repository. Rename/create a new one as config.yaml and fill up following keys:

device:
  host: XXX.XXX.XXX.XXX # your device's ip address
  port: 4370 # usually 4370 is used by most of the devices
endpoint: http://my-app.test/log # a post API route to your app
transmission: true # whether or not to transmit data to API, useful for debugging purpose
log:
  filename: transaction # name of log file
  split: true # splits log file for each day if enabled, else writes into one file

Running

After configuring, you can run python connect.py to start sending realtime attendance log to your application. The request payload is:

{
  "device_user_id": 21,
  "timestamp": "2021-02-17 18:23:00"
}

The server response should contain two keys:

{
  "log": {...}, // the saved object
  "message": "A response message"
}

Note: You should use a service like Supervisor to keep the script running and restarting automatically in case of any exception. An example supervisor config file is also provided.

Debugging

The script keeps all necessary log information within the directory which may come handy for debugging. The log files can be split into several files for each day or can be written into one file. See the Config File section for configuration.

Known Issues

The script can detect any disruption in connectivity and hence exits so that supervisor can rerun the script reconnecting to the device. The reconnection attempt might take a few seconds and during this time nothing will be transmitted.

zkconnect's People

Contributors

sowrensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

zkconnect's Issues

Sync Realtime Attendance from multiple devices

I have a single microservice running and now i have to sync Realtime Attendance in it. The zkconnect connects only a single device is it possible to connect multiple devices with the single microservice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.