float data | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
float data
No permission to create posts
June 13, 2019
9:13 am
Avatar
Peigne
New Member
Members
Forum Posts: 2
Member Since:
June 13, 2019
sp_UserOfflineSmall Offline

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);
}

June 13, 2019
10:38 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 861
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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

June 13, 2019
11:09 am
Avatar
Peigne
New Member
Members
Forum Posts: 2
Member Since:
June 13, 2019
sp_UserOfflineSmall Offline

Thanks for your answer. I'll have a look a it.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
17 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:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457