极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10876|回复: 4

谁帮我看一下代码,谢谢

[复制链接]
发表于 2016-2-15 22:06:54 | 显示全部楼层 |阅读模式
本帖最后由 a6641 于 2016-2-15 22:10 编辑

[pre lang=""]#include <Ethernet.h>
#include <WiFi.h>
#include <SPI.h>
#include <HttpClient.h>
#include <yl_data_point.h>
#include <yl_device.h>
#include <yl_w5100_client.h>
#include <yl_wifi_client.h>
#include <yl_messenger.h>
#include <yl_sensor.h>
#include <yl_value_data_point.h>
#include <yl_sensor.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "DHT.h"
#include <math.h>

#define DHTPIN 2     // what pin we're connected to
int BH1750address = 0x23;
byte buff[2];

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);
yl_device ardu(164872);
yl_sensor generic(183023, &ardu);
yl_sensor generic(183049, &ardu);
yl_sensor generic(183050, &ardu);
yl_sensor generic(381365, &ardu);
//replace first param value with ur u-apikey
yl_w5100_client client;
yl_messenger messenger(&client, "u-apikey", "api.yeelink.net");
personal_info_dp qinqingege("personal_info");

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);  //for output information
  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
  Ethernet.begin(mac);
   bmp.begin();
  dht.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  uint16_t val=0;
  BH1750_Init(BH1750address);
  delay(200);
  if(2==BH1750_Read(BH1750address))
  {
    val=((buff[0]<<8)|buff[1])/1.2;
  }

  Serial.print("Sensor value is: ");
  Serial.println((int)val);

  return val;
}

int BH1750_Read(int address) //
{
  int i=0;
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 2);
  while(Wire.available()) //
  {
    buff = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission();
  return i;
}

void BH1750_Init(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();
  Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
   
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    float h = dht.readHumidity();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
  }
}[/code]
回复

使用道具 举报

发表于 2016-2-15 23:09:51 | 显示全部楼层
看完了
回复 支持 反对

使用道具 举报

发表于 2016-2-16 11:38:16 | 显示全部楼层
看完了 X2
回复 支持 反对

使用道具 举报

发表于 2016-2-16 15:00:47 | 显示全部楼层
不就一段代码吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-2-20 17:27:47 | 显示全部楼层
我指的是修改一下
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 23:53 , Processed in 0.086788 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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