VisualHMI phased application (customized): dynamic password Lua metatable solution

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

The system installment is "locked before expiration", while the custom installment is "locked upon expiration" - this is more in line with real-life leasing scenarios. This article is encapsulated using Lua metatables to achieve precise timing triggering + dynamic passwords (the algorithm is externalized, without pre-stored static passwords).

1. Differences between the two schemes

DimensionsSystem scheme (pre-locked)Custom scheme (locked upon expiration)
Trigger timingTakes effect immediately after configurationLocks only when current time ≥ deadline
User perceptionLocked in advanceLocked just upon expiration

2. Design points

  • Dynamic Password: calculated in real-time by the external function password_func(date) (such as year + month + day), not pre-stored, to prevent reverse engineering
  • Super Password: a single uint32, one-click global unlock, with on-site operation and maintenance as a backup
  • Self-checking Hot Update: initiates detection of date changes, automatically rewrites and stores after configuration modifications
  • State Persistence: time/switch/unlock progress stored in VT_RW non-volatile area, not lost during power loss

3. Instantiation (main.lua)

Stage.new(base_addr, stage_dates, password_func, super_password):

-- base_addr: VT_RW 起始地址,连续存储所有配置
-- stage_dates: 3期截止日期列表,必须递增
-- password_func: 密码计算函数
-- super_password: 超级密码
dofile("stage.lua")
g_stage = Stage.new(0x1000,
  {{2023,11,1},{2023,12,1},{2024,1,1}},
  function(d) return d[1]+d[2]+d[3] end,
  123456)

The module is implemented using closures + metatables OO, supporting 1~10 stages, with states fully stored in the RW area. The core decision-making function get_eligible_stage() strictly compares system time with the deadline, and only locks the screen if now ≥ deadline.

VisualHMI phased application (customized): dynamic password Lua metatable solution插图

Customized staging is more flexible than system staging, at the cost of having to write your own Lua module (stage.lua).Dynamic password is not pre-stored—— The password is generated and discarded immediately. Even if someone dumps the RW area, they can only see the result of a certain period, and cannot reverse engineer the algorithm. The state must be stored in the RW area, otherwise the unlock progress will be lost upon restart.

Compiled from Guangzhou Dacai Technology VisualHMI development documentation (hmi-doc.gz-dc.com) and other technical tutorials "Staged Application (RW-Custom)", copyright belongs to Dacai Technology.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.