Tutorial 8
Tutorial 8
Arduine Screenshots
PushingBox Screenshots:
Email Screenshot:
Code:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
};
EthernetClient client;
int lightlevel = 0;
pinMode(LDRPIN, INPUT);
Ethernet.init(32);
Serial.begin(57600);
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
delay(1000);
void loop() {
lightlevel = 1024 - analogRead(LDRPIN); // read the light
// purposes only:
if(client.find("\r\n\r\n")) {
while (client.available()) {
char c = client.read();
Serial.write(c);
if(c == '1') {
sendBox = true;
}
if (millis() - lastConnectionTime > timegap) { // wait for timegap secs
if(sendBox)
httpRequest(1);
else
httpRequest(0);
Serial.println();
client.stop();
if (client.connect(server, 80)) {
Serial.println("Connected to server");
sendBox = false;
Serial.println(url);
delay(10);
client.println(url);
client.println("Host: 192.168.0.1");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
else {
Serial.println("Connection failed");
}