Got it.
I replaced
sprintf(buf, "/GrabData/New/?MCID=%s&Amps1=%.1f\n",s,Amps1);
with
sprintf(buf, "/GrabData/New/?MCID=%s&Amps1=%.1f\n",s.c_str(),Amps1);
Got it.
I replaced
sprintf(buf, "/GrabData/New/?MCID=%s&Amps1=%.1f\n",s,Amps1);
with
sprintf(buf, "/GrabData/New/?MCID=%s&Amps1=%.1f\n",s.c_str(),Amps1);
This is a dangerous thing to do tho' - I'm not even sure this can build at all - I expect you have changed the declaration of s
along with the code.
Strings
are no char *
or const char *
but have an cast operator (const char*)
overload that makes your first line valid code, but s
is not a String
object anymore, so you shouldn't (and supposedly can't even) call StringClass
methods on it.
You should not even rely on const char* s = someString.c_str();
or const char* s = (const char*)someString;
to keep up with any change of someString
or to be const
either.
As long someString
stays in place, you might see changes reflected in s
, but once someString
gets relocated due to growing out of its current heap position s
will reference freed space, which might get invalidated (possibly causing a hard fault) or taken up by a subsequently created different heap variable.
Good catch yes I also updated the āconst char* s = System.deviceID();ā to
double Amps1 = 21;
double Amps2 = 22;
String s = System.deviceID();
char buf[50];
void setup() {
Serial.begin(9600);
}
void loop() {
sprintf(buf, "/GrabData/New/?MCID=%s&Amps1=%.1fAmps2=%.1f\n",s.c_str(),Amps1,Amps2);
Serial.print(buf);
delay(1000);
}
Sorry to revive such an old thread, but Iām having this same problem, and I canāt quite tell if it was resolved here. I want to be able to update my request.path, and Iām trying to use format() like thisā¦
request.path.format("/weatherstation/updateweatherstation.php?ID=KCADALYC8&dateutc=now&winddir=%d&windspeedmph=%d&windgustmph=%d&softwaretype=vwsversionxx&action=updateraw HTTP/1.1", wind_dir, wind_speed, wind_gust);
But when I print out request.path it appears to be completely empty.
Any tips would be greatly appreciated.
Why do you not try it the way shown above with sprintf()
?
String::format()
does return a new String
obeject - it doesnāt alter the string in place.
I have no good excuse. It must have been too late at night. I think I saw the sprintf to buf, but didnāt see that that was then copied to request.path. Iām pretty familiar with working with char[], but not strings.
In any event, that solved it. Thanks very much.
The HttpClient.h
doesnt seem to exist for particle photon ! I get this errror when I try to compile.
testapp.ino:1:24: HttpClient.h: No such file or directory
on what device you are running your code on ?
It does exist and there is no distiction of platform as far as visibility is concerned.
What IDE are you using?
Have you actually imported the library?
I am using webide as of now.
If you post a SHARE THIS REVISION link we may be able to find the reason for your issue.
Nevermind I got it working. I inclded the HttpClient.cpp and HttpClient.h files along with my project. Thank you