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

相关文章

房产证 不动产查询

陕西政务服务网(便民服务)陕西政务服务网(手机版?更直观)不动产权证书|不动产登记证明(电子证照)商品房合同备案查询权利人查询

通过高德api查询所有店铺地址信息

通过高德api查询所有店铺地址电话信息 需求:通过高德api查询所有店铺地址信息需求分析具体实现1、申请高德appkey2、下载types city 字典值3、具体代码调用 需求:通过高德api查询所有店铺地址信息 需求分析 查询现有高德api发现现有接口关键字搜索API服务地址: https://developer.amap.com/api/webservice/gui

SQL Server中,查询数据库中有多少个表,以及数据库其余类型数据统计查询

sqlserver查询数据库中有多少个表 sql server 数表:select count(1) from sysobjects where xtype='U'数视图:select count(1) from sysobjects where xtype='V'数存储过程select count(1) from sysobjects where xtype='P' SE

【青龙面板辅助】JD商品自动给好评获取京豆脚本

1.打开链接 开下面的链接进入待评价商品页面 https://club.jd.com/myJdcomments/myJdcomments.action?sort=0 2.登陆后执行脚本 登陆后,按F12键,选择console,复制粘贴以下代码,先运行脚本1,再运行脚本2 脚本1代码 可以自行修改评价内容。 var content = '材质很好,质量也不错,到货也很快物流满分,包装快递满

Java中如何优化数据库查询性能?

Java中如何优化数据库查询性能? 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们将深入探讨在Java中如何优化数据库查询性能,这是提升应用程序响应速度和用户体验的关键技术。 优化数据库查询性能的重要性 在现代应用开发中,数据库查询是最常见的操作之一。随着数据量的增加和业务复杂度的提升,数据库查询的性能优化显得尤为重

BD错误集锦9——查询hive表格时出错:Wrong FS: hdfs://s233/user/../warehouse expected: hdfs://mycluster

集群环境描述:HDFS集群处于HA模式下,同时启动了YARN\JN\KAFKA\ZK。 现象: FAILED: SemanticException Unable to determine if hdfs://s233/user/hive/warehouse/mydb.db/ext_calllogs_in_hbase is encrypted: java.lang.IllegalArgument

MybatisPlus指定字段查询

一,上代码 QueryWrapper<Device> queryWrapper = Wrappers.query();queryWrapper.select("project_id as projectId,count(device_id) as total").in("project_id",projectIds).isNotNull("project_id").eq("del_flag",B

温湿度采集及OLED显示

目录 软件I2C和硬件I2C每隔2秒钟采集一次温湿度数据,显示到OLED上,同时通过串口发送到上位机的“串口助手”软件 软件I2C和硬件I2C "I2C"代表Inter-Integrated Circuit,是一种用于在数字电路之间进行通信的串行通信协议。软件I2C和硬件I2C是两种实现这种协议的方式。 软件I2C是通过软件来模拟I2C通信协议的实现方式。在这种情况下,微控制

ORACLE 、达梦 数据库查询指定库指定表的索引信息

在Oracle数据库中,索引是一种关键的性能优化工具,通过它可以加快数据检索速度。在本文中,我们将深入探讨如何详细查询指定表的索引信息,以及如何利用系统视图和SQL查询来获取这些信息。 索引在数据库中的重要性 索引是一种数据结构,用于加快数据库表中数据的检索速度。它类似于书籍的目录,可以帮助数据库引擎快速定位数据行,特别是在大型数据集合下,其作用尤为显著。 查询指定表的索引信息 在Orac

Spring 内部类获取不到@Value配置值问题排查(附Spring代理方式)

目录 一、实例问题 1、现象 2、原因 3、解决 二、Spring的代理模式 1、静态代理(Static Proxy) 1)原理 2)优缺点 3)代码实现 2、JDK动态代理(JDK Dynamic Proxy) 1)原理 2)优缺点 3)代码实现 3、cglib 代理(Code Generation Library Proxy) 1)原理 2)优缺点 3)代码实