REHolt / Garage-Door-Controller

ESP8266 Garage Door opener with Android App
GNU General Public License v3.0
5 stars 1 forks source link

unable to compile #3

Closed angipp01 closed 8 years ago

angipp01 commented 8 years ago

screenshots.pdf Yesterday with the old file I get no errors, but with this file I get errors.

angipp01 commented 8 years ago

Also I get this red message on the top of screenshots.pdf screen all the time. I even happened with the old .aia file.

REHolt commented 8 years ago

I have been trying to take a look, but App Inventor is not working correctly on my tablet today. As soon as I get home I will see if I can find the problem. Sorry for the problems and the delay. As I said before, this is my first Android app, so there has been a bit of a learning curve. I have most of the next version (with configuration page) working but still having problems. I thought the one on github was working when I uploaded it. Since I have several versions, I could a configuration management issue.

I try to get it straightened out shortly.

REHolt commented 8 years ago

From the error in you PDF it looks like you may need to reload the file. There may have been an error in the upload. I was trying to upload the github version to app inventor so I could be sure of what I posted. Just can't get it to work right now. I'll try again when I get home.

REHolt commented 8 years ago

OK, you were right, it wouldn't compile. I just uploaded the fixed file. It was a "Configuration Management" issue. I uploaded the file I was working on.

angipp01 commented 8 years ago

Ok now Press the Power icon on/off I get the correct status depending on the magnetic switch (good works). Currently I only have one switch (need to buy another one) and it is connected to D5. MY relay is connected to D4.

Issue: I know the relay is working because once it is connected to D4, it triggers. But why doesn't the App trigger this? With your original and newer verison of App, the relays never trigger. It should trigger it without any involvement of the status of the Switches.

This might be my last piece of the puzzle.

REHolt commented 8 years ago

Unless you modified the program D5 is set as an input and has the interrupt attached. You will need to set it as an output . Most of my I/O was set-up using variables to define the pin number. This has the advantage of only needing to change the number in the variable declare statement and not chase it all over the file. Unfortunately, I didn't do that with the relay pin. That means you will have to change all of the relay write statements to be pin 5.

Never MInd, I miss-read your question

REHolt commented 8 years ago

You are correct the APP should trigger the relay. The android app doesn't send a request for a specific pin. It just send a request and the Arduino app decides what to do with it. IF it's not working, i will have to take another look. I tested it earlier before re-uploading it and it seemed to work for me, but that doesn't mean I didn't screw it up again. I've been pretty focused on trying to get the new version of the app working with user configurable set-up information. I've go most of the config stuff working, I'm just having trouble with the file read/write. the File Read seems to work on the main page, but not on the config page.

REHolt commented 8 years ago

The only way i have to test it right now is to use my actual garage door opener since I sold my last unit to a guy at work and don't have any more parts. I just tried the Arduino app, I compiled it and uploaded it to my garage door, and it worked. I am able to open the door and read status

I also compiled the Android app that I uploaded earlier and it works as well. One thing that I noticed is that I only changed the IP in one location "http://Your Device IP", in the other location I left my IP address. If you didn't change them in both places one of the functions wont work.

angipp01 commented 8 years ago

I am noticing the http://192.168.1.59/Status and http://192.168.1.59/gpio/1 are the same.
I test them on a webpage and I get the same result. It just displays the status of the garage door Open/Close

I have supplied a another screenshot

of the MIT site and my wiring. D4 is connected to the Relay.

I have inputted the ip address on the top and the bottom of the MIT site.

Every time I press the button it only gives me the status of OPEN/CLOSED (that works)

I was thinking the delay is too fast. So I changed it, but still didn't make a difference. I still get no trigger action.

I have changed the delay from 500 to 50000 (still no trigger action)

// Match the request int val; if (req.indexOf("/gpio/1") != -1){ val = 1; digitalWrite(4, val); delay (5000); val = 0; digitalWrite(4, val); client.flush();} else if (req.indexOf("/Status") != -1) val = 0; else { val=0; Serial.println("invalid request"); client.stop(); return; }

angipp01 commented 8 years ago

I have provided a screenshot of the MIT site and the wiring screenshots.pdf image1 34565 2

REHolt commented 8 years ago

