-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpClient doesn't send a request #1937
Comments
Hi @qdimka, we'll look into this but as you've only just started using Sming I'd recommend moving to Sming 4.0.0 which has been released today. |
I've located the reason for the 'already freed' message, I'll submit a PR to patch that (present in 4.0 as well). However, I've yet to discover why no response is received (success or failure). |
Compiling the framework with DEBUG_VERBOSE_LEVEL=3 we get this:
The -8 error code is I'm assuming a valid connection key is required so this isn't entirely unexpected. |
Thanks, @mikee47 I've tried Sming 4.0.0 (from develop).
I've tried other sites without https, but still get the same error. |
I've got the progress. I added a port to the url. Url url;
url.Host = "api.thingspeak.com";
url.Port = 80;
url.Path = "/update";
url.Query["key"] = "WHRMN4Y50D05IK3R";
url.Query["field1"] = String(sensorValue);
Serial.println(String(url));
auto* request = thingSpeak.createRequest(url);
HttpHeaders headers;
headers[HTTP_HEADER_USER_AGENT] = _F("HttpClient/Sming");
request
->setMethod(HTTP_GET)
->setHeaders(headers)
->onRequestComplete(onDataSent);
thingSpeak.send(request);
That's enough for me. I think we can close this issue. |
Yes, this is another bug - thank you for raising this issue. You can track the progress of this in #1939. The reason the sample doesn't work is that the scheme is missing from the URL. Easily fixed by adding:
This also sets the default port (80) so without it the connection is attempted to port 0 which of course fails. Setting the URL using a regular string works OK. |
This PR addresses some inconsistencies with the `Url` class. **Ensure Url provides default port for default scheme** When building a URL the Scheme defaults to HTTP if not specified. This means the port should also default to 80, but it doesn't. For example: ``` Url url; url.Host = "api.thingspeak.com"; url.Path = "/update"; ``` This produces the correct URL text `http://api.thingspeak.com/update` with the default scheme, but `getPort()` incorrectly returns 0. See #1937 (comment), PR #1945 provided a fix but didn't actually resolve the underlying issue. **Url::toString() doesn't lowercase scheme** For example: ``` Url url; url.Scheme = "HTTP"; url.Host = "api.thingspeak.com"; url.Path = "/update"; ``` Incorrectly produces `HTTP://api.thingspeak.com/update`. **Add `Url::getQueryParameter` method** Care is required when reading query parameters as direct access to the `Query` member variable means non-existent keys get added. Therefore a `const` cast is required. This method provides a more convenient way for safely reading values, and also allows a default to be given where the value doesn't exist.
Hi, everyone.
I started using Sming a couple of days ago. It is the great tool.
But I have some problems.
I need to send the sensor data to thinkspeak.
I am using this sample.
I modified next line:
Nothing to happened after first call thinkSpeak.downloadString.
onDataSent
wasn`t called.After the next call, I got the message "Already freed".
What do I do wrong?
The text was updated successfully, but these errors were encountered: