Arduino and Xively

Last week I created on Xively a channel "Temperature".
With a Arduino Uno, Internet shield and SHT15 sensor I see the values on Xively.
It's works well.
I have one question. The values are visible as 24.00 , 25.00 and so on.
Round whole numbers. What I will see is 24.1 , 25.3 and so on.
One number after the zero.

Below my sketch:
Who can advice / help me that the values are one number after the zero?


#include <SPI.h>
#include <SHT1x.h>
#include <Wire.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Your Xively key to let you upload data
char xivelyKey[] = "YOUR_XIVELY_API_KEY";

// Specify data and clock connections and instantiate SHT1x object
#define dataPin 6
#define clockPin 7
SHT1x sht1x(dataPin, clockPin);

// Define the strings for our datastream IDs
char sensorId[] = "Temperatuur";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(29985, datastreams, 1 /* number of datastreams */);

EthernetClient client;
XivelyClient xivelyclient(client);

void setup() {
Wire.begin();
Serial.begin(9600);

Serial.println("Starting single datastream upload to Xively...");
Serial.println();

while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}

void loop()
{
float temperature;
float humidity;

// Read values from the sensor
temperature = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();

int sensorValue = temperature;
datastreams[0].setFloat(sensorValue);

//Serial.print("Read sensor value");
Serial.print("Read sensor value", 1);
Serial.println(datastreams[0].getFloat());

Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned");
Serial.println(ret);

Serial.println();
delay(30000);
}

int sensorValue = temperature;
  datastreams[0].setFloat(sensorValue);

Why are you truncating the temperature to an int, and then using setFloat() with that int as input? No wonder you only get whole numbers.

I used the tutorial on the Xively website.

I used the tutorial on the Xively website.

So? Why not change it if it doesn't do what you want?

I don't have enough program experience too change the sketch.

jack100:
void loop()
{
float temperature;
float humidity;

// Read values from the sensor
temperature = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();

int sensorValue = temperature;
datastreams[0].setFloat(sensorValue);

There is nothing wrong with the fundamental communication, and I assume the local display is OK.

But

You have declared temperature as a float.
You then derive sensorValue as an int of temperature, thereby stripping off the decimals you had.
Then you the want to setFloat. Too late, it's an int, and once it's an int, it's an int forever.

So, try changing the line to

float sensorValue = temperature;

and see how that goes.........

So, try changing the line to

Or, skip making a copy of the value, and just use temperature in the setFloat() method call.

Hello Nick,

Your tip works!
I changed: int sensorValue = temperature;
in: float sensorValue = temperature;
Now I see for the temperature on my channel 26,21 , 26,25 and so on.
Many thanks!
I have another question.
How can I change the format from 26,21 in 26,2
One number after the zero.

Greetings,
Jack

How can I change the format from 26,21 in 26,2

Edit the library. Change what setFloat() does.

jack100:
How can I change the format from 26,21 in 26,2
One number after the zero.

If you succeed at that, you're a better man than I, Gunga Din.......

I recognise that temperatures to two places are rarely essential but concluded that was something best left alone there, or truncated in the archived Excel file instead - if needed.

This is because, not only are you fiddling with the local maths for a doubtful end, but you are also changing the nature of the datastream to xively. I would rather not rock the boat on that particular lake.

If you really feel you must do this, you need somebody who really knows what they are doing to point you in exactly the right direction, and show you exactly what to do, how to do it, and what tools to do it with. Otherwise, don't bother.

Further to the previous, I believe that using the line

float sensorValue = sht1x.readTemperatureC();

instead of deriving "temperature", makes far more sense and avoids a step on the path to confusion, but I have not done it myself. I have never understood why the code does it that way. The values "temperature" and "humidity" are redundant, apparently just for human consumption.

I can't change the format from two number after the zero in one number after the zero. But it's OK.
I have added an second channel "Humidity".
Now I am satisfied with the results.

https://xively.com/feeds/29985

Jack

jack100:
But it's OK.

Looks pretty good..........!

You will also note that it looks pretty much like anybody else's. I'm sure it is possible, but I don't recall ever seeing data to one dp.

https://xively.com/feeds/83153