ttlock-sdk-js
ttlock-sdk-js copied to clipboard
How can it work continuously?
I order ttlock via MQTT and run file continuously. (without process.exit(code)) I have problem about scanning lock in second time. I try to console.log(await client.startScanLock()). in first time,it return boolean
How to Set all boolean to be default value. please
Hi, please observe the listen.js example. It runs continuously and reports when lock is locked or unlocked.
Thank you for your time and help. It works ! BTW I realize its not need to reset all of boolean.
I'm not sure what booleans you are reffering to.
The whole SDK is event based and the basic process is:
- most of the actions are Promises as they are async operations
- client scan for locks:
startScanLock
does an active BLE scan,startMonitor
does passive BLE scan and only listens for advertisments (this is actually enough most times as the lock does not seem to actually reply to active scans and it just broadcasts when it wants) - client events are fired when a lock is found, you should store the lock object in order to further interact with that lock
- lock events are fired when the lock changes parameters (like when it is locked or unlocked, battery level changes, lock is connected/disconnected etc.)
- you cannot directly connect to a lock until it is found by a scan (this is a limitation of the BLE framework)
According to your example, you use process.exit(0). So the program will exit when TTLock function is done, but my purpose is able to control TTLock repeatedly without process.exit(0) I tried to command TTLock to unlock/lock/etc. At first, It worked. but the second round, It stucked with the client.startScanLock() and not foundLock by a scan. I console.log the value of client.startScanLock(). It was false. It should be TRUE. thus I opened this issue to ask you about this problem. Nevertheless I have already read all of your code and found the way to solve the problem. When I commanded TTLock in the second round, startNobleScan() in NobleScanner.js did not work because nobleState != "poweredOn"