/*
Web client This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen */
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h> #define ResetPIN 7 // 初始化引脚
LiquidCrystal lcd(, , , , , ); // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAA, 0xCE, 0xEA, 0xFF, 0xE1 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "192.168.9.6"; // name address for Google (using DNS)
String clientPwd="-1"; // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(,,,);
IPAddress gateway(,,,);
IPAddress dns_server(,,,);
IPAddress subnet(,,,);
// 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; int errCount=; void setup() { //LCD
// 设置行列值
lcd.begin(, ); pinMode(ResetPIN,OUTPUT);
digitalWrite(ResetPIN,LOW); // Open serial communications and wait for port to open:
Serial.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// give the Ethernet shield a second to initialize:
if (Ethernet.begin(mac) == ) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip,dns_server,gateway,subnet);
} delay();
Serial.println("Ready");
} void loop()
{ Serial.println(clientPwd);
// 打印字符串
lcd.setCursor(,);
lcd.print(clientPwd); httpRequest();
delay(); } //================Http Request Code========================
void httpRequest(){
// if you get a connection, report back via serial: if(!client.connected()){
Serial.println("disconnecting.");
client.stop();
if (client.connect(server, )) {
Serial.println("connected");
}else{
// kf you didn't get a connection to the server:
Serial.println("connection failed");
errCount++;
if(errCount>=){
digitalWrite(ResetPIN,HIGH);
delay();
}
}
} else{ // Make a HTTP request:
client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf=0" +" HTTP/1.1");
client.println("Host:" +String(server));
//client.println("Connection: close"); client.println();
delay();
String reply="";
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
reply+=c; }
//Serial.print(reply);
int index=reply.indexOf("\"Model\":\"8888");
if(index>=){
index=index+;
clientPwd= reply.substring(index,index+);
Serial.println("Changed:" + clientPwd); } errCount=;
//wdt_reset();
} }
//================End Http Request Code===============
arduino网卡扩展板,会使用 2,10,11,12,13 i/o口,所以要调整lcd使用的接口
人体感应器信号输出连S9013三极管(来控制lcd背景灯的亮与灭(使用K编号的脚)
/*
Web client This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield. Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen */
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/wdt.h> #define ResetPIN 7
#define HasManPIN 8
#define RebootPIN 6 // Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAA, 0xCE, 0x3A, 0x6F, 0xE1 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "192.168.9.6"; // name address for Google (using DNS)
String clientPwd="-1";
int hasMan=;
LiquidCrystal_I2C lcd(0x27,,); // Set the static IP address to use if the DHCP fails to assign
IPAddress ip(,,,);
IPAddress gateway(,,,);
IPAddress dns_server(,,,);
IPAddress subnet(,,,);
// 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; int errCount=;
unsigned long lastRequest=; void setup() { pinMode(HasManPIN,INPUT);
pinMode(ResetPIN,OUTPUT);
pinMode(RebootPIN,OUTPUT); digitalWrite(ResetPIN,LOW);
digitalWrite(RebootPIN,LOW); // Open serial communications and wait for port to open:
Serial.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
// give the Ethernet shield a second to initialize:
if (Ethernet.begin(mac) == ) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip,dns_server,gateway,subnet);
} lcd.init();
lcd.backlight();
lcd.print("-1");
delay();
Serial.println("Ready");
lastRequest=millis(); wdt_enable(WDTO_8S);
} void loop()
{
//digitalWrite(RebootPIN,LOW); if((millis()-lastRequest)>=){
Serial.println("reboot");
digitalWrite(ResetPIN,HIGH);
delay();
}
Serial.println("lcd...");
Serial.println(clientPwd);
// 打印字符串
lcd.setCursor(,);
lcd.print(clientPwd); //digitalWrite(RebootPIN,HIGH); hasMan=digitalRead(HasManPIN);
Serial.println(hasMan);
if(hasMan==){
lcd.backlight();
}else{
lcd.noBacklight();
} if( (millis() - lastRequest) >=)
{
httpRequest();
lastRequest=millis();
} delay();
Serial.println("lcd over!");
//
wdt_reset(); } //================Http Request Code========================
void httpRequest(){
// if you get a connection, report back via serial: if(!client.connected()){
Serial.println("disconnecting.");
client.stop();
if (client.connect(server, )) {
Serial.println("connected");
}else{
// kf you didn't get a connection to the server:
Serial.println("connection failed");
errCount++;
if(errCount>=){
digitalWrite(ResetPIN,HIGH);
delay();
}
}
} else{ // Make a HTTP request:
client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf="+String(hasMan) +" HTTP/1.1");
client.println("Host:" +String(server));
//client.println("Connection: close"); client.println();
delay();
String reply="";
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
reply+=c; }
//Serial.print(reply);
int index=reply.indexOf("\"Model\":\"8888");
if(index>=){
index=index+;
clientPwd= reply.substring(index,index+);
Serial.println("Changed:" + clientPwd); } errCount=;
//wdt_reset();
} }
//================End Http Request Code===============