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 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

浅谈mysql的sql_mode可能会限制你的查询

《浅谈mysql的sql_mode可能会限制你的查询》本文主要介绍了浅谈mysql的sql_mode可能会限制你的查询,这个问题主要说明的是,我们写的sql查询语句违背了聚合函数groupby的规则... 目录场景:问题描述原因分析:解决方案:第一种:修改后,只有当前生效,若是mysql服务重启,就会失效;

MySQL多列IN查询的实现

《MySQL多列IN查询的实现》多列IN查询是一种强大的筛选工具,它允许通过多字段组合快速过滤数据,本文主要介绍了MySQL多列IN查询的实现,具有一定的参考价值,感兴趣的可以了解一下... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析与优化1.

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解

C++常见容器获取头元素的方法大全

《C++常见容器获取头元素的方法大全》在C++编程中,容器是存储和管理数据集合的重要工具,不同的容器提供了不同的接口来访问和操作其中的元素,获取容器的头元素(即第一个元素)是常见的操作之一,本文将详细... 目录一、std::vector二、std::list三、std::deque四、std::forwa

使用Python高效获取网络数据的操作指南

《使用Python高效获取网络数据的操作指南》网络爬虫是一种自动化程序,用于访问和提取网站上的数据,Python是进行网络爬虫开发的理想语言,拥有丰富的库和工具,使得编写和维护爬虫变得简单高效,本文将... 目录网络爬虫的基本概念常用库介绍安装库Requests和BeautifulSoup爬虫开发发送请求解

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Python如何获取域名的SSL证书信息和到期时间

《Python如何获取域名的SSL证书信息和到期时间》在当今互联网时代,SSL证书的重要性不言而喻,它不仅为用户提供了安全的连接,还能提高网站的搜索引擎排名,那我们怎么才能通过Python获取域名的S... 目录了解SSL证书的基本概念使用python库来抓取SSL证书信息安装必要的库编写获取SSL证书信息