66741 发表于 2016-1-23 09:20:32

谁来给我修改一下代码? 帮我把W5100的代码改成可以上传至yeelink的代码可以吗?

#include "DHT.h"
#include <SFE_BMP180.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include "RTClib.h"

DHT dht;
RTC_DS1307 RTC;
SFE_BMP180 pressure;
byte mac[] = {
   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 51, 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);

void setup()
{
   Serial.begin(9600);
   Serial.println();
   Wire.begin();
   RTC.begin();
   Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)");
   {
   dht.setup(2); // data pin 2
   if (! RTC.isrunning()) {
       Serial.println("RTC is NOT running!");
       // following line sets the RTC to the date & time this sketch was compiled
       RTC.adjust(DateTime(__DATE__, __TIME__));
       {
         while (!Serial) {
         }
         ; // wait for serial port to connect. Needed for Leonardo only
       }
       // start the Ethernet connection and the server:
       Ethernet.begin(mac, ip);
       server.begin();
       Serial.print("server is at ");
       Serial.println(Ethernet.localIP());
       {
         Serial.println("REBOOT");

         // Initialize the sensor (it is important to get calibration values stored on the device).

         if (pressure.begin())
         Serial.println("BMP180 init success");
         else
       }
   }
   }
}
void loop() {�
delay(dht.getMinimumSamplingPeriod());
   float humidity = dht.getHumidity();
   float temperature = dht.getTemperature();
}
{
   Serial.print(dht.getStatusString());
   Serial.print("\t");
   Serial.print(humidity, 1);
   Serial.print("\t\t");
   Serial.print(temperature, 1);
   Serial.print("\t\t");
   Serial.println(dht.toFahrenheit(temperature), 1);
}
{
   // 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
         for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
             int sensorReading = analogRead(analogChannel);
             client.print("analog input ");
             client.print(analogChannel);
             client.print(" is ");
             client.print(sensorReading);
             client.println("<br />");
         }
         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");
   }
   {
   char status;
   double T, P, p0, a;

   // Loop here getting pressure readings every 10 seconds.

   // If you want sea-level-compensated pressure, as used in weather reports,
   // you will need to know the altitude at which your measurements are taken.
   // We're using a constant called ALTITUDE in this sketch:

   Serial.println();
   Serial.print("provided altitude: ");
   Serial.print(ALTITUDE, 0);
   Serial.print(" meters, ");
   Serial.print(ALTITUDE * 3.28084, 0);
   Serial.println(" feet");

   // If you want to measure altitude, and not pressure, you will instead need
   // to provide a known baseline pressure. This is shown at the end of the sketch.

   // You must first get a temperature measurement to perform a pressure reading.

   // Start a temperature measurement:
   // If request is successful, the number of ms to wait is returned.
   // If request is unsuccessful, 0 is returned.

   status = pressure.startTemperature();
   if (status != 0)
   {
       // Wait for the measurement to complete:
       delay(status);

       // Retrieve the completed temperature measurement:
       // Note that the measurement is stored in the variable T.
       // Function returns 1 if successful, 0 if failure.

       status = pressure.getTemperature(T);
       if (status != 0)
       {
         // Print out the measurement:
         Serial.print("temperature: ");
         Serial.print(T, 2);
         Serial.print(" deg C, ");
         Serial.print((9.0 / 5.0)*T + 32.0, 2);
         Serial.println(" deg F");

         // Start a pressure measurement:
         // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
         // If request is successful, the number of ms to wait is returned.
         // If request is unsuccessful, 0 is returned.

         status = pressure.startPressure(3);
         if (status != 0)
         {
         // Wait for the measurement to complete:
         delay(status);

         // Retrieve the completed pressure measurement:
         // Note that the measurement is stored in the variable P.
         // Note also that the function requires the previous temperature measurement (T).
         // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
         // Function returns 1 if successful, 0 if failure.

         status = pressure.getPressure(P, T);
         if (status != 0)
         {
             // Print out the measurement:
             Serial.print("absolute pressure: ");
             Serial.print(P, 2);
             Serial.print(" mb, ");
             Serial.print(P * 0.0295333727, 2);
             Serial.println(" inHg");

             // The pressure sensor returns abolute pressure, which varies with altitude.
             // To remove the effects of altitude, use the sealevel function and your current altitude.
             // This number is commonly used in weather reports.
             // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
             // Result: p0 = sea-level compensated pressure in mb

             p0 = pressure.sealevel(P, ALTITUDE); // we're at 1655 meters (Boulder, CO)
             Serial.print("relative (sea-level) pressure: ");
             Serial.print(p0, 2);
             Serial.print(" mb, ");
             Serial.print(p0 * 0.0295333727, 2);
             Serial.println(" inHg");

             // On the other hand, if you want to determine your altitude from the pressure reading,
             // use the altitude function along with a baseline pressure (sea-level or other).
             // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
             // Result: a = altitude in m.

             a = pressure.altitude(P, p0);
             Serial.print("computed altitude: ");
             Serial.print(a, 0);
             Serial.print(" meters, ");
             Serial.print(a * 3.28084, 0);
             Serial.println(" feet");
         }
         else Serial.println("error retrieving pressure measurement\n");
         }
         else Serial.println("error starting pressure measurement\n");
       }
       else Serial.println("error retrieving temperature measurement\n");
   }
   else Serial.println("error starting temperature measurement\n");

   delay(5000);// Pause for 5 seconds.
   }
   {
   DateTime now = RTC.now();

   Serial.print(now.year(), DEC);
   Serial.print('/');
   Serial.print(now.month(), DEC);
   Serial.print('/');
   Serial.print(now.day(), DEC);
   Serial.print(' ');
   Serial.print(now.hour(), DEC);
   Serial.print(':');
   Serial.print(now.minute(), DEC);
   Serial.print(':');
   Serial.print(now.second(), DEC);
   Serial.println();

   Serial.print(" since midnight 1/1/1970 = ");
   Serial.print(now.unixtime());
   Serial.print("s = ");
   Serial.print(now.unixtime() / 86400L);
   Serial.println("d");

   // calculate a date which is 7 days and 30 seconds into the future
   DateTime future (now.unixtime() + 7 * 86400L + 30);

   Serial.print(" now + 7d + 30s: ");
   Serial.print(future.year(), DEC);
   Serial.print('/');
   Serial.print(future.month(), DEC);
   Serial.print('/');
   Serial.print(future.day(), DEC);
   Serial.print(' ');
   Serial.print(future.hour(), DEC);
   Serial.print(':');
   Serial.print(future.minute(), DEC);
   Serial.print(':');
   Serial.print(future.second(), DEC);
   Serial.println();

   Serial.println();
   delay(3000);
   }
}
}
}
页: [1]
查看完整版本: 谁来给我修改一下代码? 帮我把W5100的代码改成可以上传至yeelink的代码可以吗?