The delay does not need to be long. 500ms (1/2sec) works well on most garage door openers. All you are doing is simulating the push of a physical button. As far as the app and the web page are.concerned, the return data is always the status of the sensors, so that is correct.

In your pictures of the App Inventor screen it looks like the data is correct.

In the picture of the wiring, both relay lights are on, the red one indicates the relay has power and the green one indicates the relay is active, or being switched. If it is on all the time, that's the problem. I'm not familiar with the 'ESPDUINO' board, I use a much smaller device. On mine the digital I/O pins are 3.3v logic and the relay is 5v logic. I had to use a 2N2222A transistor and a 100k ohm resistor to interface the two.

REHolt commented 8 years ago

Here are a couple of pictures of my devices. 20160825_093804 20160820_103645

angipp01 commented 8 years ago

Your relay seems to be like mine. I don't think I need a transistor and 10k~ resistor. The spec sz it can be directly attached.
. I bought ming form: http://www.gearbest.com/power/pp_355149.html

Main Features: ● Relay control interface by single chip IO. Low level suction close, high level release ● It can be directly connected to the arduino boards ● High quality songle relay

angipp01 commented 8 years ago

I have also connected my oscilloscope to output pin D4. and press the button and don't see any visual display to 3.3 V. So I changed you scripted to have an High (1) output on D4. and it my reading it 3.3V. So I know the D4 can output 3.3V but the triggering with on the App or the Script is not working. Just the status changes work, when I move the magnetic switches.

The description says it is a 5V relay http://www.gearbest.com/power/pp_355149.html

REHolt commented 8 years ago

It can be driectly connected to the ADRUINO boards. I beleive they have 5 volt compatible pins. the ESP 8266 does not. I could not get mine to work without the transistor. I compiled and tested the app on my board today, and on another board a friend of mine brought back in to work today (His is the first picture) and had no problems. they both have the transistor. I used my cell phone in tethering mode, so the only thing I changed was the SSID and Password. I was able to make the relay switch and read status.

REHolt commented 8 years ago

Comment from description of Adruino Uno:

IOREF. This pin on the Arduino/Genuino board provides the voltage reference with which the microcontroller operates. A properly configured shield can read the IOREF pin voltage and select the appropriate power source or enable voltage translators on the outputs to work with the 5V or 3.3V.

Exerpt from ESPDuino: "All pins use 0 – 3.3 V"

angipp01 commented 8 years ago

Ok thanks I will look into it. Ya my boards has pins for 5V and 3.3V. You have been a big help.

REHolt commented 8 years ago

The 5 volt pins are for input power. It has an on-board 3.3v regulator. You can also power it directly from 3.3 volts. The relay is not getting enough current from the 3.3volt pull-up and is staying powered on.

angipp01 commented 8 years ago

what about this?

// Match the request int val; if (req.indexOf("/gpio/0") != -1) val = 0; if (req.indexOf("/gpio/1") != -1){ val = 1;

REHolt commented 8 years ago

That statement is reading the web request (the information you put in your prowser) and setting a variable accordig to the value you request. In the version you should be using (the version with Status), the whole statement should look like: // Match the request int val; if (req.indexOf("/gpio/1") != -1){ val = 1; digitalWrite(4, val); delay (500); val = 0; digitalWrite(4, val); client.flush();} else if (req.indexOf("/Status") != -1){ val = 0; client.flush();} else { val=0; Serial.println("invalid request"); client.stop(); return; Notice it checks to see if you are requesting "Status" and sets val = 0.

The Transistor basicly inverts the signal. The relay is looking for a low on its input to turn on. " Low level suction close, high level release", so a 1 (High) on the output pin (D4) will turn on the transistor, which allows current to flow, pulling the relay input low. Since you do not have the transistor, if you invert those values, it MIGHT work. See Below. Mine did not, as the relay would not work with the 3.3v input.

