mortenx
September 30, 2020, 1:53pm
#1
i am usung gsm shield and posting to ubidots and want to change temperature to variable
how can i make temperature as variable?
sprintf(URL, "POST /api/v1.6/devices/veetase HTTP/1.1\r\nHost: things.ubidots.com\r\nX-Auth-Token: BBFF-BPww3n4f4E1AnEVGnSzly\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{\"temperature\":100}\r\n");
if (!fona.postData("things.ubidots.com", 443, "HTTPS", URL)) // Server, port, connection type, URL
What data type is temperature? Do you actually know how to use sprintf() ?
Need to see your entire sketch.
mortenx
September 30, 2020, 5:13pm
#4
I am using simcom 5320 and Adafruit_FONA.h library and want to use POST funtion to send data to web.
float temperature = analogRead(A0) * 1.23;
uint16_t battLevel = 3700;
char URL[150];
char tempBuff[16];
char battLevelBuff[16];
dtostrf(temperature, 1, 2, tempBuff);
dtostrf(battLevel, 1, 0, battLevelBuff);
sprintf(URL, "POST /api/v1.6/devices/veetase HTTP/1.1\r\nHost: things.ubidots.com\r\nX-Auth-Token: BBFF-1Mkt6C7sFnN5SVWTzROoIuTmoId\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{\"temperature\":100}\r\n");
if (!fona.postData("things.ubidots.com", 443, "HTTPS", URL)) // Server, port, connection type, URL
I'm not certain what size you really need for char URL , but see if this example does what you want.
void setup() {
Serial.begin(115200);
float temperature = 1234.56;//analogRead(A0) * 1.23;
uint16_t battLevel = 3700;
char URL[175];
char tempBuff[16];
char battLevelBuff[16];
dtostrf(temperature, 1, 2, tempBuff);
Serial.println(tempBuff);
dtostrf(battLevel, 1, 0, battLevelBuff);
//sprintf(URL, "POST /api/v1.6/devices/veetase HTTP/1.1\r\nHost: things.ubidots.com\r\nX-Auth-Token: BBFF-1Mkt6C7sFnN5SVWTzROoIuTmoId\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{\"temperature\":100}\r\n");
sprintf(URL, "POST /api/v1.6/devices/veetase HTTP/1.1\r\nHost: things.ubidots.com\r\nX-Auth-Token: BBFF-1Mkt6C7sFnN5SVWTzROoIuTmoId\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{\"temperature\":%s}\r\n", tempBuff);
Serial.print(URL);
//if (!fona.postData("things.ubidots.com", 443, "HTTPS", URL)) // Server, port, connection type, URL
}
void loop() {}
i got this working like this:
String httpbuff;
httpbuff += "POST /api/v1.6/devices/veetase HTTP/1.1\r\nHost: things.ubidots.com\r\nX-Auth-Token: BBFF-BPww3n4f4E1AnEVGnSzlyyxz8U\r\nContent-Type: application/json\r\nContent-Length: 20\r\n\r\n{\""; //{
httpbuff += "temperature";
httpbuff += "\":";
httpbuff += temperature;
httpbuff += "}\r\n";
const char *string1Char = httpbuff.c_str();
fona.postData("things.ubidots.com", 443, "HTTPS", string1Char) ;// Server, port, connection type, URL
i got this working like this:
String httpbuff;
Before adopting String concatenation as the solution to your problem, you might want to read about the possible issues created by the use of the String objects.