Before offering bunch of programming advice, the first question is: have you been able to get the initial sketch working? No point attempting to modify something that doesn't work.
Hello guys, thanks for your time. Regarding your questions. Yes it works exactlly like it should. My piezo reads the knocks just fine and does what it suppose to do. When i started a few weeks back I added a second secret knock and i duplicated everything in the script (i added a "1" in the end of each variable or int. For example; secrerknock and secretknock1, listentosecretknock and listentosecretknock1) the problem i had was that when the script started to read, some times it would look for secretknock and sometimes for secretknock1 but it would never listen for both at the same time. So it was pointless. I dont know if it makes any sense what i just wrote. I will try to recreate the script and upload a video. Thanks!
Suppose that you have two patterns, 120221 and 212012, where the 0, 1, and 2 represent interval muliplicands. If you get a duration of 1 times the interval, compare that with the first value in each pattern. Only one matches. If the next value you get is 2, the first pattern is still in contention. If the next value is a 4, that doesn't match the next value in any of the patterns still in contention, so the knock sequence is not one you are supposed to recognize.
However you represent the patterns that are valid knock patterns, you get knocks at some interval that you morph in the same way you morphed the data in the valid knock patterns. The 0 through n morphed values match, or do not match the 0 through n morphed values in the stored patterns.
patduino:
Ok, yeah, I saw that. I'll download your example and let you know what I think.
Just out of curiosity, what's the application for this?
Hey, thanks! I'm pretty sure you've heard of "Knocki" if not, search for it. Its a device that lets you turn any surface into "touch surface" and lets you interact with your smart home. I have a smartthings hub in my house and i have everything automated. I use ifttt or webcore which lets me control my switches etc by using web requests.
I have an esp-8266 with a web request script that works like this:
If
GPIO 0 is HIGH
Then
Send web request (Ifttt url that turns on my lights)
If
GPIO 2 is HIGH
Then
Send web request (Ifttt url that turns off my lights)
if you'd like i can attach the ifttt script.
Bottom line, arduino has a script about knocks if the first secret knock is validated then it turns Pin 6 to HIGH which is connected to ESP'S GPIO 0.
If the SECOND secret knock is validated it turns pin 7 to HIGH which is connected to ESP'S GPIO 2.
P.S i want to create my own because kocki is still a work in progress and idk when is it gonna be available.
Thanks for the info. I'm pretty impressed with the whole SmartThings environment.
It also sounds like you're an IFTTT power user; nice!
At one time, SmartThings offered an Arduino shield, but that hasn't been available for a year+ or so... I was working with a client that had grand plans for them, but -- poof! gone.
Ok... So after looking over your example code, I think the easiest thing will be to leave it essentially as-is, but check the collected knock pattern against both (or more) secret code patterns and return a code associated with the pattern that matches.
patduino:
Ok... So after looking over your example code, I think the easiest thing will be to leave it essentially as-is, but check the collected knock pattern against both (or more) secret code patterns and return a code associated with the pattern that matches.
Hey, i tried a few things with no luck. Anyways thanks for the help!
I looked over the code and realized that it was pretty close to what you needed. For fun... I overachieved and gave you three knock patterns rather than the two you asked for. I also left a few notes in the code to explain how to extend the pattern count to any number -- limited only by the amount of RAM in your Arduino.
At the end of the sketch is a function named validateKnock() that returns a bool indicating whether the knock pattern was accepted. I modified that function to search through an array of potential knock patterns and to return an integer code indicating which pattern was found, or 0 if none.
I also added a few else-if statements to evaluate the returned value and to call the associated function and created a few placeholder functions for you to fill-in with your IFTTT GPIO calls.
NOTE - The code allows you to reprogram the secret knock code. I did not extend this to work with more than just the first pattern in the list since there was only 1 programming button. To reprogram all of them, you'll need to add additional buttons and modify the code to pay attention to which one was pressed.
I looked over the code and realized that it was pretty close to what you needed. For fun... I overachieved and gave you three knock patterns rather than the two you asked for. I also left a few notes in the code to explain how to extend the pattern count to any number -- limited only by the amount of RAM in your Arduino.
At the end of the sketch is a function named validateKnock() that returns a bool indicating whether the knock pattern was accepted. I modified that function to search through an array of potential knock patterns and to return an integer code indicating which pattern was found, or 0 if none.
I also added a few else-if statements to evaluate the returned value and to call the associated function and created a few placeholder functions for you to fill-in with your IFTTT GPIO calls.
NOTE - The code allows you to reprogram the secret knock code. I did not extend this to work with more than just the first pattern in the list since there was only 1 programming button. To reprogram all of them, you'll need to add additional buttons and modify the code to pay attention to which one was pressed.
Enjoy!
Pat.
Sir, YOU ARE THE BEST!!! it worked like a charm. Thank you so much. i will answer in PM too.