完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我尝试发送 HTTP 请求,但它失败了
HTTP 代码返回 -1 尽管 URL 在 Postman 上成功运行并且 Wifi 成功连接 我正在使用 WIFI 管理器并且它成功连接到网络 注意:mysite2020 是一个例子,但我的主机在 POSTMAN 上运行良好,并且在数据库中发布了数据 这是我的代码 代码:全选#include #include #include #include #include #include IPAddress staticIP750_100(192,168,1,16); IPAddress gateway750_100(192,168,1,1); IPAddress subnet750_100(255,255,255,0); HTTPClient http; #define ONE_WIRE_BUS 2 // DS18B20 on NodeMCU pin D4 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DS18B20(&oneWire); float temp_0; const char* host = "http://mysite2020.info"; void setup() { Serial.begin(115200); WiFiManager wifimanger ; DS18B20.begin(); Wire.begin(D2, D1) WiFi.mode(WIFI_STA); wifimanger.autoConnect("Inlet Device","12345"); while ((!(WiFi.status() == WL_CONNECTED))){ delay(300); Serial.println("..."); } Serial.println("WiFi connected"); WiFi.config(staticIP750_100, gateway750_100, subnet750_100); WiFi.hostname("Inlet Device") ; delay(3000); Serial.println("Welcome To Device No : 1"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Your Gateway is : "); Serial.println((WiFi.gatewayIP().toString().c_str())); Serial.println("Your Hostname is : "); Serial.println((WiFi.hostname())); delay(3000); Serial.println("Welcome to my Project!"); delay(3000); } void loop() { 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; } Serial.print("Requesting URL: "); sendtemp (); } void sendtemp () { temp_0=23.26; String url = "http://mysite2020.info/Api/insert_mssqlserver.php?Reading=" + String(temp_0); Serial.println(url); http.begin(url); http.addHeader("Content-Type", "application/x-www-form-urlencoded"); auto httpCode = http.GET(); Serial.println(httpCode); //Print HTTP return code String payload = http.getString(); Serial.println(payload); //Print request response payload http.end(); //Close connection Serial.println(); Serial.println("closing connection"); delay(500); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
528浏览 6评论
438浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
425浏览 5评论
422浏览 4评论
398浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-7 23:00 , Processed in 0.790396 second(s), Total 77, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号