Problem with multiple http get request
Posted: Sat Jul 10, 2021 8:29 am
I have a problem with a Wemos D1 mini.
I try to make 2 Http Get Request to 2 different servers. I will update the temperature to an external website and to a local Domoticz server I have at home. The first http Request works but not the other. And I remove the first and just drive the other then work it so there is nothing wrong with the address itself. I would like help understanding what I do for the wrong or what it is too wrong on the code.
Maybe no good looking code but I'm a beginner.
And all SerialPrint is for trying to understand what is happening and not happening.
I try to make 2 Http Get Request to 2 different servers. I will update the temperature to an external website and to a local Domoticz server I have at home. The first http Request works but not the other. And I remove the first and just drive the other then work it so there is nothing wrong with the address itself. I would like help understanding what I do for the wrong or what it is too wrong on the code.
Maybe no good looking code but I'm a beginner.
And all SerialPrint is for trying to understand what is happening and not happening.
Code: Select all
>
#include <Arduino.h
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#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);
}
}