esp8266 / esp8266/Arduino

Problems connecting to Insecure server while also connecting to a secure mqtt broker (with a certificate)

Open
#9,054 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
16.7k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

Hi All,
My problem is this: I am connecting to an MQTT broker with a certificate.. That works ok.
But then further down I have to send data to a few weather services, they accept https and http requests.
The code that is sent is correct. It worked before I added the certificate and it works when I copy and paste it int chrome.

I really dont know what to do. I have found a few similar things but none have worked or I was unsuccessful implementing them...

the sending part is basically this:

```cpp
Link = "https://www.windguru.cz/upload/api.php?";
getData = Link + getData + "uid=" + String(Station_1_uid); // WindGuru ID
getData = getData + "&salt=" + String(time); // Time
getData = getData + "&hash=" + md5.toString(); // Identification
getData = getData + "&wind_min=" + String(WindMin1ms * kKnots, 2);
if (!isnan(bmpT))
getData = getData + "&temperature=" + String(bmpT, 1); // temperature
#ifdef DataDEBUG
Serial.println(getData);
#endif
std::unique_ptr client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https; // must be declared after WiFiClient for correct destruction order, because used by http.begin(client,...)
https.begin(*client, getData); // Specify request destination
int httpCode = https.GET(); // Send the request
#ifdef DataDEBUG
Serial.println(httpCode); // ACT!
// Serial.printf("[HTTP] GET failed, error: %s\n", https.errorToString(httpCode).c_str());
#endif
if (httpCode > 0)
{ // Check the returning code
String payload = https.getString(); // Get the request response payload
#ifdef DataDEBUG
Serial.println(payload); // Print the response payload
#endif
if (mqttClient.connected() && (payload != "OK"))
mqttClient.publish((MQTT_TOPIC + "/debug").c_str(), payload.c_str());
}
https.end(); // Close connection
}
else
{
Serial.println("No wind data available");
return false; // fail
}
return true; // done
}
```

Thanks for any help.
(board ESP8266 07s)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.