极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4358|回复: 2

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

[复制链接]
发表于 2016-1-22 20:51:16 | 显示全部楼层 |阅读模式
本帖最后由 66741 于 2016-1-29 16:18 编辑

我才12岁


  1. Hardware connections:

  2. - (GND) to GND
  3. + (VDD) to 3.3V

  4. (WARNING: do not connect + to 5V or the sensor will be damaged!)

  5. You will also need to connect the I2C pins (SCL and SDA) to your
  6. Arduino. The pins are different on different Arduinos:

  7. Any Arduino pins labeled:  SDA  SCL
  8. Uno, Redboard, Pro:        A4   A5
  9. Mega2560, Due:             20   21
  10. Leonardo:                   2    3

  11. Leave the IO (VDDIO) pin unconnected. This pin is for connecting
  12. the BMP180 to systems with lower logic levels such as 1.8V

  13. Have fun! -Your friends at SparkFun.

  14. The SFE_BMP180 library uses floating-point equations developed by the
  15. Weather Station Data Logger project: http://wmrx00.sourceforge.net/

  16. Our example code uses the "beerware" license. You can do anything
  17. you like with this code. No really, anything. If you find it useful,
  18. buy me a beer someday.

  19. V10 Mike Grusin, SparkFun Electronics 10/24/2013
  20. */

  21. // Your sketch must #include this library, and the Wire library.
  22. // (Wire is a standard library included with Arduino.):

  23. #include <Ethernet.h>
  24. #include <WiFi.h>
  25. #include <SPI.h>
  26. #include <yl_data_point.h>
  27. #include <yl_device.h>
  28. #include <yl_w5100_client.h>
  29. #include <yl_wifi_client.h>
  30. #include <yl_messenger.h>
  31. #include <yl_sensor.h>
  32. #include <yl_value_data_point.h>
  33. #include <yl_sensor.h>
  34. #include "dht11.h"
  35. #include <SFE_BMP180.h>
  36. #include <Wire.h>

  37. //this example reads data from a lm35dz sensor, convert value to degree Celsius
  38. //and then post it to yeelink.net

  39. //replace 2633 3539 with ur device id and sensor id
  40. yl_device ardu(2633);
  41. yl_sensor therm(3539, &ardu);
  42. //replace first param value with ur u-apikey
  43. yl_w5100_client client;
  44. yl_messenger messenger(&client, "u-apikey", "api.yeelink.net");

  45. const int pin = 5;

  46. dht11 DHT11;   // the Object for sensor DHT11
  47. int temp; // 溫度, 因為 DHT11 只有給整數 !
  48. int humi; // 濕度, 因為 DHT11 只有給整數 !

  49. SFE_BMP180 pressure;

  50. double baseline; // baseline pressure

  51. void setup()
  52. {
  53.   Serial.begin(9600); //for output information
  54.   Serial.println("REBOOT");
  55.   byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
  56.   Ethernet.begin(mac);
  57.   Serial.println("Testing the DHT11 and dht11.h Library !");
  58.   int chk = DHT11.read(pin);
  59.   Serial.print(String("Error code=") + chk);
  60.   Serial.println(String("Humidity=") + DHT11.humidity + ", Temperature=" + DHT11.temperature);
  61.   if (pressure.begin())
  62.     Serial.println("BMP180 init success");
  63.   else
  64.   {
  65.     // Oops, something went wrong, this is usually a connection problem,
  66.     // see the comments at the top of this sketch for the proper connections.

  67.     Serial.println("BMP180 init fail (disconnected?)\n\n");
  68.     while (1); // Pause forever.
  69.   }

  70.   // Get the baseline pressure:

  71.   baseline = getPressure();

  72.   Serial.print("baseline pressure: ");
  73.   Serial.print(baseline);
  74.   Serial.println(" mb");
  75. }

  76. void loop()
  77. {
  78.   delay(2000);   // Wait 2  seconds between measurements.
  79.   int chk = DHT11.read(pin);
  80.   if (chk != 0 ) {  // 讀取 DHT11 有問題
  81.     Serial.println("DHT11 reading Error !");
  82.   } else {    // 把這行注釋掉就可以有錯也照印 !
  83.     temp = DHT11.temperature;
  84.     humi = DHT11.humidity;
  85.     Serial.print("Humidity: ");
  86.     Serial.print(humi);
  87.     Serial.print(" %\t");
  88.     Serial.println(String("Temperature: ") + temp + " oC");
  89.     double a, P;

  90.     // Get a new pressure reading:

  91.     P = getPressure();

  92.     // Show the relative altitude difference between
  93.     // the new reading and the baseline reading:

  94.     a = pressure.altitude(P, baseline);

  95.     Serial.print("relative altitude: ");
  96.     if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
  97.     Serial.print(a, 1);
  98.     Serial.print(" meters, ");
  99.     if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
  100.     Serial.print(a * 3.28084, 0);
  101.     Serial.println(" feet");

  102.     delay(500);
  103.   }


  104.   double getPressure()
  105.   {
  106.     char status;
  107.     double T, P, p0, a;

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

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

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

  116.       delay(status);

  117.       // Retrieve the completed temperature measurement:
  118.       // Note that the measurement is stored in the variable T.
  119.       // Use '&T' to provide the address of T to the function.
  120.       // Function returns 1 if successful, 0 if failure.

  121.       status = pressure.getTemperature(T);
  122.       if (status != 0)
  123.       {
  124.         // Start a pressure measurement:
  125.         // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
  126.         // If request is successful, the number of ms to wait is returned.
  127.         // If request is unsuccessful, 0 is returned.

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

  133.           // Retrieve the completed pressure measurement:
  134.           // Note that the measurement is stored in the variable P.
  135.           // Use '&P' to provide the address of P.
  136.           // Note also that the function requires the previous temperature measurement (T).
  137.           // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
  138.           // Function returns 1 if successful, 0 if failure.

  139.           status = pressure.getPressure(P, T);
  140.           if (status != 0)
  141.           {
  142.             return (P);
  143.           }
  144.           else Serial.println("error retrieving pressure measurement\n");
  145.         }
  146.         else Serial.println("error starting pressure measurement\n");
  147.       }
  148.       else Serial.println("error retrieving temperature measurement\n");
  149.     }
  150.     else Serial.println("error starting temperature measurement\n");
  151.   }// if..else..
  152. } // loop(
  153. Hardware connections:

  154. - (GND) to GND
  155. + (VDD) to 3.3V

  156. (WARNING: do not connect + to 5V or the sensor will be damaged!)

  157. You will also need to connect the I2C pins (SCL and SDA) to your
  158. Arduino. The pins are different on different Arduinos:

  159. Any Arduino pins labeled:  SDA  SCL
  160. Uno, Redboard, Pro:        A4   A5
  161. Mega2560, Due:             20   21
  162. Leonardo:                   2    3

  163. Leave the IO (VDDIO) pin unconnected. This pin is for connecting
  164. the BMP180 to systems with lower logic levels such as 1.8V

  165. Have fun! -Your friends at SparkFun.

  166. The SFE_BMP180 library uses floating-point equations developed by the
  167. Weather Station Data Logger project: http://wmrx00.sourceforge.net/

  168. Our example code uses the "beerware" license. You can do anything
  169. you like with this code. No really, anything. If you find it useful,
  170. buy me a beer someday.

  171. V10 Mike Grusin, SparkFun Electronics 10/24/2013
  172. */

  173. // Your sketch must #include this library, and the Wire library.
  174. // (Wire is a standard library included with Arduino.):

  175. #include <Ethernet.h>
  176. #include <WiFi.h>
  177. #include <SPI.h>
  178. #include <yl_data_point.h>
  179. #include <yl_device.h>
  180. #include <yl_w5100_client.h>
  181. #include <yl_wifi_client.h>
  182. #include <yl_messenger.h>
  183. #include <yl_sensor.h>
  184. #include <yl_value_data_point.h>
  185. #include <yl_sensor.h>
  186. #include "dht11.h"
  187. #include <SFE_BMP180.h>
  188. #include <Wire.h>

  189. //this example reads data from a lm35dz sensor, convert value to degree Celsius
  190. //and then post it to yeelink.net

  191. //replace 2633 3539 with ur device id and sensor id
  192. yl_device ardu(2633);
  193. yl_sensor therm(3539, &ardu);
  194. //replace first param value with ur u-apikey
  195. yl_w5100_client client;
  196. yl_messenger messenger(&client, "u-apikey", "api.yeelink.net");

  197. const int pin = 5;

  198. dht11 DHT11;   // the Object for sensor DHT11
  199. int temp; // 溫度, 因為 DHT11 只有給整數 !
  200. int humi; // 濕度, 因為 DHT11 只有給整數 !

  201. SFE_BMP180 pressure;

  202. double baseline; // baseline pressure

  203. void setup()
  204. {
  205.   Serial.begin(9600); //for output information
  206.   Serial.println("REBOOT");
  207.   byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
  208.   Ethernet.begin(mac);
  209.   Serial.println("Testing the DHT11 and dht11.h Library !");
  210.   int chk = DHT11.read(pin);
  211.   Serial.print(String("Error code=") + chk);
  212.   Serial.println(String("Humidity=") + DHT11.humidity + ", Temperature=" + DHT11.temperature);
  213.   if (pressure.begin())
  214.     Serial.println("BMP180 init success");
  215.   else
  216.   {
  217.     // Oops, something went wrong, this is usually a connection problem,
  218.     // see the comments at the top of this sketch for the proper connections.

  219.     Serial.println("BMP180 init fail (disconnected?)\n\n");
  220.     while (1); // Pause forever.
  221.   }

  222.   // Get the baseline pressure:

  223.   baseline = getPressure();

  224.   Serial.print("baseline pressure: ");
  225.   Serial.print(baseline);
  226.   Serial.println(" mb");
  227. }

  228. void loop()
  229. {
  230.   delay(2000);   // Wait 2  seconds between measurements.
  231.   int chk = DHT11.read(pin);
  232.   if (chk != 0 ) {  // 讀取 DHT11 有問題
  233.     Serial.println("DHT11 reading Error !");
  234.   } else {    // 把這行注釋掉就可以有錯也照印 !
  235.     temp = DHT11.temperature;
  236.     humi = DHT11.humidity;
  237.     Serial.print("Humidity: ");
  238.     Serial.print(humi);
  239.     Serial.print(" %\t");
  240.     Serial.println(String("Temperature: ") + temp + " oC");
  241.     double a, P;

  242.     // Get a new pressure reading:

  243.     P = getPressure();

  244.     // Show the relative altitude difference between
  245.     // the new reading and the baseline reading:

  246.     a = pressure.altitude(P, baseline);

  247.     Serial.print("relative altitude: ");
  248.     if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
  249.     Serial.print(a, 1);
  250.     Serial.print(" meters, ");
  251.     if (a >= 0.0) Serial.print(" "); // add a space for positive numbers
  252.     Serial.print(a * 3.28084, 0);
  253.     Serial.println(" feet");

  254.     delay(500);
  255.   }


  256.   double getPressure()
  257.   {
  258.     char status;
  259.     double T, P, p0, a;

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

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

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

  268.       delay(status);

  269.       // Retrieve the completed temperature measurement:
  270.       // Note that the measurement is stored in the variable T.
  271.       // Use '&T' to provide the address of T to the function.
  272.       // Function returns 1 if successful, 0 if failure.

  273.       status = pressure.getTemperature(T);
  274.       if (status != 0)
  275.       {
  276.         // Start a pressure measurement:
  277.         // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
  278.         // If request is successful, the number of ms to wait is returned.
  279.         // If request is unsuccessful, 0 is returned.

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

  285.           // Retrieve the completed pressure measurement:
  286.           // Note that the measurement is stored in the variable P.
  287.           // Use '&P' to provide the address of P.
  288.           // Note also that the function requires the previous temperature measurement (T).
  289.           // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
  290.           // Function returns 1 if successful, 0 if failure.

  291.           status = pressure.getPressure(P, T);
  292.           if (status != 0)
  293.           {
  294.             return (P);
  295.           }
  296.           else Serial.println("error retrieving pressure measurement\n");
  297.         }
  298.         else Serial.println("error starting pressure measurement\n");
  299.       }
  300.       else Serial.println("error retrieving temperature measurement\n");
  301.     }
  302.     else Serial.println("error starting temperature measurement\n");
  303.   }// if..else..
  304. } // loop(
复制代码
帮我把W5100的代码改成可以上传至yeelink的代码可以吗?
回复

使用道具 举报

 楼主| 发表于 2016-1-29 16:21:09 | 显示全部楼层
怎么多人看就帮我修改一下吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-1-29 17:29:38 | 显示全部楼层
有人吗?谁来帮帮我啊。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 17:27 , Processed in 0.058548 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表