이것은 일반적인 질문이라는 것을 알고 있지만 사실은 모든 코드가 다릅니다. 때로는 개념을 코드에 적용하기가 어렵고 작동하지 않습니다. 그러니 제발 도와주세요.이 코드에 무슨 문제가 있습니까? GitHub에서 가져 왔습니다. 약간의 작업을 수행하기 전에 먼저 컴파일하려고합니다. 수정하면 온도 및 습도 데이터를 ThingSpeak 클라우드 서버로 보냅니다.

#include <DHT.h> // Including library for dht #include <ESP8266WiFi.h> String api_key = "YOUR API KEY"; // Enter your Write API key from ThingSpeak const char *ssid = "YOUR WIFI SSID"; // replace with your wifi ssid and wpa2 key const char *pass = "YOUR WIFI PASSWORD"; const char* server = "api.thingspeak.com"; #define DHTPIN 1 // pin where the dht11 is connected DHT dht; WiFiClient client; void setup() { Serial.begin(115200); delay(10); pinMode(2, OUTPUT); digitalWrite(2, 0); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); } void loop() { int chk = DHT.read(DHTPIN); float hum = DHT.humidity; float temp = DHT.temperature; if (isnan(hum) || isnan(temp)) { Serial.println("Failed to read from DHT sensor!"); return; } if (client.connect(server, 80)) { // "184.106.153.149" or api.thingspeak.com String data_to_send = api_key; data_to_send += "&field1="; data_to_send += hum; data_to_send += "&field2="; data_to_send += temp; data_to_send += "\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: " + api_key + "\n"); client.print("Content-Type: application/x-www-form- urlencoded\n"); client.print("Content-Length: "); client.print(data_to_send.length()); client.print("\n\n"); client.print(data_to_send); delay(1000); Serial.print("Temperature: "); Serial.print(temp); Serial.print(" degrees Celcius, Humidity: "); Serial.print(hum); Serial.println("%. Send to Thingspeak."); } client.stop(); Serial.println("Waiting..."); // ThingSpeak needs minimum 15 sec delay between updates, I"ve set it to 30 seconds delay(10000); } 

컴파일 할 때이 오류가 발생합니다.

 Arduino: 1.8.10 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200" C:\Users\Agent 96\Desktop\thingspeak\thingspeak.ino: In function "void loop()": thingspeak:37:20: error: expected primary-expression before "." token int chk = DHT.read(DHTPIN); ^ thingspeak:38:22: error: expected primary-expression before "." token float hum = DHT.humidity; ^ thingspeak:39:23: error: expected primary-expression before "." token float temp = DHT.temperature; ^ Multiple libraries were found for "DHT.h" Used: C:\Users\Agent Not used: C:\Users\Agent Multiple libraries were found for "ESP8266WiFi.h" Used: C:\Users\Agent exit status 1 expected primary-expression before "." token This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. 

좀 도와주세요. 저는 초보자입니다.

답변

DHT를 정의했습니다. 따라서 “DHT를 dht로 바꿔야합니다. 그러면”계속 진행할 수 있습니다.

답변

loop () 바로 뒤의 세 줄을 다음과 같이 변경합니다.

 int chk = dht.read(DHTPIN); float hum = dht.humidity; float temp = dht.temperature; 

DHT “를 소문자로 변환합니다. DHT는 클래스이고 dht는 DHT 클래스의 객체입니다.

또한 DHT.h 및 Esp8266WiFi.h 라이브러리의 여러 사본이 있습니다. . Arduino 코드가있는 cuurent 디렉토리와 Documents-> Arduino-> Libraries 디렉토리. 이러한 라이브러리는 Documents-> Arduino-> Libraries 디렉토리에 있어야합니다.

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다