One Value Always Reports As Zero?


#1

Hi Chaps,
In the code below temp1 and hum report correct values to the exosite portal but temp2 reports zero.
I have a DS18B20 and a DHT11 connected to an arduino uno with an ether shield attached.
Can anyone tell me why ?
Sorry for the poor code formatting,shows fine in notepad++
Cheers.

#include <EEPROM.h>
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Exosite.h>
#include “DHT.h”

// Pin use
#define ONEWIRE 7 //pin to use for One Wire interface
#define DHTPIN 5
DHT dht(DHTPIN, DHT11);

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

String cikData = “my-cik-entered-here”; // <-- FILL IN YOUR CIK HERE!
byte macData[] = {0xFD, 0x31, 0x0F, 0xB1, 0x60, 0x4A};

// User defined variables for Exosite reporting period and averaging samples
#define REPORT_TIMEOUT 30000 //milliseconds period for reporting to Exosite.com
#define SENSOR_READ_TIMEOUT 5000 //milliseconds period for reading sensors in loop

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() {
Serial.begin(9600);
Serial.println(“Boot”);
// Start up the OneWire Sensors library
sensors.begin();
delay(1000);
Serial.println(“Starting Exosite Temp Monitor”);
Serial.print("OneWire Digital Pin Specified: ");
Serial.println(ONEWIRE);
Ethernet.begin(macData);
// wait 3 seconds for connection
delay(3000);

}

//
// 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 temp1F;
//static float temp2F;
static float temp1C;
static float temp2C;
static float temh;
char buffer[7];
String readParam = “”;
String writeParam = “”;
String returnString = “”;

Serial.print("."); // print to show running

// Read sensor every defined timeout period
if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT) {
Serial.println();
Serial.println(“DS18B20 Requesting temperature…”);
sensors.requestTemperatures(); // Send the command to get temperatures
temp1C = sensors.getTempCByIndex(0);
Serial.print(“Celsius: “);
Serial.print(temp1C);
Serial.println(” C …DONE”);
temp1F = DallasTemperature::toFahrenheit(temp1C);
Serial.print(“Fahrenheit: “);
Serial.print(temp1F);
Serial.println(” F …DONE”);

  // Wait a few seconds between measurements.
 delay(2000);

temh = dht.readHumidity();
// Read temperature as Celsius
float temp2C = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(temh) || isnan(temp2C) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, temh);

Serial.print(“DHT Humidity: “);
Serial.print(temh);
Serial.print(” %\t”);
Serial.print(“DHT Temperature: “);
Serial.print(temp2C);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t”);
Serial.print(“DHT Heat index: “);
Serial.print(hi);
Serial.println(” *F”);

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 = "";       
writeParam = "temp1="; 

String tempValue = dtostrf(temp1C, 1, 2, buffer); 

writeParam += tempValue;    

writeParam += "&temp2="; 

tempValue = dtostrf(temp2C, 1, 2, buffer);

writeParam += tempValue;    

writeParam += "&hum="; /

String humValue = dtostrf(temh, 1, 2, buffer);

writeParam += humValue;    

//writeParam += "&message=hello"; 

if ( exosite.writeRead(writeParam, readParam, returnString)) {
  Serial.println("Exosite OK");
  if (returnString != "") {
    Serial.println("Response:");
    Serial.println(returnString);
  }
}
else {
  Serial.println("Exosite Error");
}

sendPrevTime = millis(); //reset report period timer
Serial.println("done sending.");

}
delay(1000); //slow down loop

}


#2

I’m sure you checked this, but when you print out the value of temp2C, it is not 0 in the serial debug log?
Otherwise this generally looks like it should work.


#3

I checked that yes,all 3 values are correct in the serial log.
forgot to mention that in my original post.


#4

If there was a way for you to print out writeParam, I’d be curious what it looks like.
This may be similar to what this user found. It’s been a while, so I have to think about what the actual problem is but essentially have found some issues with appending strings correctly and although it looks like it should be fine, you end up getting something unexpected. Your situation is slightly different in that I don’t think you are getting an error message, but I’d be curious if it is a similar issue.
Sending Two Datasources from Arduino to Exosite .