本帖最后由 Wei 于 2014-6-15 15:25 编辑
20140615更新
现在代码搞定。成功上传乐联网了。我测试的时候设置的是15秒更新一次。正常使用的时候用1分钟吧。
代码部分
串口打印部分
乐联网的查看页面
实物图:USB供电,网线传数据到乐联网
- #include <SPI.h>
- #include <Ethernet.h>
- #include <LeweiClient.h>
- #include "Wire.h"
- #include <si7013.h>
- #define USERKEY "XX" // replace your key here
- #define LW_GATEWAY "01"
- LeWeiClient *lwc;
- unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
- boolean lastConnected = false; // state of the connection last time through the main loop
- const unsigned long postingInterval = 30*1000; //delay between updates to cosm.com
- int pin = 8;
- unsigned long duration;
- unsigned long starttime;
- unsigned long sampletime_ms = 30000;
- unsigned long lowpulseoccupancy = 0;
- float ratio = 0;
- double concentration = 0;
- // Pin connected to the Si7005 CS pin
- // The other I2C pins is controlled by the Wire library
- SI7013 si7013(0x40, 1);
- void setup()
- {
- Wire.begin();
- si7013.begin();
- Serial.begin(9600);
-
- lwc = new LeWeiClient(USERKEY, LW_GATEWAY);
- starttime = millis();
- }
-
-
- void loop()
- {
- Serial.print("Humidity = ");
- Serial.print(si7013.readHumidity());
- Serial.println();
- Serial.print("Temperature From Humidity Reading = ");
- Serial.print(si7013.getTempFromHumidity());
- Serial.println();
- Serial.print("Temperature = ");
- Serial.print(si7013.readTemperature());
- Serial.println();
-
- lwc->append("SD", si7013.readHumidity()*0.01);
- lwc->append("WD", si7013.readTemperature()*0.01);
- lwc->send();
- delay(15000);
- }
复制代码
码我都是东拼西凑的,大家不要见笑啊~
|