为什么在大约1周后停止运行arduino?

问题描述 投票:1回答:1

这适用于小型家庭自动化系统。我有一个带有以太网盾的arduino uno。这个arduino处理来自其他网站的请求,并将引脚设置为1.5秒。然后我们的大门或围栏打开或关闭。

这个系统大约工作一周。然后我必须手动重置arduino,它再工作一周。

码:

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
IPAddress ip(192,168,1,54);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(8080);

//variables for clicking

bool gateClick = false;
bool fenceClick = false;
long time = 0;
boolean isBusy = false;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);



  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

  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 newData = false;
String request = "";
while (client.connected()) {

  while (client.available()) {
    char c = client.read();
    Serial.write(c);
    request += c;
    newData = true;

  }
  if (newData) {
    // send a standard http response header
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/plain");
    client.println("Connection: close");  // the connection will be closed after completion of the response
    //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
    client.println("Access-Control-Allow-Origin: *");
    client.println();
    client.println("<!DOCTYPE HTML>");
    client.println("<html>");


    //Request is always: "value(abc)?".
    //  a is always 2,
    //  b: 1 = fence, 2 = gate,
    //  c: 0 of 1 open of close, regular push button, not important
    if (request.indexOf("value(210)?") != -1 || request.indexOf("value(211)?") != -1)
    {
      client.println("Ok");
      fenceClick = true;
    }
    else if (request.indexOf("value(220)?") != -1 || request.indexOf("value(220)?") != -1)
    {
      client.println("Ok");
      gateClick = true;

    }

    else
    {
      client.println("not in use");
    }


    client.println("</html>");
    newData = false;
    break;
  }

}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
  }


  //setting pin high or low
  //There only can be one pin high at the same time, hardware requires that

  //when any pin is high
  if(isBusy == true)
  {
    //when any pin is high for more than 1500 millis, make it all low
    if(millis() - time > 1500 || millis() - time <0)
    {

      digitalWrite(7, LOW);//gate

      digitalWrite(6, LOW);//fence

      Serial.println("All low");

      isBusy = false;
    }
  }
  else
    //when all pins are low, check if there's any that must be high
  {

    if( gateClick == true)
    {
      digitalWrite(7, HIGH);
      time = millis();
  isBusy = true;
  gateClick = false;
  Serial.println("Gate high");


}
else if( fenceClick == true)
{
  digitalWrite(6, HIGH);
  time = millis();
  isBusy = true;
  fenceClick = false;
  Serial.println("fence high");

  }

 }
}
arduino webrequest ethernet
1个回答
1
投票

我通过删除所有“串行”线解决了这个问题。看起来缓冲区已满,arduino停止运行。它运行良好大约几个月。

© www.soinside.com 2019 - 2024. All rights reserved.