int val; if (req.indexOf("/gpio/1") != -1){ val = 0; digitalWrite(4, val); delay (500); val = 1; digitalWrite(4, val); client.flush();} else if (req.indexOf("/Status") != -1){ val = 1; client.flush();} else { val=0; Serial.println("invalid request"); client.stop(); return;

angipp01 commented 8 years ago

I have uploaded your last modification. It works.

I have a question. I thought my relay works on 5V? But when I give it 5V the Relay is forced on (it is stuck in Triggered). But when I give it a supply of only 3.3V it functions normally. The APP works perfect.

REHolt commented 8 years ago

Which change are you refering too? The one above with the inverted outputs? According to the relay spec. it does work on 5V. Where are you inputting the 3.3v? At the relay power pin, or at the trigger pin? I'm not sure what it is doing. I would need to see a schematic of how you have it connected.

angipp01 commented 8 years ago

I used your last sketch. I connected 3.3v to the VCC on the relay. It feels like the 5v to the VCC on the relay was saturated it and leaving stuck in triggered with the red like always on. The 3.3V works fine can you explain? Would there be a concern?

I kinda like powering the relay too high (5v) leaving the relay triggered.

REHolt commented 8 years ago

I think I would make some measurements and verify what is happening. The relay could be switching because when it tries to turn on, it is pulling too much power from the 3.3v supply. On most of these parts the 3.3v supply has very little current. It's possible your ESPDuino is resetting each time due to a droop in the power. I am just speculating, since I am not really sure how you have it connected and I am not familiar with this part. I just don't think your configuration would be very reliable or stable. I think I have a couple of the dual relays like you show in your picture. If I have some time tomorrow, I will try to breadboard a circuit like what I think you have and see if I can figure out what is going on.

REHolt commented 8 years ago

By the way, the last file I uploaded should have been just like the others and if your part is working the way it is supposed to, the outputs would be inverted, So I don't think it is really working the way you think it is.

REHolt commented 8 years ago

Sorry, I was in no shape to answer your question last night. Here is the story. Attached is a basic drawing of your relay circuit. 2016-08-26 2

With +5 volts applied to the relay power pin, the Red LED will come on. If the ESPDUINO D4 is connected to the relay control pin, when D4 output his Low (normal state) current will flow through the coil of the relay, turning it on, along with the Green LED. (Check the Normally Open (NO) contacts, they should be shorted). If D4 is High (3.3V), there will still be some voltage across the relay coil (~1.8v). This is probably enough to cause the relay to turn on, so the Green LED will still be on and the NO contacts will still be shorted.

With 3.3 volts applied to the relay power pin, the Red LED will come on. If the ESPDUINO D4 is connected to the relay control pin, when D4 output his Low (normal state) current will flow through the coil of the relay, turning it on along with the Green LED. (Check the Normally Open (NO) contacts, they should be shorted). If D4 is High (3.3V), there will be no voltage across the relay coil (0v since both sides are now 3.3v). This will cause the relay to turn off, so the Green LED will be off and the NO contacts will be open.

The second scenario, while currently working, can't be trusted. If your supply voltage drops slightly it may not supply enough current to switch the relay, or the relay and diode combination may pull more current than your 3.3volt supply can handle. The relay is designed to operate at 5V. Right now it is sensitive enough to work at a lower voltage. With age that could change and your circuit would stop working. 2016-08-26 3

Using this circuit will isolate the relay control pin from the ESP8266. It will provide an open collector input so that if the transistor is off (D4 =low), the relay will not be connected to ground. When D4=High, the transistor will turn on, connecting the relay control pin to ground and the relay will turn on.

REHolt commented 8 years ago

Oh, and if you ever try to use both relays, it will probably not work due to the current draw.

angipp01 commented 8 years ago

I have bought a 100k resistors and a 2n2222 transitor. I am going to wiring it up at per your recommendation (I notice many use this type of pull down concept.

I have 2 garage doors so eventually I will be duplicating everything and use other outputs. Also I have and exterior door at my garage that I will also be connecting a megnetic door contact (when the extort door opens I will get a text message)

REHolt commented 8 years ago

Sounds good. Let me know how it goes

angipp01 commented 8 years ago

The relay will not be used simulatiously. The relays only have a 0.5sec action. I have tested the 2n2222 and resistor on a breadboard and worked fine. Will solder it on a board tomorrow. Now to look for a case.

angipp01 commented 8 years ago

I am trying to implement a 2nd garage door with 2 door contacts. (same as your concept). So I have simply duplicated everything (I ignored OTA, and SMS section - didn't touch this section.)

It seemed logical but something doesn't seem right. I am not getting any errors but the URL is not working.

Also the same think I am doing with the APP. I have created Screen2 and duplicated everything using the another URL http:serverip/gpio/2 & http:serverip/Status2

garage dual.txt

REHolt commented 8 years ago

I've looked at doing the same thing (a friend has two garage doors) , but haven't implemented it yet. My approach would be a little different than yours. I would combine the two "Match Request" routines. It looks like the first one is evaluating the data and if it is "/gpio/2", it evaluates it as an invalid response and clears the buffer basically destroying the data, so Match2 has nothing to evaluate and doesn't work.

Try this approach. No guarantees, I just coded this in the text file and haven't compiled or tested it yet, as I am at work.

<// Match the request int val;

int val2;

if (req.indexOf("/gpio/1") != -1){ val = 1; digitalWrite(4, val); delay (500); val = 0; digitalWrite(4, val); client.flush();}

else if (req.indexOf("/Status") != -1){ val = 0; client.flush();}

// Match the request 2 else if (req.indexOf("/gpio/2") != -1){ val2 = 1; digitalWrite(2, val2); delay (500); val2 = 0; digitalWrite(2, val2); client.flush();}

else if (req.indexOf("/Status2") != -1){ val2 = 0; client.flush();} else { val=0; Serial.println("invalid request"); client.stop(); return; }>

You will also need to redo the "Prepare Response" routine. you will want to prepare the response based on which door is being accessed.

One other note; It looks like you are using GPIO2 as the control for the second door. I am not familiar with the ESPDuino part you are using, but on most of these devices GPIO2 is shared with the Tx or RX pin (can't remember which). You will want to double check that since if it is, it could cause your door to open any time the part is reset. This could be a problem if you are not home and there is a power outage. When power comes back on, your door will open.

angipp01 commented 8 years ago

Thanks for your suggestion. I will attempt to configure it Friday or Saturday.

REHolt commented 8 years ago

If you get it to work post both the ESP code and the Android code to the github repository under a new branch or version. I might want to use it. It would be nice to have a second contributor:)

angipp01 commented 8 years ago

I don't really understand what is meant "Prepare Response routine."
I have applied, my script and then your script. Once it is applied. http://IPaddress/Status http://IPaddress/Status2 http://IPaddress/gpio/1 http://IPaddress/gpio/2 All results as Page "Cannot be found"

But when I reload your 1 door script, http://IPaddress/gpio/1 Works fine.

Don't understand, all I did was duplicate everything and added "2" to the values.

REHolt commented 8 years ago

Upload a copy of your file and I will see what I can find. It may be late this evening or tomorrow before I get a chance to look at it. I got other commitments today.

I haven't looked at the software for this in about a week. I just finished laying out a PCB for another project. I actually puts some hooks in the layout so that I can use it for the Garage Opener as well. (Just in case it doesn't work for the intended purpose).

angipp01 commented 8 years ago

This is weird.. Using your scripted, WIFI works, but with mine it doesn't. This doesn't make sense since I didn't touch the WIFI parameters I have modified 2-3 more things but no change.( Again, you have other prioritizes, no rush.)

garage door test.txt

REHolt commented 8 years ago

I took your attached txt file and copied it directly into a blank sketch. I had to add the key.h file into the directory (Copied directly from the github directory). I ran "verify" and it compiled without errors. It did show the "deprecated variable" warning. I don't currently have a device to test it on, all of mine are deployed. I ordered a couple more over a month ago but they apparently got lost in the mail.

Looking over the file, it does look like you started with an older version, but the changes were insignificant. The door open routines look OK, I don't see any reason they wouldn't work. You still have not changed the "Response" routine. I believe the way it is written you would only get status of one door. Without being able to test it, I'm not sure what needs to change.

I have posted a couple of new versions of the Android App. I finally got all of the configuration stuff to work. I am playing with a version that will control 2 doors, but haven't gotten very far yet. I won't be able to fully test it since I don't have a device available. I plan to make it configurable for one or two doors, with or without sensors, so I can at least partially test it. It may not help though if the ESP Sketch isn't working correctly. I know one of the guy's a made a garage door opener for isn't using it yet (he has an iPhone). I may see if I can get it back from him for awhile so that I can use it for testing.

angipp01 commented 8 years ago

Ok thanks. I am excited. I will keep working on it.

REHolt commented 8 years ago

I had some time today (waiting on a delivery guy), so I made some changes to the ESP8266 app to accommodate 2 garage doors. I think could have done a little better as far as coding, but I hope it works. It should provide control and status on two doors. I posted it in the github directory. Take a look and let me know what you think, and how it works.

angipp01 commented 8 years ago

It works. I haven't connected to the relay yet. But the Website is working for Status 1&2. I have tested the door contacts and they never says "closed". I looked over your code, and I found the issue. Look at line 109 and 115 They both say "(Door1Status2)" So on line 115, I changed it to (Door2Status2). I haven't tested it yet. I will test it tomorrow morning.

angipp01 commented 8 years ago

Yes that was it. Door contacts works both 1&2 and open/closed. I will work on an App for Both doors and both statuses. I will update you when I am done the app

REHolt commented 8 years ago

Glad it works. I have an Android App that will work with two doors as well. I haven't quite got it working yet, but it is close. If you get the Android App working before I do, Please add it to this project as a contributor. I have been jumping around a lot on several different projects (My wife says I have ADD). I spent most of yesterday working on a mechanical design for another project. I went to dinner with a friend Friday night, turns out he has a CNC Router and he is going to make the mechanical part for me, if I can get a design file that works.

angipp01 commented 8 years ago

Ok, this is that I came up with. I have both buttons on same screen Left/right door. The Status output results in a html URL (weird). i have supplied and apk and aia files.. I don't know how you did the V3 apk file to change the ip address (like that)

https://drive.google.com/drive/folders/0B0_n097zdR0AQjNOYVdmRjNqcTg?usp=sharing

Yes my wife is saying the same thing. Last week I was at the Blue Jays game while messaging you back.

REHolt commented 8 years ago

Thanks! I updated your file with the Configuration Capability, so you can see how it's done. I posted it to the github as Android_Garage_Door_Opener_2Doors.aia. To use th configuration, just tap the title and it will take you to the configuration page, where you can enter the IP address and save it.

angipp01 commented 7 years ago

You are going to kill me. Sorry got to ask. The entire system is controlled by an Android app. ( I have an Tablet and Android tv boxes, to operate and check on the status of the door.) Regarding Phones, we use Apple (yes it was a mistake). So, I am trying to add a 3rd site to this script that has all the functions on one page (then I can bookmark this page and make it an icon)
example: http://randomnerdtutorials.com/esp8266-web-server/

I watched many youtube vid and couldn't adapt to your script. So searched for another solution called "Cayenne app"[apple/Ardroid](I think it uses Blynk) I have applied it to your script and receiving no errors (great). When I upload it to the Ardiuno, I get an IP address from Wifi (I can see this in the DCHP tables from the router.) but the gpio/1 & 2 Status 1 & 2 aren't working. But if I remove code for Cayenne, it works (suspecting there is a conflict) I really don't care about Cayenne app, just would like a way for Apple to have a control (the easiest way would be an alternate site.)

If you search for "//For Cayenne APP" you will find 7 entries.

#include <ESP8266WebServer.h>
#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266httpUpdate.h>
#include <CayenneDefines.h> //For Cayenne APP
#include <BlynkSimpleEsp8266.h> //For Cayenne APP
#include <CayenneWiFiClient.h>  //For Cayenne APP

extern "C" {
#include "user_interface.h"
}
#include "Keys.h"  //includes the wifi credentials and IFTTT URL

#ifdef DEBUG_ESP_PORT
#define DEBUG_MSG(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#else
#define DEBUG_MSG(...)
#endif

#define CAYENNE_PRINT Serial   //For Cayenne APP
char token[] = "nat3zk6agb";   //For Cayenne APP

// Hostname defaults to esp8266-[ChipID]

//Garage Door Status variables
int Status_Open;
int Status_Closed;
int On_Status;
String Door1_Status = "Unknown";
String Door2_Status = "Unknown";
//int val;

const byte Door1Enable = 15;
const byte Door2Enable = 14;

//Interrupt Definition
const byte Door1Status1 = 12;  //Open
const byte Door1Status2 = 13;  //Closed
const byte Door2Status1 = 4;  //Open
const byte Door2Status2 = 5;  //Closed
volatile byte state = LOW;

//Garage Door Open Timer setup
double openForTooLongInMins = 60;
int doorOpenedAtTimeInMills = 0;
int doorOpenDurationInSeconds = 0;
bool messageSentInThisOpening = false;
const int doorOpen = HIGH;
const int doorClosed = LOW;
SimpleTimer timer;

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

//-------------------------------------------------------------------------------
void setup() {

// Hostname defaults to esp8266-[ChipID]
wifi_station_set_hostname(Host_Name);

  Serial.begin(115200);
  delay(10);
  Cayenne.begin(token, "Media2", "905615");  //For Cayenne APP

  Serial.println("Booting");
  WiFi.mode(WIFI_STA);

// prepare GPIO to control the door switchw
  pinMode(Door1Enable, OUTPUT);
  digitalWrite(Door1Enable, 0);
  pinMode(Door2Enable, OUTPUT);
  digitalWrite(Door2Enable, 0);

// Prepare GPIO pins to monitor Status of the door 1
pinMode(Door1Status1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Door1Status1), Status1, CHANGE);
pinMode(Door1Status2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Door1Status2), Status1, CHANGE);

// Prepare GPIO to monitor Status of the door 2
pinMode(Door2Status1, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Door2Status1), Status2, CHANGE);
pinMode(Door1Status2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Door2Status2), Status2, CHANGE);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifiCreds[0]);
Serial.println(Host_Name);

