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

相关文章

MyBatis模糊查询报错:ParserException: not supported.pos 问题解决

《MyBatis模糊查询报错:ParserException:notsupported.pos问题解决》本文主要介绍了MyBatis模糊查询报错:ParserException:notsuppo... 目录问题描述问题根源错误SQL解析逻辑深层原因分析三种解决方案方案一:使用CONCAT函数(推荐)方案二:

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

MySQL 中的 JSON 查询案例详解

《MySQL中的JSON查询案例详解》:本文主要介绍MySQL的JSON查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

C# foreach 循环中获取索引的实现方式

《C#foreach循环中获取索引的实现方式》:本文主要介绍C#foreach循环中获取索引的实现方式,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、手动维护索引变量二、LINQ Select + 元组解构三、扩展方法封装索引四、使用 for 循环替代

MySQL索引的优化之LIKE模糊查询功能实现

《MySQL索引的优化之LIKE模糊查询功能实现》:本文主要介绍MySQL索引的优化之LIKE模糊查询功能实现,本文通过示例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录一、前缀匹配优化二、后缀匹配优化三、中间匹配优化四、覆盖索引优化五、减少查询范围六、避免通配符开头七、使用外部搜索引擎八、分

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n