Config module

import config

The device can be configured via WEB interface (v 2.0), CAN-commands and/or by placing custom settings.cfg file in the root directory of the internal flash storage.

CAN commands

Command Reply Description
~I ~Ix.x Query the firmware version
~A<dec> ~A<dec> Set the device CAN ID (default is 66 - 0x42)
~D<dec> ~D<dec> Set the partner CAN ID (default is 1 - 0x01)
~R ~R500 Reset the device in 500ms

Settings class

Attention, instead of creating a new instance, which will most likely break things, use the global instance from the config module

from config import settings

(When editing the settings.cfg file, either in a built-in editor or by mounting the flash storage, pay attention that all the keys listed below are present and have the appropriate values. No key-value checking will be performed.)

Key Description Default
iptype IP address type ('DHCP' or 'Static', case-sensitive). DHCP
ip Static IP address (ex: 192.168.0.1). Applied only if 'iptype==Static'. 10.10.0.1
ip_start, ip_end If "x.x.x.x" is the DHCP server address (the ip parameter), DCHP clients will be given address from "x.x.x." to "x.x.x.". 2 and 16
src CAN ID from the device-originating messages 0x42
dst Device will only accept the messages with this CAN ID 0x01
baud CAN baudrate. Must be one of 10, 20, 50, 100, 125, 250, 500, 1000 500
format RFID data format string. Ref. format description hU*
protocol Socket protocol to be used for RFID data transmission ('UDP', 'TCP', 'CAN'. used only in the usercode). UDP
dest RFID data destination IP. 10.10.0.2
dport RFID data destination port. 5555
keytype Mifare Classic key type ('A' or 'B'), Mifare Ultralight Password ('UL'), or Mifare Plus password ('PL'). A
key Mifare Classic key (6 bytes - 12 hex digits), Mifare Ultralight Password (4 bytes - 8 hex digits), or Mifare Plus password (16 bytes - 32 hex digits). FFFFFFFFFFFF
lang Web interface language ('en', 'ru', or 'auto'). auto
wdt Enable/Disable watchdog, boolean. True
editor Enable/Disable the user-code editor in the web interface, boolean. True
dash Enable/Disable the dashboard in the web interface, boolean. True
web_auth Enable/Disable the web interface authentication, boolean. False
web_pwd web interface password. (empty)
set_auth Enable/Disable settings access authentication in the web interface. False
set_pwd settings access password. (empty)
info_t system state report interval in seconds. 10

In case of a network configuration error, the module becomes a DHCP server with the address '10.10.0.1' and the client addresses range '10.10.0.2' to '10.10.0.16'

Dict-like interface

getitem

def __getitem__(self, key)

ex: settings['lang']

Returns the current value associated with key. Attention: unlike the correponding dict class method, this one searches the key in the current settings, then fallbacks to the default settings, and should that fail, returns None. The KeyError is not thrown.

setitem

def __setitem__(self, key, value)

ex: settings['lang'] = 'en'

Write to flash

def write(self)

Write the current settings to the flash memory

Get value

def get(self, key, fallback=None)

Get the value associated with key. If the value is not found, fallback value is returned.

Set value

def set(self, key, value)

Set the value for the key.

Reset to the default values

def defaults(self)

Dump the current settings and fill them with the default values.

Global Database Instance

from config import udb

Refer to the Database class description.

TimeKeeper

This class keeps track of time. Use the global tkeep instance instead of creating new instances.

from config import tkeep

Reinit

def reinit(self)

Call this function if the RTC clock has been reconfigured or adjusted. This function is called internally whenever needed. Do not call it manually

Get time

def time(self, isbin=False)

Return the current datetime as an epoch value (isbin==True) or as a string 'yyyy.mm.dd HH:MM:SS' (isbin==False)

Uptime

def uptime(self, isbin=False)

Return the time passed since the system startup.

Logger class

Attention, instead of creating a new instance, which will most likely break things, use the global instance from the config module

Append data to the log

async def push(self, data)
  • data - data ot be logged (str or dict)