9:13 am

June 13, 2019

Hello everyone,
I would like to modify this exemple to send float values from a weight sensor but i cant figure how to do so.
i read about float to char convertion and others topic on the forum but it is difficult for a newbe like me to understand it.
I would really appreciate if someone could help and show me how to do that.
Thanks
#include
const char* ssid = "XXXXXXXXXXXXX";
const char* password = "XXXXXXXXXXXXXXXXXX";
const char* host = "api.thingspeak.com";
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
else
{
Serial.println("connected !");
}
char buffer[200];
int adcValue = analogRead(A0); // here the value will be a float between 0.00 and 200.00
Serial.println(adcValue);
sprintf(buffer, "GET /update?key=XXXXXXXXXXXXXXXXXXXX&field1=%d
", adcValue);
client.print(buffer);
while (client.available()) {
String line = client.readStringUntil('
');
Serial.print(line);
}
client.stop();
Serial.println("closing connection");
delay(60000);
}
10:38 am


Moderators
March 7, 2017

Change int to float, and then look up the sprintf documentation (google) to see what flag to change the "%d" to.
I would really recommend using the ThingSpeak Communication library, it will handle much of the type conversion for you, or explicitly denote (i.e. writeFloatField())
ThingSpeak Library for Arduino and ESP8266 : https://github.com/mathworks/thingspeak-arduino
Most Users Ever Online: 166
Currently Online:
21 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457