WiFi.begin(wifiCreds[0], wifiCreds[1]);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
// ESP.restart();
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());

// print the host name
Serial.print("Host Name: ");
Serial.println(WiFi.hostname());

// Port defaults to 8266
// ArduinoOTA.setPort(8266);

// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname(Host_Name);

// No authentication by default
//ArduinoOTA.setPassword((const char *)"1234");

ArduinoOTA.onStart([]() {
Serial.println("Start");
});

ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});

ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});

ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});

//setup the OTA server
ArduinoOTA.begin();

Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

//check Status of Garage Doors at power-up
if (Door1_Status = "Unknown") Status1();

//check Status of Garage Door at power-up
if (Door2_Status = "Unknown") Status2();

timer.setInterval(5000, checkOpen);
}
/*------------------------------------------------------------
* Interrupt Service Routine for Garage Door Status
* The routine is set-up to read two HALL-Effect sensors
* One (Status_Open) is triggered when the door is all the way open
* The second (Status_Closed) one is triggered when the door is all the way closed
* If they are both reading "Low" then there is a sensor error,
* since they are pulled up to 3.3volts and are pulled low when the magenet
* is present. The second one is probably over-kill, but it gives an indiction if the door
* is only partially open
*/

void Status1() {
Status_Open = digitalRead(Door1Status1);
Status_Closed = digitalRead(Door1Status2);
switch (Status_Open) {
case 0:
{
switch (Status_Closed) {
case 0:
{
Door1_Status = "Sensor Error";
}
break;
case 1: {
Door1_Status = "Open";
}
break;
}
}
break;
case 1:
{
switch (Status_Closed) {
case 0:
{
Door1_Status = "Closed";
}
break;
case 1: {
Door1_Status = "Partially Open";
}
break;
}
}
}
}

