SHT30通过blinker获取温湿度,小爱同学查询温湿度

2023-11-11 01:40

本文主要是介绍SHT30通过blinker获取温湿度,小爱同学查询温湿度,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

功能介绍:1、通过Blinker读取和统计温湿度历史数据;2、小爱同学查询温湿度;
硬件:SHT30传感器、ESP8266
程序介绍:第一部分为blinker界面配置(可复制到blinker APP内,直接配置界面);第二部分为SHT3x.h库的内容;第三部分为arduino编译的程序(如果没有库,复制命名为SHT3x.h然后放在和arduino程序同一个文件夹里),第三部分为blinker界面配置(可复制到blinker APP内,直接配置界面)
 


界面配置:
{¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨num¨¨t0¨¨温度¨¨ico¨¨fad fa-thermometer-three-quarters¨¨clr¨¨#389BEE¨¨min¨É¨max¨¤o¨uni¨¨°C¨¨bg¨É¨cols¨Í¨rows¨Ë¨key¨¨temp¨´x´É´y´Ñ¨speech¨|÷¨lstyle¨Ê}{ßAßBßC¨湿度¨ßE¨fad fa-humidity¨ßGßHßIÉßJ¢1cßK´%´ßMÉßNÍßOËßP¨humi¨´x´Í´y´ÑßR|÷ßSÊ}{ßA¨cha¨ßMɨsty¨¨line¨ßG¨#EA0909¨¨sty1¨ßY¨clr1¨¨#076EEF¨¨sty2¨ßY¨clr2¨ßHßNÑßOÍßPßQ´x´É´y´¤AßR|÷¨key2¨´´¨key0¨ßQßCßD¨t1¨ßT¨key1¨ßVßSÊ}÷¨actions¨|¦¨cmd¨¦¨switch¨‡¨text¨‡¨on¨¨打开?name¨¨off¨¨关闭?name¨—÷¨triggers¨|{¨source¨ßl¨source_zh¨¨开关状态¨¨state¨|ßnßp÷¨state_zh¨|¨打开¨¨关闭¨÷}÷}

库文件:<SHT3x.h>

/*Arduino library for Sensirion temperature and humidity sensors SHT30, SHT31 & SHT35.the heavy version.Check for /examples for examples of different use cases.The datasheet I followed is:https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdfFor more simple version check the SimpleSHT3x library.The constructor structure:SHT3x(	int Address = 0x44, //I2C device address, 0x44 or 0x45ValueIfError Value = Zero, //What to return in case of errors. Zero or PrevValueuint8_t HardResetPin = 255, //Number of pin RESET connected to (input from 100 to 255 if not used)SHT3xSensor SensorType = SHT30, //Sensor type, SHT30, SHT31 or SHT35.SHT3xMode Mode=Single_HighRep_ClockStretch //Operation mode , look for "enum SHT3xMode"); Supports:Temperature data at Celsius, Kelvin and Fahrenheit scales.Relative humidity data.Absolute humidity data at Torr, mm Hg, Pa, bar, technical and standard atmosphere, psi scales.Data integrity (by CRC8 algorithm) (datasheet/section 4.12).Temperature, relative and absolute humidity tolerances (in dependence from measured values)Calibration (linear) of temperature and humidity data by factors or by reverse sensor values (2 points)Heater On/Off (integrated to SHT3x sensor) (datasheet/section 4.10)Different sensor actions modes (datasheet/section 4.3)Reset: soft (I2C) and hard (by corresponding pin) (datasheet/section 4.9)Do not supports:Action in periodic mode (datasheet/section 4.5)Interrupts (datasheet/section 3.5)Note 1: by default, the data from sensor updates not faster, than 2 times a second.For faster update use SetUpdateInterval(uint32_t UpdateIntervalMillisec); but do not exceed the datasheet values (10 measurments per second (100 ms)) because of sensor self-heating (datasheet/section 4.5, at the end of Table 9)Note 2: The sensor type affects the tolerance values only. Created by Risele for everyone's use (profit and non-profit).ALL THESE WOR_DSARE YOURS EXCEPTRISELEATTEMPT NOnamechangING THEREUSE THEM TOGETHERUSE THEM IN PEACE*/#ifndef SHT3x_h#define SHT3x_h//Arduino standart libraries#if defined(ARDUINO) && ARDUINO >= 100#include "Arduino.h"#else#include "WProgram.h"#endif //Arduino I2C/TWI library#include <Wire.h>//For calculating the tolerance of absolute humidity#include <math.h> class SHT3x{public:enum ValueIfError //Define, what to return in case of error: Zero or previous value{Zero,PrevValue};enum SHT3xMode{Single_HighRep_ClockStretch,Single_MediumRep_ClockStretch,Single_LowRep_ClockStretch,Single_HighRep_NoClockStretch,Single_MediumRep_NoClockStretch,Single_LowRep_NoClockStretch	};enum SHT3xSensor{SHT30,SHT31,SHT35};enum TemperatureScale{Cel,Far,Kel};enum AbsHumidityScale{mmHg,Torr, 	//same as mm HgPa,Bar,At,	 	//Techical atmosphereAtm,	//Standart atmospheremH2O,psi,};struct CalibrationPoints{float First;float Second;};struct CalibrationFactors{CalibrationFactors():Factor(1.), Shift(0.){}float Factor;float Shift;};SHT3x(	int Address = 0x44,ValueIfError Value = Zero,uint8_t HardResetPin = 255,SHT3xSensor SensorType = SHT30,SHT3xMode Mode=Single_HighRep_ClockStretch);void Begin();void UpdateData();float GetTemperature(TemperatureScale Degree = Cel);float GetRelHumidity();float GetAbsHumidity(AbsHumidityScale Scale = Torr);float GetTempTolerance(TemperatureScale Degree = Cel, SHT3xSensor SensorType = SHT30);float GetRelHumTolerance(SHT3xSensor SensorType = SHT30);float GetAbsHumTolerance(AbsHumidityScale Scale = Torr, SHT3xSensor SensorType = SHT30);uint8_t GetError();void SetMode(SHT3xMode Mode = Single_HighRep_ClockStretch);void SetTemperatureCalibrationFactors(CalibrationFactors TemperatureCalibration);void SetRelHumidityCalibrationFactors(CalibrationFactors RelHumidityCalibration);void SetTemperatureCalibrationPoints(CalibrationPoints SensorValues, CalibrationPoints Reference);void SetRelHumidityCalibrationPoints(CalibrationPoints SensorValues, CalibrationPoints Reference);void SoftReset();void HardReset();void HeaterOn();void HeaterOff();void SetAddress(uint8_t NewAddress);void SetUpdateInterval(uint32_t UpdateIntervalMillisec);void SetTimeout(uint32_t TimeoutMillisec);private:float _TemperatureCeil;float _RelHumidity;bool _OperationEnabled 	= false;uint8_t _HardResetPin;ValueIfError _ValueIfError;uint8_t _MeasLSB; 	//Data read command, Most Significant Byte uint8_t _MeasMSB; 	//Data read command, Most Significant Byte uint8_t _Address;SHT3xSensor _SensorType;uint32_t _UpdateIntervalMillisec = 500;uint32_t _LastUpdateMillisec = 0;uint32_t _TimeoutMillisec = 100;void SendCommand(uint8_t MSB, uint8_t LSB);bool CRC8(uint8_t MSB, uint8_t LSB, uint8_t CRC);float ReturnValueIfError(float Value);void ToReturnIfError(ValueIfError Value);CalibrationFactors _TemperatureCalibration;CalibrationFactors _RelHumidityCalibration;/* * 	Factors for poly for calculating absolute humidity (in Torr):*	P = (RelativeHumidity /100%) * sum(_AbsHumPoly[i]*T^i)*	where P is absolute humidity (Torr/mm Hg),*	T is Temperature(Kelvins degree) / 1000,* 	^ means power.*	For more data, check the NIST chemistry webbook:*	http://webbook.nist.gov/cgi/cbook.cgi?ID=C7732185&Units=SI&Mask=4&Type=ANTOINE&Plot=on#ANTOINE*/float _AbsHumPoly[6] ={-157.004, 3158.0474, -25482.532, 103180.197, -209805.497, 171539.883}; enum Errors{noError 		= 0,Timeout 		= 1,DataCorrupted 	= 2,WrongAddress	= 3,//I2C errorsTooMuchData 	= 4,AddressNACK 	= 5,DataNACK 		= 6,OtherI2CError 	= 7,UnexpectedError = 8} _Error;void I2CError(uint8_t I2Canswer);};
#endif //SHT3x_h

 arduino编译程序:

/*
*SHT30 通过I2C接口测量温湿度,ESP8266的D1与SHT30的SCL相连、D2与SDA相连
*/
#define BLINKER_WIFI
#define BLINKER_ESP_SMARTCONFIG    //Smartconfig手机配网用这段,代码写入注释这一条
#define BLINKER_WITHOUT_SSL //非SSL加密通信接入,省堆栈
#define BLINKER_MIOT_SENSOR#include <Blinker.h>
#include <SHT3x.h>
SHT3x Sensor;  //默认传感器类型为SHT30char auth[] = "Blinker APP key";  //blinker账户生产的密码,小爱同学必须选用阿里云
//代码配网用下面这两段
//char ssid[] = "WIFI ssid";   //WiFi账号
//char pswd[] = "WiFi pswd";   //WiFi密码//定义blinker软件内数据组件键名分别为:humi、temp
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");float humi_read, temp_read;//小米小爱状态回调函数
void miotQuery(int32_t queryCode)
{BLINKER_LOG("MIOT Query codes: ", queryCode);int hVal = humi_read;    //多次测试湿度须为整数型switch (queryCode){case BLINKER_CMD_QUERY_ALL_NUMBER :BLINKER_LOG("MIOT Query All");BlinkerMIOT.temp(temp_read);BlinkerMIOT.humi(hVal);BlinkerMIOT.print();break;default :BlinkerMIOT.temp(100);BlinkerMIOT.humi(100);BlinkerMIOT.print();break;}
}void heartbeat()
{TEMP.print(temp_read);HUMI.print(humi_read);
}void dataStorage()
{
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("humi", humi_read);
}
void setup()
{//调试程序Serial.begin(115200);BLINKER_DEBUG.stream(Serial);Sensor.Begin();   //初始化温湿度传感器pinMode(LED_BUILTIN, OUTPUT);digitalWrite(LED_BUILTIN, LOW);Blinker.begin(auth);              //手机配网用这段//Blinker.begin(auth, ssid, pswd); //代码配网用这段Blinker.attachHeartbeat(heartbeat);Blinker.attachDataStorage(dataStorage);//注册小爱同学状态回调函数BlinkerMIOT.attachQuery(miotQuery);
}void loop()
{Blinker.run();Sensor.UpdateData();  //更新传感器数据temp_read = Sensor.GetTemperature();  //读取温度humi_read = Sensor.GetRelHumidity();//调试窗口输出if (isnan(temp_read) || isnan(humi_read)){BLINKER_LOG("Failed to read from SHT sensor!");}else{BLINKER_LOG("Humidity: ", humi_read, " %");BLINKER_LOG("Temperature: ", temp_read, " °C");}Blinker.delay(1000);}

 

这篇关于SHT30通过blinker获取温湿度,小爱同学查询温湿度的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/386688

相关文章

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

Mybatis中的like查询

<if test="templateName != null and templateName != ''">AND template_name LIKE CONCAT('%',#{templateName,jdbcType=VARCHAR},'%')</if>

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

JS和jQuery获取节点的兄弟,父级,子级元素

原文转自http://blog.csdn.net/duanshuyong/article/details/7562423 先说一下JS的获取方法,其要比JQUERY的方法麻烦很多,后面以JQUERY的方法作对比。 JS的方法会比JQUERY麻烦很多,主要则是因为FF浏览器,FF浏览器会把你的换行也当最DOM元素。 <div id="test"><div></div><div></div

京东物流查询|开发者调用API接口实现

快递聚合查询的优势 1、高效整合多种快递信息。2、实时动态更新。3、自动化管理流程。 聚合国内外1500家快递公司的物流信息查询服务,使用API接口查询京东物流的便捷步骤,首先选择专业的数据平台的快递API接口:物流快递查询API接口-单号查询API - 探数数据 以下示例是参考的示例代码: import requestsurl = "http://api.tanshuapi.com/a

vcpkg子包路径批量获取

获取vcpkg 子包的路径,并拼接为set(CMAKE_PREFIX_PATH “拼接路径” ) import osdef find_directories_with_subdirs(root_dir):# 构建根目录下的 "packages" 文件夹路径root_packages_dir = os.path.join(root_dir, "packages")# 如果 "packages"

DAY16:什么是慢查询,导致的原因,优化方法 | undo log、redo log、binlog的用处 | MySQL有哪些锁

目录 什么是慢查询,导致的原因,优化方法 undo log、redo log、binlog的用处  MySQL有哪些锁   什么是慢查询,导致的原因,优化方法 数据库查询的执行时间超过指定的超时时间时,就被称为慢查询。 导致的原因: 查询语句比较复杂:查询涉及多个表,包含复杂的连接和子查询,可能导致执行时间较长。查询数据量大:当查询的数据量庞大时,即使查询本身并不复杂,也可能导致

oracle11.2g递归查询(树形结构查询)

转自: 一 二 简单语法介绍 一、树型表结构:节点ID 上级ID 节点名称二、公式: select 节点ID,节点名称,levelfrom 表connect by prior 节点ID=上级节点IDstart with 上级节点ID=节点值 oracle官网解说 开发人员:SQL 递归: 在 Oracle Database 11g 第 2 版中查询层次结构数据的快速

Weex入门教程之4,获取当前全局环境变量和配置信息(屏幕高度、宽度等)

$getConfig() 获取当前全局环境变量和配置信息。 Returns: config (object): 配置对象;bundleUrl (string): bundle 的 url;debug (boolean): 是否是调试模式;env (object): 环境对象; weexVersion (string): Weex sdk 版本;appName (string): 应用名字;