ChemE
Well-Known Member
FuzzeWuzze is correct. One pin on the Arduino Uno will support 5 DS18B20's no problem captrichc.
Great. Thanks. One last question. Will the coding work from the original postings.
#include <Xively.h>
#include <XivelyClient.h>
#include <XivelyDatastream.h>
#include <XivelyFeed.h>
#include <CountingStream.h>
#include <b64.h>
#include <HttpClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
//Defines for DS18B20
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Sensor1 = {0x28, 0x82, 0x03, 0x55, 0x05, 0x00, 0x00, 0xB8};
DeviceAddress Sensor2 = {0x28, 0x82, 0x03, 0x55, 0x05, 0x00, 0x00, 0xB8};
//End Defines for DS18B20
//Defines for Xively Ethernet
char xivelyKey[] = "YKTsQhH5n2bt9AXyPpFQ123gfd7jH0jTccxmAds6AvAr7aBc";
byte mac[] = {
0x00, 0x1D, 0x0D, 0x2C, 0x55, 0x3D};
EthernetClient client;
XivelyClient Xivelyclient(client);
//End Defines for Xively Ethernet
double s1 = 0;
double s2 = 0;
#define MYDELAY 5000
char sensor1Id[] = "FermSensor1";
char sensor2Id[] = "Ambient";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensor1Id, strlen(sensor1Id), DATASTREAM_FLOAT),
XivelyDatastream(sensor2Id, strlen(sensor2Id), DATASTREAM_FLOAT)};
XivelyFeed feed(633693457, datastreams, 2);
void setup(void)
{
// start serial port
Serial.begin(9600);
SetupSensors();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
}
void SetupSensors()
{
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Sensor1, 12);
sensors.setResolution(Sensor2, 12);
}
float getTemperature(DeviceAddress deviceAddress)
{
//Get temperature, convert to Fahrenheit, and return
return DallasTemperature::toFahrenheit(sensors.getTempC(deviceAddress));
}
void loop(void)
{
SensorLoopAndSend();
}
void SensorLoopAndSend()
{
sensors.requestTemperatures();
s1 = getTemperature(Sensor1);
s2 = getTemperature(Sensor2);
Serial.print("S1: ");
Serial.println(s1);
Serial.print("S2: ");
Serial.println(s2);
if((s1 != 185) && (s2 != 185) && (s1 != 32) && (s2 != 32))
{
datastreams[0].setFloat(s1);
datastreams[1].setFloat(s2);
int ret = Xivelyclient.put(feed, xivelyKey);
}
delay(MYDELAY);
}
#include <EEPROM.h>
#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 = "YOURCIKHERE"; // <-- FILL IN YOUR CIK HERE! (https://portals.exosite.com -> Add Device)
byte macData[] = {YOURMACADDRESSHERE}; // <-- FILL IN YOUR Ethernet shield's MAC address here.
IPAddress ip(YOURIPADDRESSHERE);
// 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
/*==============================================================================
* 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() {
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;
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("Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
float 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");
sensors.requestTemperatures(); // Send the command to get temperatures
float temp2C = sensors.getTempCByIndex(1);
Serial.print("Celsius: ");
Serial.print(temp2C);
Serial.println(" C ..........DONE");
temp2F = DallasTemperature::toFahrenheit(temp2C);
Serial.print("Fahrenheit: ");
Serial.print(temp2F);
Serial.println(" F ..........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
writeParam = "temp1="; //parameters to write e.g. 'temp=65.54' or 'temp=65.54&status=on'
String tempValue = dtostrf(temp1F, 1, 2, buffer); // convert float to String, minimum size = 1, decimal places = 2
writeParam += tempValue; //add converted temperature String value
writeParam += "&temp2="; //parameters to write e.g. 'temp=65.54' or 'temp=65.54&status=on'
tempValue = dtostrf(temp2F, 1, 2, buffer);
writeParam += tempValue; //add converted temperature String value
//writeParam += "&message=hello"; //add another piece of data to send
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
}