Digistump Forums
The Oak by Digistump => Oak Projects => Topic started by: tycen on March 09, 2016, 04:52:35 pm
-
Anyone have any suggestions for a sketch to interact with the Oak via a web interface. I have my Oak up and running and would like to move forward with a project to use it to open/close my garage door (using a relay). I see the ESP projects out there, but I thought I saw something about ESP sketches possibly breaking the Oak (for now). So, the end result I'm looking for is for the Oak to host a web page I can hit from my phone (while on my wifi) where I can toggle a pin on the Oak to activate the relay controlling the garage door.
Any ideas? Thanks!
-
Unless you want to create you own web page to interact with the Oak, why not use Blynk. It offers a variety of widgets including button widgets that can interact with Oak pins (real and virtual). I've only pushed data to Blynk but I think you can easily find an example use of buttons to effect actions on the Oak side.
While Blynk support is not official yet for the Oak, you can get it to work with a simple addition to BlynkSimpleOak.h and the inclusion of SimpleTimer.h.
See this post http://digistump.com/board/index.php/topic,2069.0.html (http://digistump.com/board/index.php/topic,2069.0.html) for details. If you need more clarity on how to mod BlynkSimleOak.h just shout out. But basically if you take a look at the .h file it may be obvious.
My Blynker (sic) monitors pool temp and pushes temp data to a gauge widget and messages to a virtual LCD like "Come on in the water is fine" or "Polar Bear Club Only!". You need to sign up for a Blynk account (download the app to your phone) and get an auth token to link the Oak to the Blynk app.
-
UPDATE: to last post. You don't need SimpleTimer.h. It's only used for periodically firing of a function in a sketch. It's not needed for a Blynk button widget controlling one of the Oak real pins.
What ever pin you control the relay from would be specified in the Blynk app button widget.
Your code could be as simple as this.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleOak>
char auth[] = "YOURAUTHCODE";
void setup()
{
Serial.begin(9600); // Only if using serial output
delay(5000);
Blynk.begin(auth);
}
void loop()
{
Blynk.run();
}
-
OK... If you would like to use Blynk and have an access code required to open your garage, here is an example I put together using button and LCD widgets on virtual pins. The buttons are on V1, V2, V3, V4 and represent digits 1 to 4 respectively. The LCD widget in on virtual pin 5 (V5). You will need to create the corresponding project with widgets on Blynk, 4 buttons, 1 LCD.
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example runs directly on Oaks.
*
* Please be sure to select Oak
* in the Tools -> Board menu!
*
* Change Blynk auth token to run :)
*
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleOak.h>
//#include <SimpleTimer.h>
WidgetLCD lcd(V5); // Blynk LCD widget
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YOURAUTHTOKENGOESHERE";
int accessCODE[4] = {1,4,1,3}; // Modifiy to your liking and/or increase number of digits
int accessINPUT[4];
int digit = 0;
int OakLEDpin = 1; // Oak onboard LED pin 1
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
if (param.asInt()==1) {
lcd.print(digit,1, "*");
accessINPUT[digit++] = 1;
digit = digit % 4;
if (digit == 0)
checkAccess();
}
}
BLYNK_WRITE(V2) //Button Widget is writing to pin V2
{
if (param.asInt()==1) {
lcd.print(digit,1, "*");
accessINPUT[digit++] = 2;
digit = digit % 4;
if (digit == 0)
checkAccess();
}
}
BLYNK_WRITE(V3) //Button Widget is writing to pin V3
{
if (param.asInt()==1) {
lcd.print(digit,1, "*");
accessINPUT[digit++] = 3;
digit = digit % 4;
if (digit == 0)
checkAccess();
}
}
BLYNK_WRITE(V4) //Button Widget is writing to pin V4
{
if (param.asInt()==1) {
lcd.print(digit,1, "*");
accessINPUT[digit++] = 4;
digit = digit % 4;
if (digit == 0)
checkAccess();
}
}
void checkAccess() {
for(int i=0; i<4; i++) {
if (accessINPUT[i] != accessCODE[i]) {
lcd.print(0,0, "NO CIGAR!");
lcd.print(0,1, " ");
digitalWrite(OakLEDpin,LOW);
return;
}
}
lcd.print(0,0, "Winner! ");
lcd.print(0,1, " ");
// Do something
digitalWrite(OakLEDpin,HIGH);
return;
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(OakLEDpin, OUTPUT);
digitalWrite(OakLEDpin,LOW);
}
void loop() {
Blynk.run();
}
-
With regard to the last post... here is what your Blynk app could look like. Again the buttons are on V1, V2, V3, V4 and represent the digits 1 - 4 respectively. The LCD widget is on virtual pin V5.
-
exeng - that is some great info! Thanks for taking the time. I had thought about Blynk (I was even a backer for their Kickstarter before Oak partnered with them). I'll play around with it and let you know.
The Blynk route will definitely work in the short term. However, I want it to be web based eventually for the following reasons:
- I want my wife to be able to use and I don't think she'd be interested in me installing Blynk on her phone
- I want to be able to open/close it remotely (via home VPN). Blynk is only local connections - right? Or maybe not.
But yeah, Blynk might definitely get me what I need in the interim. Thanks again!
-
Haven't tested it but I believe that if your Oak is connected to the internet, you should be able to access it remotely via Blynk connected wireless or cellular. That is if you are out and about you should be able to login to Blynk over the cell network. Blynk will know if your Oak is connected.
You could even add a sensor to indicate whether or not your garage door is open.
-
OK... Tested it and as long as your Oak is internet connected you can login to Blynk from anywhere and control the Oak. Doesn't matter if you get to Blynk on a wireless net or cellular. The downside is you have to be logged in to Blynk to use it. And... it's yet another app on your phone that wants access to files and camera.
Have fun and let us know how it works out for you. You got me thinking about doing the same with an added open close sensor and possibly an RTC that alerts me if it's open in the evening or for unusually long periods of time. Heck, I once went on vacation and left the garage open. My good neighbor tried to close it from in the garage but kept tripping the safety beam on the way out. He ended up nailing the thing shut and covering the block of wood (temp lock) with my trash cans.
-
Thanks for testing it out. Sorry if I missed it, but where do I get BlynkSimpleOak.h?
When I compile I get "fatal error: BlynkSimpleOak.h: No such file or directory"
-
It lives here on my Windows system:
C:\Users\Stephen\AppData\Roaming\Arduino15\packages\digistump\hardware\oak\0.9.5\libraries\Blynk
Basically, it should have been installed with the 0.9.5 repo
You'll have to make the addition to the BlynkSimpleOak.h file that I described in a prior post which is...
Add this to your local copy...
// ADDED for Oak (by exeng) - similar to above but without args to connectWiFi()
void connectWiFi()
{
BLYNK_LOG("Oak in connect WiFi");
WiFi.begin(); // Oak is already has a configured SSID to connect to
while (WiFi.status() != WL_CONNECTED) {
::delay(10000); // delay 10 seconds
}
BLYNK_LOG("Connected to WiFi");
IPAddress myip = WiFi.localIP();
BLYNK_LOG("My IP: %d.%d.%d.%d", myip[0], myip[1], myip[2], myip[3]);
}
// END of ADDED for Oak (by exeng)
After these lines in the BlynkWifi class:
class BlynkWifi
: public BlynkProtocol<BlynkArduinoClient>
{
typedef BlynkProtocol<BlynkArduinoClient> Base;
public:
BlynkWifi(BlynkArduinoClient& transp)
: Base(transp)
{}
void connectWiFi(const char* ssid, const char* pass)
{
/*BLYNK_LOG("Connecting to %s", ssid);
if (pass && strlen(pass)) {
WiFi.begin(ssid, pass);
} else {
WiFi.begin(ssid);
}*/
while (WiFi.status() != WL_CONNECTED) {
::delay(500);
}
BLYNK_LOG("Connected to WiFi");
IPAddress myip = WiFi.localIP();
BLYNK_LOG("My IP: %d.%d.%d.%d", myip[0], myip[1], myip[2], myip[3]);
}
Basically the repo version was complaining about no matching function for connectWiFI() and I increased the delay in the while loop to 10 seconds.
Hope this helps.
-
Weird, I see the file (I'm on Mac, but I can find it in the corresponding location), but it's not showing up in my libraries in the IDE and the compiling still fails.
I'll have to dig into it more later. I also see I have 0.9.2 in there, which I thought I hadn't installed and thought I recalled there being something bad about that - so I'll have to dig into that as well.
Thanks again for the help - I'll get that issue worked out and then try it out.
-
I don't think 0.9.2 has the Blynk library in it and is also missing some others that are in 0.9.5. I moved that old repos out to a save directory and did the Boards Manager install for Oak to get the 0.9.5 installed. You can't just drop it in the directory (as I found out). It only showed up after the formal Board Manager install in the IDE.
-
Just a heads up... Blynk will charge for widgets at some point. See my Blynk post here: http://digistump.com/board/index.php/topic,2069.msg9481.html#msg9481 (http://digistump.com/board/index.php/topic,2069.msg9481.html#msg9481)
-
exeng - you're awesome! It's totally working. I didn't realize you were putting an access code on there, too. Very clever. I think I finally figured out my problem with BlynkSimpleOak.h - I had edited it in TextWrangler and I think that changed the permission on it (although the looked good on the command line. So, I blew away my Arduino installation and libraries and reinstalled everything and then edited that file via command line. Everything's working now and this will be a great solution for getting what I need for now.
I was a Blynk Kickstarter backer (basic level, I think) so I should be good with keeping the basic widgets at least.
So many projects are coming to mind now...
Thanks again for helping me get an early jump on using this!
-
Can I bug you with one more question? I tried looking for the answer myself, but am not having much luck (still new to Blynk).
If I wanted to take out the access code and just have a single button for actuating the relay - what would that look like?
Another random question - my LCD in my Blynk app has Chinese characters on the bottom - I noticed yours does too in your screenshot. Any idea what that's about?
-
If you want to have Blynk toggle a real pin, I think the dead simple example I posted earlier would work. http://digistump.com/board/index.php/topic,2073.msg9464.html#msg9464 (http://digistump.com/board/index.php/topic,2073.msg9464.html#msg9464)
Basically when you add the button widget just spec which digital pin you want to connect it to. With the above code the pin should go high when you press the button. I'm not at my system so I can't test it. Alternatively, you could strip the current example down to one button (using the virtual pin V1) and read whether you are getting a 1 or 0 (you'll get 1 when button the is pressed) and pulse stretch a digitalWrite(pin,HIGH) for the relay control pin. You could do a simple test using the onboard LED pin 1.
If you poke around on the internet for Blynk examples you may find an example or tutorial for controlling a real pin.
Yes I saw the characters on the LCD. Can't read it, so I don't know what's there. Perhaps the name of the widget creator or the LCD brand???
-
@tycen, You inspired me to pursue this with your initial post re: wanting to use that Oak as a remote garage opener. You have created a monster...
Decided to put my example Blynk access code example and 1 Oak to good use and have been putting together a home grown shield to open the garage remotely, sense light, and sense open or closed states. Much to the bane of my lovely wife, I've been building a prototype that can now be tested. And yes, it does open and close the garage door. Need to add the sensors (reed switches) and figure out how I can utilize the light sensing. So here is the tease... A photo of the prototype shield. Perhaps someday I will share, once tested and complete.
For now, enjoy my "Blynk"ing garage door opener.
-
That looks great! I had to set the project aside for a few weeks, but just yesterday and today have been thinking about it more. I actually have a relay shield for the Digispark Pro that I am going to use - I just need to solder the three pin header on my Oak but haven't had a chance to do that yet. I also just sent off some PCB's to OSH Park for a temp monitor I want to do for my freezer and extra fridge in the garage.
I'm hoping to get the garage door opener project kicked back into gear here in the next few days. I like your idea of sensing the state of the door with reed switches - I'll need to plan for something like that, too - I also have inadvertently left the garage door open all night.
Thanks for the update - I'll share mine when I have it - hopefully soon.
-
UPDATE: Well I got bit by pins 0 and 2 again. Was going to use these for reed switch inputs but it looks like I will need to have a pull-down resistor on the sensor inputs for the door open and closed switches to ensure they return to ground when they are open. Since pull downs are a no no on these pins, I get to rework the board at least one more time. Light sensing is working. Just need to translate it into something meaningful like day/night or lights on/off. For example, it's dark and your door is open. Well I'll just close it then.
-
I like the light sensing idea. How are you going to account for the light from the garage light?
A future project I have on my list is an auto door open/close for my chicken coop (based on light from sunrise/sunset). The Oak/Arduino part of that is easy enough - the hard part is getting the motor setup and power to the coop.
So many projects...so few power outlets where you need them...
-
The light sensor logic does not distinguish between lights on and daylight. I have 2 auto close timeouts. Dark timeout is the short one. Quite often I forget that I left the door open at night. Daylight timeout is the long one (can be fooled by lights on). I guess could add an RTC for time of day input.
BTW, move the door sensing inputs to pins 9, 10 so that I can use a pull-down to ground. Only using the closed sensor right now.
Code is evolving as testing continues.
-
Just wanted to say thanks for the info in this thread! I've been able to use blynk now to read a temp sensor and toggle a pin on the oak. Thanks!
-
Just a heads up on Blynk... Looks like they are finally starting to charge for Widgets. There is a Blynk thread here http://digistump.com/board/index.php/topic,2069.msg9887.html#msg9887 (http://digistump.com/board/index.php/topic,2069.msg9887.html#msg9887) that has started to talk about this. Don't know how this will effect users with the app already installed. My Widget Box seems to have a variety of widgets available to use at no cost. Don't know if this will change for those that already have the app installed.
-
Indeed Blynk turned on in App purchases and is giving free accounts only 2000 Energy units, enough to start at least one project.
If you bought the OAK BLYNK on Kickstarter you should have email to get your reward and that credits you 100,000 Energy units.
more notes here: http://digistump.com/board/index.php/topic,2069.msg9894.html#msg9894 (http://digistump.com/board/index.php/topic,2069.msg9894.html#msg9894)
-
@exeng - I finally got mine installed. I forgot that I had ordered the Oak Relay Shield - so I soldered that up and worked out the final bit of code - now I have a simple remote garage door opener. I hope to add some sensors to it later, but for now at least it's opening/closing.
Sidenote: I haven't updated my Blynk app yet, but since I was a Kickstarter backer of their original project I already got my email telling me I'll never run out of energy. I'm interested to see how that will work. I don't blame them - they gotta make money to keep the lights on. I think I'd be happy to pay if I had to (within reason) - such an incredibly useful app already - and I haven't even done any projects yet beyond this door opener.
Sidenote 2: the Oak Relay shield is poorly designed (and I say that as someone who really likes Erik and his projects - I was a backer for Digispark and Digispark Pro). The shield only has one side of the Oak pins - but is just big enough to effectively block the other side of the board from even using jumper wires. I guess I'm glad he focused more on getting the project out the door - but I just wanted to mention it for others. I'm going to see if he's posted the Eagle files for the shield so I can see if I can make it smaller to open up the blocked pins for jumper wires or just widen it a bit and bring the second row of pins up to the shield.
Here's the code I ended up with:
/* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example runs directly on Oaks.
*
* Please be sure to select Oak
* in the Tools -> Board menu!
*
* Change Blynk auth token to run :)
*
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleOak.h>
//#include <SimpleTimer.h>
WidgetLCD lcd(V5); // Blynk LCD widget
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AUTHTOKENHERE";
int OakLEDpin = 1; // Oak onboard LED pin 1
int Relaypin = 5; // relay on pin 5
BLYNK_WRITE(V1) //Button Widget is writing to pin V1
{
if (param.asInt()==1)
{
lcd.print(0,0, "You Shall Pass! ");
lcd.print(0,1, " ");
digitalWrite(OakLEDpin, HIGH);
digitalWrite(Relaypin, HIGH);
delay(500);
digitalWrite(OakLEDpin, LOW);
digitalWrite(Relaypin, LOW);
lcd.print(0,0, "You Shall Pass! ");
lcd.print(0,1, " DONE! ");
}
else
{
lcd.print(0,0, " Waiting... ");
lcd.print(0,1, " ");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(OakLEDpin, OUTPUT);
digitalWrite(OakLEDpin, LOW);
pinMode(Relaypin, OUTPUT);
digitalWrite(Relaypin, LOW);
}
void loop() {
Blynk.run();
}
And attached are some pictures (of really nothing more than an Oak and an Oak relay shield).
Thanks again for the help on getting started with Blynk/Oak!
-
@tycen, Away today but when I return I will share my schematic and code. It's a work in progress.
-
I just finished testing my version that uses IFTTT.
It uses an Oak, a Relay module, and two window/door sensors to give feedback on if the garage door is open or closed.
I have set up a DO button that lets me toggle the garage door open or closed, and I set up a recipe that works off my iPhone so that when I drive up to my house the door automatically opens.
I have set up three variables, one to tell me how many times the door has been opened or closed, and a variable to let me see if the garage door is open or closed that's connected to the two door sensors.
I put it up last night and got it working, still have to install the door sensors tonight.
I'll post the schematics, and links to the recipes I use (with the tokens removed :) ) and the url's I use to read the door status and how many times it's been opened.