Hello All:
I have an Arduino Uno with a SeeedStudio Ethernet Shield v2.0
It's set up as a test while I learn....just lighting LEDs and Relays for now.
Currently it is setup like a WebServer where I can call HTTP Requests from the web (or an iOS app called AEC - Arduino Ethernet Controller...but that app is just making the requests when you press a button).
Everything above is working fine.
I recently took apart a wireless doorbell and attached it to the Arduino. I have the RF board powered by the breadboard and wired to one pin on the Arduino from it's speaker wire. When the doorbell goes off, the arduino detects the HIGH reading on the pin.
I want the arduino to then send an HTTP GET request to a webaddress/service that sends a notification to my pebble watch. (Called Doorbell on the Pebble store).
I dont know how to make this request withing the sketch. I tried a few examples after searching but could never make it happen.
Could someone please take a look. I don't know how to do this...and I really have tried.
My current functions are doorBell() and dbNotify() starting on line 94.
void doorBell()
{
int dbPressed = digitalRead(19);
if (dbPressed == HIGH) {
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledAmber, HIGH);
delay(500);
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledAmber, LOW);
dbNotify();
delay(3000); //prevent multiple function calls because it's connected to speaker wire.
}
}
void dbNotify() //client function to send/receive GET request data.
{
if (client.connect(dbServer, 80)) {
Serial.println("Doorbell Server Connected");
Serial.println("==========================");
client.println("GET /doorbell/?key=1234567890 HTTP/1.0"); // Make a HTTP request:
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("Doorbell Connection Failed");
Serial.println("==========================");
}
}
Basic event based client code you might modify to test your bell setup. Note that you will probably need something like a 2000ms delay after your button event so only one notification will be sent instead of a bunch.
//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "checkip.dyndns.com"; // test web page server
EthernetClient client;
//////////////////////
void setup(){
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.begin(9600);
Serial.println("Better client ip test 3/1/13"); // so I can keep track of what is loaded
Serial.println("Send an e in serial monitor to test"); // what to do to test
}
void loop(){
// check for serial input
if (Serial.available() > 0) //if something in serial buffer
{
byte inChar; // sets inChar as a byte
inChar = Serial.read(); //gets byte from buffer
if(inChar == 'e') // checks to see byte is an e
{
sendGET(); // call sendGET function below when byte is an e
}
}
}
//////////////////////////
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET / HTTP/1.1"); //download text
client.println("Host: checkip.dyndns.com");
client.println("Connection: close"); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop(); //stop client
}
Thanks for the replies...I'll continue to test and re-write. I'll report back. The watch notification service may be broken as I'm getting delayed responses when sending via browser (my visitor will leave before I know the bell rang). But I'm still determined to get the code working. Thanks.