Sensors to Pachube - Completed!

Hi all,

I’m using three 1 wire temperature sensors to send to Pachube, but this could apply to any sensor that is hooked up to Arduino. My project would not be possible without the help of these forums, so I thought I would post the code…

Arduino code (you need the One Wire library and the Dallas Temperature library):

#include <OneWire.h>
#include <DallasTemperature.h>

// I could not get parasite power to work, so I used 3 pins...
OneWire oneWireA(3);
OneWire oneWireB(2);
OneWire oneWireC(12);

DallasTemperature sensorsA(&oneWireA);
DallasTemperature sensorsB(&oneWireB);
DallasTemperature sensorsC(&oneWireC);

float tempA;
float tempB;
float tempC;

void setup(void)
{

  // start serial port
  Serial.begin(9600);

  // Start up the library
  sensorsA.begin();
  sensorsB.begin();
  sensorsC.begin();
}

void loop(void)
{ 
  sensorsA.requestTemperatures();
  tempA = sensorsA.getTempFByIndex(0);
  
  sensorsB.requestTemperatures(); 
  tempB = sensorsB.getTempFByIndex(0);
  
  sensorsC.requestTemperatures();
  tempC = sensorsC.getTempFByIndex(0);
  
  Serial.print(tempA);    
  Serial.print(",");
  Serial.print(tempB);  
  Serial.print(",");
  Serial.println(tempC);  
  
}

Processing code (you need the Arduino library and the EEML library):

import processing.serial.*;
import cc.arduino.*;

import eeml.*;

Serial myPort;        // The serial port

Arduino arduino;

String fromArduinoSerial;
float lastUpdate;

int firstComma, secondComma, tempComma;
String firstString, secondString, thirdString, tempString;
int stringLength;

DataOut dOut; 

void setup()
{

  // List all the available serial ports
  println(Serial.list());//1
  myPort = new Serial(this, Serial.list()[0], 9600);//1

  dOut = new DataOut(this, "http://www.pachube.com/api/YOUR_SITE_NUMBER_HERE.xml", "YOUR_ACCESS_KEY_HERE"); 

  dOut.addData(1, "In the house");
  dOut.addData(2, "In the fermenter");
  dOut.addData(3, "In the beer");
}

void draw()
{

  fromArduinoSerial = myPort.readStringUntil('\n');

  if (fromArduinoSerial != null) {
    println(fromArduinoSerial);

    if ((millis() - lastUpdate) > 1000 * 60 * 1) {

      // The following parses the 3 comma delimited temps from Arduino.
      // Im sure there is a cleaner way to do this, but I dont know it.
      
      stringLength = fromArduinoSerial.length();
      firstComma = fromArduinoSerial.indexOf(',');

      tempComma = firstComma + 1;
      tempString = fromArduinoSerial.substring(tempComma, stringLength);

      secondComma = tempString.indexOf(',') + firstComma + 1;

      firstString = fromArduinoSerial.substring(0, firstComma);
      firstComma = firstComma + 1;
      secondString = fromArduinoSerial.substring(firstComma, secondComma);
      secondComma = secondComma + 1;
      thirdString = fromArduinoSerial.substring(secondComma, stringLength);
      
      // The following sends the temp info to Pachube

      println("ready to PUT: ");
      dOut.update(0, firstString); 
      int response = dOut.updatePachube(); 
      println(response); 

      println("ready to PUT: ");
      dOut.update(1, secondString); 
      response = dOut.updatePachube(); 
      println(response); 

      println("ready to PUT: ");
      dOut.update(2, thirdString); 
      response = dOut.updatePachube(); 
      println(response); 

      lastUpdate = millis();

      delay(3000);

      myPort.clear();
    }
  }
}

You can see the results here: https://pachube.com/feeds/45035 and http://eandbs.netne.net/ (if its running at the time). For those curious about the beer reference, this is a fermentation chamber monitor. I’m still in the process of building the chamber and the thermowell is in the mail.

Thanks again to all those who contributed code to these forums!