Go Down

Topic: Wie Nachkommanullen darstellen? (Read 1 time) previous topic - next topic


Nov 17, 2013, 08:04 pm Last Edit: Nov 18, 2013, 12:18 am by -Micky Reason: 1
Habe folgendes Script welches auch sehr gut funktioniert. Nur leider werden die Nachkommanullen weggelassen. Was muß ich machen das diese dargestellt werden?
Code: [Select]
Exosite Arduino Basic Temp Monitor 2 (updated to use Exosite library)
This sketch shows an example of sending data from a connected
sensor to Exosite. (http://exosite.com) Code was used from various
public examples including the Arduino Ethernet examples and the OneWire
Library examples found on the Arduino playground.
(OneWire Lib credits to Jim Studt, Tom Pollard, Robin James, and Paul Stoffregen)
This code keeps track of how many milliseconds have passed
and after the user defined REPORT_TIMEOUT (default 60 seconds)
reports the temperature from a Dallas Semi DS18B20 1-wire temp sensor.
The code sets up the Ethernet client connection and connects / disconnects
to the Exosite server when sending data.
- Tested with Aruduino 1.0.5
- Arduino included Ethernet Library
- Arduino included SPI Library
- Using Exosite library (2013-10-20) https://github.com/exosite-garage/arduino_exosite_library
- Using OneWire Library Version 2.0 - http://www.arduino.cc/playground/Learning/OneWire
- Using Dallas Temperature Control Library - http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_372Beta.zip
- Uses Exosite's basic HTTP API, revision 1.0 https://github.com/exosite/api/tree/master/data
- User has an Exosite account and created a device (CIK needed / https://portals.exosite.com -> Add Device)
- User has added a device to Exosite account and added a data source with alias 'temp', type 'float'

- Arduino Duemilanove or similiar
- Arduino Ethernet Shield
- Dallas Semiconductor DS18B20 1-Wire Temp sensor used in parasite power mode (on data pin 7, with 4.7k pull-up)

Version History:
- 1.0 - November 8, 2010 - by M. Aanenson
- 2.0 - July 6, 2012 - by M. Aanenson
- 3.0 - October 25, 2013 - by M. Aanenson - Note: Updated to use latest Exosite Arduino Library

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Exosite.h>

// Pin use
#define ONEWIRE 7 //pin to use for One Wire interface

// Set up which Arduino pin will be used for the 1-wire interface to the sensor
OneWire oneWire(ONEWIRE);
DallasTemperature sensors(&oneWire);

* Configuration Variables
* Change these variables to your own settings.
String cikData = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";  // <-- FILL IN YOUR CIK HERE! (https://portals.exosite.com -> Add Device)
byte macData[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};        // <-- FILL IN YOUR Ethernet shield's MAC address here.

// User defined variables for Exosite reporting period and averaging samples
#define REPORT_TIMEOUT 1800000//milliseconds  = 30 Min period for reporting to Exosite.com
#define SENSOR_READ_TIMEOUT 6000 //milliseconds  = 6 Sec period for reading sensors in loop

* End of Configuration Variables

class EthernetClient client;
Exosite exosite(cikData, &client);

// The 'setup()' function is the first function that runs on the Arduino.
// It runs completely and when complete jumps to 'loop()'
void setup() {
 // Start up the OneWire Sensors library
 byte addr[8];
 sensors.setResolution( 12 );
 Serial.println("Starting Exosite Temp Monitor");
 // wait 3 seconds for connection


// The 'loop()' function is the 'main' function for Arduino
// and is essentially a constant while loop.
void loop() {
 static unsigned long sendPrevTime = 0;
 static unsigned long sensorPrevTime = 0;
 static float tempC;
 static float tempD;
 char buffer[7];
 String readParam = "";
 String writeParam = "";
 String readParam1 = "";
 String writeParam1 = "";
 String returnString = "";  
 //Serial.print("."); // print to show running

// Read sensor every defined timeout period
 if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT) {
   Serial.println("Requesting temperature...");
   sensors.requestTemperatures(); // Send the command to get temperatures
   tempC = sensors.getTempCByIndex(0);
   tempD = sensors.getTempCByIndex(1);
   Serial.print("Celsius:    ");
   Serial.println(" C ..........DONE");
   Serial.print("Celsius:    ");
   Serial.println(" C ..........DONE");
   sensorPrevTime = millis();

 // Send to Exosite every defined timeout period
 if (millis() - sendPrevTime > REPORT_TIMEOUT) {
   Serial.println(); //start fresh debug line
   Serial.println("Sending data to Exosite...");
   readParam = ""; //nothing to read back at this time e.g. 'control&status' if you wanted to read those data sources
   readParam1 = "";
   writeParam = "temp="; //parameters to write e.g. 'temp=65.54' or 'temp=65.54&status=on'
   writeParam1 = "temp1=";
   String tempValue = dtostrf(tempC, 1, 2, buffer); // convert float to String, minimum size = 1, decimal places = 2
   //if (i>0 && tempValue[i-1]!='-') tempValue[i-1]='+';
   String tempValue1 = dtostrf(tempD, 1, 2, buffer);
   //if (i>0 && tempValue1[i-1]!='-') tempValue1[i-1]='+';
   writeParam += tempValue;    //add converted temperature String value
   writeParam1 += tempValue1;
   if ( exosite.readWrite(writeParam, readParam, returnString)) {
   if ( exosite.readWrite(writeParam1, readParam1, returnString)) {
   Serial.println("Exosite OK");
   if (returnString != "") {
   else {
     Serial.println("Exosite Error");

   sendPrevTime = millis(); //reset report period timer
   Serial.println("done sending.");
   delay(1000); //slow down loop


Das rote sind meine Änderungen, so funktioniert es bei mir immer.
Probier das mal aus.

tempC = sensors.getTempCByIndex(0);
    tempD = sensors.getTempCByIndex(1);
    Serial.print("Celsius:    ");
    Serial.println(" C ..........DONE");
     Serial.print("Celsius:    ");
    Serial.println(" C ..........DONE");



Der "width" Parameter ist die maximale Breite der gesamten Zahl, also Vor- UND Nachkommastellen


Bei der Serial Ausgabe funktioniert mein Script auch. Bei Exosite kommen die Nullen aber nicht an.


Das rote sind meine Änderungen, so funktioniert es bei mir immer.
Probier das mal aus.

tempC = sensors.getTempCByIndex(0);
    tempD = sensors.getTempCByIndex(1);
    Serial.print("Celsius:    ");
    Serial.println(" C ..........DONE");
     Serial.print("Celsius:    ");
    Serial.println(" C ..........DONE");


Weil du bei dtostrf als "width" 1 angeben hast.

Du musst die die maximale Anzahl aller Zeichen angeben. Also inklusive Vorzeichen, Vorkommastellen. Punkt, Nachkommastellen. Im Prinzip die Größe des Puffers - 1


Funktioniert nicht. Egal was ich eintrage. Bei Exosite werden die Nullen weggelassen.




(Sorry, ich erinnere mich nicht, eine der deutschen, dass ich in der High School gelernt, so ist dies eine automatische Übersetzung.)

Ich gehe davon aus, dass die Datenquelle, dass Sie schieben diese Werte auf "float" geben? Exosite Plattform speichert nicht die Nullen da die Werte als numerischer Datentyp bekommen gespeichert. Wenn Sie brauchen, die Nullen verwenden Typ "string", werden Sie verlieren die Fähigkeit, Berechnungen auf diese Werte jedoch tun.

Original English:
(Sorry I don't remember any of the German that I learned in High School so this is an automatic translation.)

I assume that the datasource that you're pushing these values to is set to type "float"? Exosite's platform doesn't store the trailing zeros since the values get stored as a numeric data type. If you need the trailing zeros use type "string", you will lose the ability to do calculations on these values however.

(I work for Exosite.)


Hi Patrick,

this means it is not possible to show trailing zeros on Exosite.



Sorry didn't see your reply until now.

The issue is that it's not possible to store the trailing zeros. If you create some widgets you can put the trailing zeros back on when you display the values there.


Go Up