可以在本地网页内置arduino草图中添加外部CSS(也在SD卡上)文件?

时间:2018-03-25 16:14:07

标签: css arduino

我正在用arduino和以太网盾编写代码。它包含一个加速度计,可以读取值并在网页中显示它们。它在当地。如果我不得不用client.print();编写CSS样式,我会花费大量时间和无用的代码行。我想添加一个与内部页面链接的外部CSS工作表到arduino sketch中。我试图将CSS表格放入草图的目录并设置<link href>,但它不起作用。页面是这样的:

@mike 这就是整个功能,谢谢。

      void RichiesteAlServer() {
  // 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();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          //client.println("Content-Type: text/html");
          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();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          client.println("<head><title>Sismografo</title><link href=\"css/style.css\" rel=\"stylesheet\" type=\"text/css\"/></head>");
          client.println("<body>");
          client.println("<h1>Sismografo</h1>");

          client.println("<p>");
          client.print("Indice Array : ");
          client.print(indiceArray);
          client.println("</p>");

          client.println("<p>");
          stampaCanvas(client);
          client.println("</p>");

          client.println("<p>");
          client.print("valore: ");
          client.print(arrayValoriAccel[indiceArray]);
          client.println("</p>");

          client.println("<p>");
          client.print("inizio scossa : ");
          client.print(inizio_scossa);
          client.println("</p>");


          client.println("<p>");
          client.print("fine scossa : ");
          client.print(fine_scossa);
          client.println("</p>");

          client.println("<p>");
          client.print("Durata scossa : ");
          client.print(durata_totale_scossa);
          client.println("</p>");

          client.println("<p>");
          client.print("cont : ");
          client.print(cont);
          client.println("</p>");

          client.println("</body>");
          client.println("</html>");



          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();
    Serial.println("client disconnected");
  }
}

0 个答案:

没有答案