我的 Wemos D1 mini 有问题。
我尝试向 2 个不同的服务器发出 2 个 Http Get 请求。我会将温度更新到外部网站和我家里的本地 Domo
ticz 服务器。第一个 http 请求有效,但另一个无效。我删除了第一个,只驱动另一个然后工作,所以地址本身没有任何问题。我想帮助理解我为错误所做的事情或代码上的错误。
也许没有好看的代码,但我是初学者。
所有 SerialPrint 都是为了试图了解正在发生和未发生的事情。
代码:
全选>
#include
#include
#include
#include
#include
#include
#include
#include
#include "SSD1306Wire.h"
ESP8266WiFiMulti WiFiMulti;
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
SSD1306Wire display(0x3C, 4, 5);
void setup() {
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("ssid", "password");
sensors.begin();
Serial.begin(9600);
Serial.println("Setup");
display.init();
display.flipScreenVertically();
}
void loop() {
Serial.println("Loop");
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
Serial.println("WIFI!");
WiFiClient client;
HTTPClient http;
// Get temperature
sensors.requestTemperatures();
float temp = 0.0;
float temp0 = sensors.getTemPCByIndex(0);
float temp1 = sensors.getTempCByIndex(1);
if (temp0 < temp1 && temp0 > -56) {
temp = temp0;
} else if (temp1 < temp0 && temp1 > -56) {
temp = temp1;
} else {
temp = temp0;
}
String url = "http://www.temperatur.nu/rapportera.php?hash=****censur*****&t=";
String url_d = "http://192.168.1.50:8080/json.htm?type=command¶m=udevice&idx=1&nvalue=0&svalue=";
Serial.println(temp);
url.concat(temp);
url_d.concat(temp);
Serial.println(url);
Serial.println(url_d);
display.clear();
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_24);
display.drawString(64, 4, String(temp0, 2));
display.drawString(64, 36, String(temp1, 2));
display.display();
if (temp > -56) {
if (http.begin(client, url)) { // HTTP
int httpCode = http.GET();
Serial.println("HTTP ?");
// httpCode will be negative on error
if (httpCode > 0) {
Serial.println("HTTP 200");
// Green
} else {
// Red
Serial.printf("HTTP :( %s n", http.errorToString(httpCode).c_str());
}
http.end();
}
}
delay(24000);
if (temp > -56) {
if (http.begin(client, url_d)) { // HTTP
//if (http.begin(client, url_d)) { // HTTP
int httpCode = http.GET();
Serial.println("HTTP GET dom");
// httpCode will be negative on error
if (httpCode > 0) {
String response = "HTTP ";
response.concat(httpCode);
response.concat(" dom");
Serial.println(response);
// Green
} else {
// Red
Serial.printf("HTTP :( %s n", http.errorToString(httpCode).c_str());
}
// http.end();
}
}
delay(35000);
}
}