完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我有以下代码。我需要执行以下操作:
读取温度和湿度,保存到 EEPROM,进入深度睡眠,10 秒后唤醒。(所有这些都没有启用 Wifi) 当 EEPROM 已满时,我想打开/连接 Wifi 并从 EEPROM 发送数据。我的问题是是否有人可以帮助我编写/读取我需要的 EEPROM 代码? 代码:全选// Import required libraries #include "ESP8266WiFi.h" #include "DHT.h" #include // the current address in the EEPROM (i.e. which byte // we're going to write to next) int addr = 0; // WiFi parameters const char* ssid = "xxxx"; const char* password = "xxxx"; // Pin #define DHTPIN 2 // Use DHT11 sensor #define DHTTYPE DHT11 // Initialize DHT sensor DHT dht(DHTPIN, DHTTYPE, 15); // Host const char* host = "dweet.io"; void setup() { EEPROM.begin(512); // Start Serial Serial.begin(115200); delay(10); // Init DHT dht.begin(); // We start by connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); 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() { Serial.print("Connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; const int httpPort = 80; if (!client.connect(host, httpPort)) { Serial.println("connection failed"); return; } // Reading temperature and humidity int h = dht.readHumidity(); // Read temperature as Celsius int t = dht.readTemperature(); // This will send the request to the server client.print(String("GET /dweet/for/XXXXXX?temperature=") + String(t) + "&humidity=" + String(h) + " HTTP/1.1rn" + "Host: " + host + "rn" + "Connection: closernrn"); delay(30); // Read all the lines of the reply from server and print them to Serial while(client.available()){ String line = client.readStringUntil('r'); Serial.print(line); } Serial.println(); Serial.println("closing connection"); // Repeat every 10 seconds EEPROM.write(addr, t); ESP.deepSleep(10000000, WAKE_RF_DEFAULT); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
448 浏览 0 评论
971 浏览 0 评论
1695 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1349 浏览 1 评论
1246 浏览 1 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1272浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
938浏览 3评论
2370浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2556浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1066浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-9 03:30 , Processed in 0.636628 second(s), Total 71, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1163