void Status2() {
Status_Open = digitalRead(Door2Status1);
Status_Closed = digitalRead(Door2Status2);
switch (Status_Open) {
case 0:
{
switch (Status_Closed) {
case 0:
{
Door2_Status = "Sensor Error";
}
break;
case 1: {
Door2_Status = "Open";
}
break;
}
}
break;
case 1:
{
switch (Status_Closed) {
case 0:
{
Door2_Status = "Closed";
}
break;
case 1: {
Door2_Status = "Partially Open";
}
break;
}
}
}
}

/*------------------------------------------------------------
* Door Monitoring and SMS message routines
*  
*/
void resetDoorOpenCounter() {
doorOpenDurationInSeconds = 0;
messageSentInThisOpening = false;
}

void sendSms(String message) {
HTTPClient http;

http.begin(iftttMakerUrl, "A9 81 E1 35 B3 7F 81 B9 87 9D 11 DD 48 55 43 2C 8F C3 EC 87");

http.addHeader("content-type", "application/json");
int result = http.POST("{\"value1\":\"" + message + "\"}");

http.end();
}

void checkOpen() {
if ( digitalRead(Door1Status2) == doorOpen ) {
doorOpenDurationInSeconds += 5;
}
if (digitalRead(Door2Status2) == doorClosed) {
}

if ( messageSentInThisOpening == false &&
doorOpenDurationInSeconds > openForTooLongInMins * 60 ) {
String messageToSend = (String)"WARNING: your garage door has been open for more than " + openForTooLongInMins + " mins!";
sendSms(messageToSend);

doorOpenDurationInSeconds =0;
// todo: this does not know if it sent successfully. needs work
messageSentInThisOpening = true;
}
}

