My arduino code:
Code:
#include <SPI.h>
#include <Ethernet.h>
int relayPin = 9;
char Str[11];
int prevNum = 0;
int num = 0;
long onUntil = 0;
long pollingInterval = 5000; // in milliseconds
long onTime = 60000; // time, in milliseconds, for lights to be on after new email or comment
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xE1 };
char serverName[] = "winacro.com";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield time to initialize:
delay(2000);
}
void loop()
{
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /PHP/email.php HTTP/1.1");
client.println("HOST: winacro.com");
client.println();
int timer = millis();
//delay(1000);
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
// if there's data ready to be read:
if (client.available()) {
int i = 0;
//put the data in the array:
do {
Str[i] = client.read();
i++;
delay(1);
} while (client.available());
// Pop on the null terminator:
//Str[i] = '\0';
//convert server's repsonse to a int so we can evaluate it
Serial.print(Str);
num = atoi(Str);
Serial.print("Server's response: ");
Serial.println(num);
Serial.print("Previous response: ");
Serial.println(prevNum);
if (prevNum < 1)
{ //the first time around, set the previous count to the current count
prevNum = num;
Serial.println("First comment count stored.");
}
if (prevNum > num)
{ // handle if count goes down for some reason
prevNum = num;
}
}
else
{
Serial.println("No response from server.");
}
Serial.println("Disconnecting.");
client.stop();
if(num > prevNum) {
Serial.println("New Comment.");
digitalWrite(relayPin, HIGH);
prevNum = num;
onUntil = millis() + onTime;
}
else if(millis() > onUntil)
{
digitalWrite(relayPin, LOW);
}
//delay(pollingInterval);
}
#include <Ethernet.h>
int relayPin = 9;
char Str[11];
int prevNum = 0;
int num = 0;
long onUntil = 0;
long pollingInterval = 5000; // in milliseconds
long onTime = 60000; // time, in milliseconds, for lights to be on after new email or comment
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xE1 };
char serverName[] = "winacro.com";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// give the Ethernet shield time to initialize:
delay(2000);
}
void loop()
{
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(serverName, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /PHP/email.php HTTP/1.1");
client.println("HOST: winacro.com");
client.println();
int timer = millis();
//delay(1000);
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
// if there's data ready to be read:
if (client.available()) {
int i = 0;
//put the data in the array:
do {
Str[i] = client.read();
i++;
delay(1);
} while (client.available());
// Pop on the null terminator:
//Str[i] = '\0';
//convert server's repsonse to a int so we can evaluate it
Serial.print(Str);
num = atoi(Str);
Serial.print("Server's response: ");
Serial.println(num);
Serial.print("Previous response: ");
Serial.println(prevNum);
if (prevNum < 1)
{ //the first time around, set the previous count to the current count
prevNum = num;
Serial.println("First comment count stored.");
}
if (prevNum > num)
{ // handle if count goes down for some reason
prevNum = num;
}
}
else
{
Serial.println("No response from server.");
}
Serial.println("Disconnecting.");
client.stop();
if(num > prevNum) {
Serial.println("New Comment.");
digitalWrite(relayPin, HIGH);
prevNum = num;
onUntil = millis() + onTime;
}
else if(millis() > onUntil)
{
digitalWrite(relayPin, LOW);
}
//delay(pollingInterval);
}
This is what I get:
Code:
connecting...
connected
No response from server.
Disconnecting.
connected
No response from server.
Disconnecting.
Code:
<?php
/* connect to gmail */
$hostname = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = "xcxc@winwin.com";
$password = "1123412";
/* try to connect */
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_MESSAGES);
if ($status) {
echo $status->messages;
}
?>
/* connect to gmail */
$hostname = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = "xcxc@winwin.com";
$password = "1123412";
/* try to connect */
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_MESSAGES);
if ($status) {
echo $status->messages;
}
?>