美文网首页
基于blinker——空气传感器接入小度智能音箱并显示

基于blinker——空气传感器接入小度智能音箱并显示

作者: Walk_In_Jar | 来源:发表于2019-01-10 17:36 被阅读0次

使用的是esp8266开发板+dht温湿度传感器+lcd

#define BLINKER_WIFI
#define BLINKER_DUEROS_SENSOR

#include <Blinker.h>
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //引用I2C库

//设置LCD1602设备地址,这里的地址是0x3F,一般是0x20,或者0x27,具体看模块手册
LiquidCrystal_I2C lcd(0x27, 16, 2); //d1,d2
dht DHT;//create a variable type of dht
const int DHT11_PIN = D3; //Humiture sensor attach to pin7

BlinkerNumber Number1("num-tem");//温度
BlinkerNumber Number2("num-hum");//湿度

char auth[] = "***";
char ssid[] = "***";
char pswd[] = "***";

void duerQuery(int32_t queryCode)
{
  BLINKER_LOG("DuerOS Query codes: ", queryCode);

  switch (queryCode)
  {
    case BLINKER_CMD_QUERY_AQI_NUMBER :
      BLINKER_LOG("DuerOS Query AQI");
      BlinkerDuerOS.aqi(20);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_CO2_NUMBER :
      BLINKER_LOG("DuerOS Query CO2");
      BlinkerDuerOS.co2(20);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_PM10_NUMBER :
      BLINKER_LOG("DuerOS Query PM10");
      BlinkerDuerOS.pm10(20);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_PM25_NUMBER :
      BLINKER_LOG("DuerOS Query PM25");
      BlinkerDuerOS.pm25(20);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_HUMI_NUMBER :
      BLINKER_LOG("DuerOS Query HUMI");
      BlinkerDuerOS.humi(DHT.humidity);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_TEMP_NUMBER :
      BLINKER_LOG("DuerOS Query TEMP");
      BlinkerDuerOS.temp(DHT.temperature);
      BlinkerDuerOS.print();
      break;
    case BLINKER_CMD_QUERY_TIME_NUMBER :
      BLINKER_LOG("DuerOS Query time");
      BlinkerDuerOS.time(millis());
      BlinkerDuerOS.print();
      break;
    default :
      BlinkerDuerOS.temp(20);
      BlinkerDuerOS.humi(20);
      BlinkerDuerOS.pm25(20);
      BlinkerDuerOS.pm10(20);
      BlinkerDuerOS.co2(20);
      BlinkerDuerOS.aqi(20);
      BlinkerDuerOS.time(millis());
      BlinkerDuerOS.print();
      break;
  }
}

void dataRead(const String & data)
{
  BLINKER_LOG("Blinker readString: ", data);

  Blinker.vibrate();

  uint32_t BlinkerTime = millis();
  Blinker.print(BlinkerTime);
  Blinker.print("millis", BlinkerTime);
}

void setup()
{
  lcd.init();                  // 初始化LCD
  lcd.backlight();             //设置LCD背景等亮

  Serial.begin(115200);
  BLINKER_DEBUG.stream(Serial);

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  Blinker.begin(auth, ssid, pswd);
  Blinker.attachData(dataRead);

  BlinkerDuerOS.attachQuery(duerQuery);
}

void loop()
{
  Blinker.run();
  showthlcd();
}
void showthlcd() {
D: int chk = DHT.read11(DHT11_PIN);//read the value returned from sensor
  Number1.print(DHT.temperature);
  Number2.print(DHT.humidity);
  switch (chk)//此步骤为必须,否则会出现-999.00
  {
    case DHTLIB_OK:
      //Serial.println("OK!");
      break;
    case DHTLIB_ERROR_CHECKSUM:
      //goto D;
      //Serial.print("Checksum error,\t");
      break;
    case DHTLIB_ERROR_TIMEOUT:
      goto D;
      //Serial.print("Time out error,\t");
      break;
    default:
      // goto D;
      //Serial.print("Unknown error,\t");
      break;
  }
  lcd.setCursor(0, 0);
  lcd.print("Tem:");
  lcd.print(DHT.temperature, 1); //print the temperature on lcd
  lcd.print(char(223));
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Hum:");
  lcd.print(DHT.humidity, 1);
  lcd.print(" %");
  Blinker.delay(200);
}

相关文章

网友评论

      本文标题:基于blinker——空气传感器接入小度智能音箱并显示

      本文链接:https://www.haomeiwen.com/subject/cjoarqtx.html