ChipChop Support Forum
Log in
Log out
Join the forum
My Details
REPLIES: 5
VIEWS: 265
BACK
REPLY TO THIS POST
Gizmo
28 Nov 2023
New Component - Lock
This is a new component type that goes hand in hand with the PIN Code.

I have not updated the docs so I am going to give you a quick explanation here so you can use it straight away.

This is a very simple component type and almost no different to ON/OFF except that it accepts values of LOCKED & UNLOCKED

In the Web App it will show as a button with a lock icon.



That's it, you can use it with a PIN Code so when you receive a correct pin change the Lock status and send it over heartbeat to ChipChop.



Attached images
summocoder
21 Dec 2023

So how do you link this with the pin code component?
Gizmo
22 Dec 2023

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
markfelix
25 Dec 2023

doesn't work in the actions, it's not letting me specify a value for the pin code target component => "pin_code" => Value Is
Gizmo
25 Dec 2023

@ markfelix Damnation ☠️! You are right, didn't notice that, I need to update the component definition so the Actions know that it accepts text!

Ok, will do that as soon as I catch my breath, it needs updating in few places so will take a little bit of time and I will have to do a quick restart of the Dev Console server so may be unavailable for 1-2 minutes.
markfelix
26 Dec 2023

lol, no rush, I don't really need it right now I was just playing and noticed the glitch :-)