完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在使用 NodeMCU V3 (ESP8266) 模块。我试图制作一个连接到 WiFi 并将数据上传到 ThingSpeak 的简单数据记录器。由于 NodeMCU 耗电量很大,而且不会一直使用,所以我想将其置于深度睡眠状态,直到再次需要它为止。然而,在它进入睡眠状态之后,它似乎并没有再次醒来。我根据需要将 GPIO16 连接到 RST 引脚。代码如下。
代码:全选#include #include #include #include #include #include #define LED_BULB 4 #define ONE_WIRE_BUS 0 //D1 pin of nodemcu #define DHTPIN 5 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); const char* ssid = "XXXXX"; const char* password = "XXXXX"; WiFiClient client; unsigned long myChannelNumber = XXXXX; const char * myWriteAPIKey = "XXXXX"; uint8_t temperature, humidity, dsb; void startup() { pinMode(LED_BULB, OUTPUT); digitalWrite(LED_BULB, LOW); Serial.begin(115200); dht.begin(); delay(10); // Connect to 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"); // Print the IP address Serial.println(WiFi.localIP()); ThingSpeak.begin(client); sensors.begin(); } void setup() { } void loop() { startup(); Serial.print("nnnnnnnnnnnnnnnn"); sensors.requestTemperatures(); Serial.print("DSB Temperature is: "); Serial.println(sensors.getTemPCByIndex(0)); dsb = sensors.getTempCByIndex(0); temperature = dht.readTemperature(); humidity = dht.readHumidity(); Serial.print("Temperature Value is :"); Serial.print(temperature); Serial.println("C"); Serial.print("Humidity Value is :"); Serial.print(humidity); Serial.println("%"); digitalWrite(LED_BULB, HIGH); Serial.println("Uploading DHT temp"); ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey); delay(30000); Serial.println("Uploading DHT hum"); ThingSpeak.writeField(myChannelNumber, 2, humidity, myWriteAPIKey); delay(30000); Serial.println("Uploading DS temp"); ThingSpeak.writeField(myChannelNumber, 3, dsb, myWriteAPIKey); Serial.println("Done uploading"); delay(30000); digitalWrite(LED_BULB, LOW); delay(500); digitalWrite(LED_BULB, HIGH); delay(500); digitalWrite(LED_BULB, LOW); delay(500); digitalWrite(LED_BULB, HIGH); delay(500); digitalWrite(LED_BULB, LOW); delay(500); Serial.println("Sleeping"); ESP.deepSleep(120000000); //sleeping for 120 seconds Serial.println("Waking up"); } 串行监视器上的输出如下所示。 代码:全选Connecting to XXXXX .............................................................. WiFi connected XXXXXX DSB Temperature is: 26.56 Temperature Value is :25C Humidity Value is :92% Uploading DHT temp Uploading DHT hum Uploading DS temp Done uploading Sleeping |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
540浏览 6评论
451浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
434浏览 5评论
436浏览 4评论
409浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-16 16:23 , Processed in 0.820305 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号