There's nothing to link really, it's either to be used as you would to turn something ON/OFF or to view the status of the lock.
So, if you have made some sort of lock and you want to unlock it remotely you would simply press the button in the WebApp and that would send a command to the device as UNLOCKED or LOCKED and then you would maybe send a HIGH/LOW on the lock pin.
You would also send the lock status through the heartbeat so you can see it's state.
Here are few scenarios and also using it with the Pin Code component
1. Autolock on timer idea
When you receive the command in your Arduino code you can let's say do the unlocking and immediately send a "trigger event" for that component so you know immediately that the device is "unlocked" then you could start a timer (i.e. 30 sec) and then do the locking and again send a trigger event so you can see that in the Web App
2. Using with a Pin Code component
In your code you set the [bb]ChipChop_onCommandReceived[bb] callback to listen for commands on the Pin Code component
When you receive a correct value from the Pin Code, you unlock and send that as a ChipChop.triggerEvent("lock","UNLOCKED") and then again maybe implement a timer to autolock
3. Using Actions
You can theoretically use Actions to validate the pin code, wouldn't be the most practical way but would work for a small number of pin codes so you don't have to reprogram your device every time you change the pin.
- Let's say you create a device called "Entrance Door" with a "lock" and "pin_code" components. Create an Action and choose as trigger the "Entrance Door" and trigger component "pin_code".
- Then enter in the "Value is" what would be a valid pin i.e. (123456)
- As a target select the same Entrance Door device and Target Component select "lock"
- Now, as we are sending a command to itself (not a different device) we can only use the option "ENTIRE DEVICE" but that should be ok just select "As Text" and type "UNLOCKED"
- On the device side you would simply do something like this
void ChipChop_onCommandReceived(String target_component,String command_value, String command_source, int command_age){
if(target_component == "any"){ // you would get "any" because we have used "ENTIRE DEVICE" as a target in the Action
if(command_value == "UNLOCKED"){
/// call some function to unlock the door like
digitalWrite(lock_pin,LOW);
ChipChop.triggerEvent("lock","UNLOCKED"); //update the lock status immediately so you have a visual feedback in the Web App
}
}
}
That's just some ideas how it can be used