//--------------------------------------------------------------
void loop() {
timer.run();
Cayenne.run();   //For Cayenne APP
ArduinoOTA.handle();

// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");
while (!client.available()) {
delay(1);
}

// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();

// Match the request
int val;
int Door;
String s;
if (req.indexOf("/gpio/1") != -1){
val = 1;
Door = 1;
digitalWrite(Door1Enable, val);
delay (500);
val = 0;
digitalWrite(Door1Enable, val);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n<html>\r\nGarage Door 1 is ";
s += (Door1_Status);
s += "</html>\n";
client.print(s);
delay(1);
Serial.println("Client disonnected");

Serial.print("Door No. ");
Serial.println(Door);
Serial.println(s);}
else if (req.indexOf("/Status1") != -1){
val = 0;
Door = 1;
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n<html>\r\nGarage Door 1 is ";
s += (Door1_Status);
s += "</html>\n";
client.print(s);
delay(1);
Serial.println("Client disonnected");

Serial.print("Door No. ");
Serial.println(Door);
Serial.println(s);}
else if (req.indexOf("/gpio/2") != -1){
val = 1;
Door = 2;
Serial.print("Door No. ");
Serial.println(Door);
digitalWrite(Door2Enable, val);
delay (500);
val = 0;
digitalWrite(Door2Enable, val);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n<html>\r\nGarage Door 2 is ";
s += (Door2_Status);
s += "</html>\n";
client.print(s);
delay(1);
Serial.println("Client disonnected");

Serial.print("Door No. ");
Serial.println(Door);
Serial.println(s);}
else if (req.indexOf("/Status2") != -1){
val = 0;
Door = 2;
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n<html>\r\nGarage Door 2 is ";
s += (Door2_Status);
s += "</html>\n";
client.print(s);
delay(1);
Serial.println("Client disonnected");

Serial.print("Door No. ");
Serial.println(Door);
Serial.println(s);}
else {
val=0;
Serial.println("invalid request");
client.stop();
return;
}

// The client will actually be disconnected
// when the function returns and 'client' object is destroyed

}
`
REHolt commented 7 years ago

I have the Cayenne app on my tablet. I wasn't aware that there was code to add to your android app. I guess I haven't messed with it much. I suspect you are right, when you include their libraries, it is probably conflicting with the web calls for the door. Not sure when I will get a chance to look at this as I am working several projects right now.

A friend of mine has an Apple iPhone and wants me to make him a garage door opener. Since I don't have an iPhone or a MAC, i haven't been able to write the app. I was hoping someone else would put one together. I haven't seen anything posted on the forums, and I haven't been able to check the app-store to see if there is something close. If you come up with one let me know, please.

In the meantime I will see if I can figure out why the web-page approach, or Cayenne wount work.

angipp01 commented 7 years ago

I will try to attempt to work with the Cayenne app .

angipp01 commented 7 years ago

Well I have linked my arduino with Cayenne. I can say it is alright app for triggering applications. For example "press button" to activate and it will send an email. Pretty cool but would hate to get emails every time the button is pressed. Cayenne will not really work with your setup. Cayenne doesn't not notify of status "door is open/closed". Also doesn't email you if the door is open longer than 15min. YOur setup is way better than Cayenne. Your scoot has many customization that Cayenne can't do.

REHolt commented 7 years ago

Thanks, that was the first real program I have written for these devices. I spent a lot of time researching both the ESP8266 app and the android app. Most of the features were added just as a means of teaching myself how to program. The app worked for my purposes without most of the fancy features. All the bells and whistles are nice though:) I have several other apps I want to implement and the programming techniques I learned will come in handy for those. I wish I knew someone with a MAC who could write a similar app for the iPhone. I know a couple of people who would love to have it.

Right now I am working on another home control app and am kind of stuck. Hopefully I will figure it out soon. I just bought a 3D printer (it comes in later this week). I will be using it to make some cases for some of the projects and hopefully to make a robot I am working on.