ttlock-sdk-js icon indicating copy to clipboard operation
ttlock-sdk-js copied to clipboard

How can it work continuously?

Open nattarat1998 opened this issue 3 years ago • 5 comments

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 BUT in second time,it become false. How can I change value of client.startScanLock() to be TRUE without run file again via terminal

nattarat1998 avatar May 19 '21 10:05 nattarat1998

How to Set all boolean to be default value. please

nattarat1998 avatar May 20 '21 07:05 nattarat1998

Hi, please observe the listen.js example. It runs continuously and reports when lock is locked or unlocked.

kind3r avatar May 24 '21 16:05 kind3r

Thank you for your time and help. It works ! BTW I realize its not need to reset all of boolean.

nattarat1998 avatar May 27 '21 16:05 nattarat1998

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)

kind3r avatar May 27 '21 16:05 kind3r

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"

nattarat1998 avatar May 27 '21 17:05 nattarat1998