0
我的項目是關於通過網絡服務器解鎖和鎖門。但是我的arduino程序有一些問題。我是新的arduino程序,這是我的程序。我無法解決我的arduino程序錯誤
可以幫我解決這個問題嗎?
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modifie
*/
#include<SPI.h>
#include<Ethernet_v2.h>
#include<SD.h>
#define REQ_BUF_SZ 60
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif
IPAddress ip(192,168,1,177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0};
char req_index = 0;
boolean LED_state[2] = {0};
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Initializing SD card........");
if(!SD.begin(4)){
Serial.println("Error-SD card initialized");
return;
}
Serial.println("Success-Found cuba.htm file");
pinMode(8, OUTPUT);
// start the Ethernet connection and the server:
#if defined(WIZ550io_WITH_MACADDRESS)
Ethernet.begin(ip);
#else
Ethernet.begin(mac, ip);
#endif
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
req_index++;
}
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
if (StrContains(HTTP_req, "ajax_inputs")) {
client.println("Content-Type: text/html");
client.println("Connection: Keep-alive");// the connection will be closed after completion of the response
client.println();
SetDNS();
XML_response(client);
}
else{
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
webFile=SD.open("cuba.htm");
if(webFile){
while(webFile.available()){
client.write(webFile.read());
}
webFile.close();
}
}
Serial.print(HTTP_req);
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void SetDNS(void)
{
// LED 1 (pin 6)
if (StrContains(HTTP_req, "DNS=1")) {
DNS_state[0] = 1; // save LED state
digitalWrite(8, HIGH);
}
else if (StrContains(HTTP_req, "DNS=0")) {
DNS_state[0] = 0; // save LED state
digitalWrite(8, LOW);
}
}
void XML_response(EthernetClient cl)
{
int analog_val; // stores value read from analog inputs
int count; // used by 'for' loops
int sw_arr[] = {2, 3}; // pins interfaced to switches
cl.print("<?xml version = \"1.0\" ?>");
cl.print("<inputs>");
cl.print("<DNS>");
if (DNS_state[1]) {
cl.print("on");
}
else {
cl.print("off");
}
cl.println("</DNS>");
cl.print("</inputs>");
}
// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
for (int i = 0; i < length; i++) {
str[i] = 0;
}
}
// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;
len = strlen(str);
if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
爲了您的信息,這是原來的LED程序,但我改變它。
這是錯誤,當我編譯了一個程序
WebServer.ino: In function 'void loop()':
WebServer:96: error: 'StrContains' was not declared in this scope
WebServer:101: error: 'SetDNS' was not declared in this scope
WebServer:102: error: 'XML_response' was not declared in this scope
WebServer:118: error: 'StrClear' was not declared in this scope
WebServer.ino: In function 'void SetDNS()':
WebServer:142: error: 'StrContains' was not declared in this scope
WebServer:143: error: 'DNS_state' was not declared in this scope
WebServer:147: error: 'DNS_state' was not declared in this scope
WebServer.ino: In function 'void XML_response(EthernetClient)':
WebServer:162: error: 'DNS_state' was not declared in this scope
'StrContains' was not declared in this scope
所有感謝您的關注