Awirelesstemperature&humidityreaderandalinkedgatewaywithaNEXTIONdisplay,bothwithanArduinoesp8266
创始人
2024-11-13 10:30:23
0

一个基于Arduino esp8266的无线温度&湿度读取器和与其链接的网关,具有NEXTION显示屏。

代码示例:

无线温度&湿度读取器:

#include #include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT11

const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; const char* host = "192.168.X.XX"; // IP address of the gateway const int port = 8080;

DHT dht(DHTPIN, DHTTYPE);

void setup() { Serial.begin(115200); delay(10);

dht.begin(); WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP()); }

void loop() { float humidity = dht.readHumidity(); float temperature = dht.readTemperature(); if (isnan(humidity) || isnan(temperature)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" *C");

WiFiClient client;

if (client.connect(host, port)) { Serial.println("Connected to gateway"); String temperatureData = String(temperature, 1); String humidityData = String(humidity, 1); client.print("Temperature: "); client.println(temperatureData); client.print("Humidity: "); client.println(humidityData); } else { Serial.println("Connection failed"); }

delay(5000); }

链接的网关:

#include #include #include #include <

相关内容

热门资讯

截至发稿!智星德州插件最新版本... 截至发稿!智星德州插件最新版本更新内容详解(透视)其实存在有辅助软件(果真有挂)-哔哩哔哩一、智星德...
随着!wepoker透视最简单... 随着!wepoker透视最简单三个步骤(透视)本来有辅助修改器(确实有挂)-哔哩哔哩1、玩家可以在w...
截至发稿!pokemomo辅助... 截至发稿!pokemomo辅助工具(透视)好像真的是有辅助平台(有挂技巧)-哔哩哔哩1)pokemo...
这一问题亟待解决!拱趴大菠萝挂... 这一问题亟待解决!拱趴大菠萝挂(透视)确实真的是有辅助app(有挂分享)-哔哩哔哩小薇(辅助器软件下...
透视讲解!hhpoker可以控... 透视讲解!hhpoker可以控制吗(透视)果然是有辅助平台(有挂细节)-哔哩哔哩运hhpoker可以...
于此同时!德州真人透视脚本(透... 于此同时!德州真人透视脚本(透视)果然存在有辅助平台(有挂详情)-哔哩哔哩;1、德州真人透视脚本免费...
出现新变化!sohoo竞技联盟... 出现新变化!sohoo竞技联盟辅助器(透视)本来存在有辅助工具(存在有挂)-哔哩哔哩1、出现新变化!...
近期!epoker透视底牌(透... 近期!epoker透视底牌(透视)果然是真的辅助软件(真是有挂)-哔哩哔哩1)epoker透视底牌有...
昨日!wepoker插件程序激... 昨日!wepoker插件程序激活码(透视)原来有辅助平台(有挂详情)-哔哩哔哩1、超多福利:超高返利...
透视了解!wepoker透视破... 透视了解!wepoker透视破解版(透视)切实有辅助插件(有挂方法)-哔哩哔哩1、下载好wepoke...