我想從我的 nodemcu 向本地主機服務器發送 HTTP GET 請求。nodemcu 和我的筆記本電腦都連接到同一個 Wifi 網絡。雖然 nodemcu 連接到網絡,但它不會發送請求。我嘗試手動發送請求并使用“郵遞員”,然后就可以了。所以我認為問題出在 nodemcu 代碼或設備上。歡迎任何想法。#include <ESP8266WiFi.h>#include <WiFiClient.h> #include <ESP8266WebServer.h>#include <ESP8266HTTPClient.h>/* Set these to your desired credentials. */const char *ssid = "******"; //ENTER YOUR WIFI SETTINGSconst char *password = "****";//Web/Server address to read/write from //website or IP address of server//=======================================================================// Power on setup//=======================================================================void setup() { delay(1000); Serial.begin(115200); WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect) delay(1000); WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot WiFi.begin(ssid, password); //Connect to your WiFi router Serial.println(""); Serial.print("Connecting"); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } //If connection successful show IP address in serial monitor Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP}//=======================================================================// Main Program Loop//=======================================================================void loop() { HTTPClient http; //Declare object of class HTTPClient String ADCData, station, getData, Link; int adcvalue=253; //Read Analog value of LDR ADCData = String(adcvalue); //String to interger conversion station = "B";
2 回答

POPMUISE
TA貢獻1765條經驗 獲得超5個贊
localhost 是“自我”的簡寫。您告訴 NodeMCU 將請求發送給它自己,盡管它甚至可能不理解 localhost。您需要使用您嘗試向其發送請求的計算機的實際名稱或 IP 地址。Localhost 永遠不會像您在此處嘗試使用它的方式工作(從一臺計算機向另一臺計算機發送請求)。
- 2 回答
- 0 關注
- 245 瀏覽
添加回答
舉報
0/150
提交
取消