完善资料让更多小伙伴认识你,还能领取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); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1019 浏览 1 评论
562浏览 6评论
469浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
454浏览 5评论
454浏览 4评论
428浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 15:45 , Processed in 0.920232 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号