[SOLVED]Logging multiple temp sensors questions(step by step)

you mean change the IP address to google.com 's IP and use getpage as the same? :

if(!getPage(server, pageAdd)) Serial.print(F("Fail "));
//  else Serial.print(F("Pass "));

Use Google's home page with "/" for a page. Comment out your sprintf, and use a simple one for a test. It is something right in there causing the fail.

sorry Tim, I don't understand ... can you send me the function?

new infos: if I put the getpage before logfile, log failed all the time...

changed the ip to google.com's ip
and function is:

sprintf(pageAdd, "/");

if(!getPage(server,pageAdd)) Serial.print(F("Fail "));
 else Serial.print(F("Pass "));

return code from google is 302 and

logfile is:
2012-12-03,22:19:51,4,4,4;

2012-12-03,22:20:59,5,3,3;
2012-12-03,22:21:16,5,3,3;

I tried to change the size of the pageAdd from 140 to 139 and 141 with the original server....az API said max size can be 140...
what the hell can be the problem...I do not beleive that it cannot be solved...voaaaa....

there was no wire.begin() during the code...

We've tried about everything else, so try switching the two function calls. Call getPage() first, then logFile().

Already tried...in that case all the log action is failed...I don't believe this :~ should we need to modify pinmodes or input/output?

Does anybody havy any idea about this issue? :~
Tim thanks a lot or you!

FYI: I do not believe it is the SD and w5100 causing the problem. I use these two together all the time, and they work good together at the same time. I use them for a FTP passive client to transfer files to and from my FTP/Apache server.

Maybe try removing all but one of the other devices, and see where it starts working again.

I have lost my faith a bit...Tim you mean I should change other devices to output and put it to high?
Can you send me yiur code just to check? Maybe i should change my concept and send csv instead of sending file...
I don't beleive nobody has tried a same project... :~

You are in new territory getting that many devices working on the same Arduino. Maybe it is the power supply? Try disconnecting the other hardware and see if the code still works. It won't save/send the correct readings, but may help determine the cause of the SD fail. It uses memory and power when active.

edit: You are using:
SD
w5100
RTC
3 temperature sensors.

I've never tried that many devices before.

they are on the same shield :frowning: I cannot disconnect them...maybe is it possible in the code?

All on the same shield? That is unusual.

Try using just the SD, w5100 and RTC part of the code. Use dummy values for the temperature sensors. Does that work?

Without having all the equipment here, it is hard to troubleshoot.

vespapierre:
I have lost my faith a bit..Maybe i should change my concept and send csv instead of sending file...

I think that would be a really good idea. I would not have thought it possible to send a file, and I can't see the point of it, even if it is.

It is not that likely that there is a hardware problem. It is most likely the code - and, perhaps even more likely, the approach to the job.

The SD and ethernet work fine together with standard code. Indeed, I am using anEtherTen, which has SD and Ethernet built in. I have to admit that did a lot for my confidence. My clock, sensors and bluetooth are on a shield on top. My only problem has been with the LCD keypad shield. It clashed with the SD and I was obliged to run a jumper across the lower shield.

You should not loose faith. There are others doing similar work

I have tried many solutions...but not working...what should I change? where to go?? :~
at first: with a different concept uploading wa the first, and then came sd logging...sht...
second concept: different sensor reading->sd logging-> sending to the web...sh
t... :frowning:

I think SD log is fine. But, if not working with the getpage() function, than what? send like char? before sending to the web put to output and high the sd ? aah...how to send csv to thingspeak for example?

vespapierre:
I have tried many solutions...but not working...what should I change? where to go?? :~

We have been down this road before. The work we are doing is more or less the same, isn't it? What you should change is the code. Feel free to use mine. The reason why I say this is that my code works and yours doesn't. It gives cosm what it wants - datastreams.

at first: with a different concept uploading wa the first, and then came sd logging...sht...
second concept: different sensor reading->sd logging-> sending to the web...sh
t... :frowning:

We've been here before too. I think you are missing the concept of cosm. Cosm does the data logging, not you. Your job is to feed cosm , and you don't need the SD or the clock to do that. By all means log the data yourself for backup purposes but that is a different job.

I think SD log is fine. But, if not working with the getpage() function, than what? send like char? before sending to the web put to output and high the sd ? aah...how to send csv to thingspeak for example?

You know more about thingspeak than I do, but I understand that the essential purpose is the same as cosm - real-time graph display from a data feed, and that feed is also used to produce a time-stamped csv datalog. And, in the light of that, sending a log from the SD is not fine, it's a dumb idea, and might not be allowed.

I would like to have sd logging in case going offline...all I have to find where and how to put that sd codes...Sd involved in the concept...

Have you tested how much free memory you have (or, more likely, don't have)?

The SD library uses 512+ bytes of SRAM. That's 1/4 of the SRAM on a 328-based Arduino.

Hi Paul,

still not...how can I do that? I would be hard to loose all the free memory of a Mega 2560.

vespapierre:
I would like to have sd logging in case going offline..

That's fine, I am doing the same thing, but that's not the same as sending the SD file to cosm.

.all I have to find where and how to put that sd codes...Sd involved in the concept...

The code below is about 36k. I am currently in the throes of moving to Mega 2560. While I'm sure this can be written more elegantly, it probably won't save enough to squeeze into a Uno.

/*
/*From cosm library example and lifts from a lot of others
 particularly from Stanley in Kuala Lumpur.
 Use your own DS18B20 addresses, keys etc.
 
 */
#include <LiquidCrystal.h>
#include <SD.h>
#include <string.h>
#include "RTClib.h"

RTC_DS1307 RTC;
File myFile;
char filename[] = "00000000.CSV";
#include "Wire.h"
#define DS1307_ADDRESS 0x68

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Cosm.h>

byte InThermo[8] =  {
  0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
  0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char cosmKey[] = "l6ab.....................................0Zz0g";

int sensorPin = 3;
int  second, minute, hour, weekDay, monthDay, month, year;
float InTemp, OutTemp;

// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
//char sensorId2{} = "DrainThermo"

const int bufferSize = 100;
char bufferValue[bufferSize]; // enough space to store the string we're going to send

CosmDatastream datastreams[] = {
  CosmDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),
  CosmDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT),
  //    CosmDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
CosmFeed feed(83153, datastreams, 2 /*put your number here */);

EthernetClient client;
CosmClient cosmclient(client);

LiquidCrystal lcd(8,9,16,5,6,7);

void setup() {

  Wire.begin();
  Serial.begin(9600);
  delay(300);//Wait for newly restarted system to stabilize
  Serial.print("Temperature measurement");
  Serial.print("Initializing SD card...");

  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }

  Serial.println("initialization done.");

  sensors.setResolution(InThermo, 12);
  sensors.setResolution(OutThermo, 12);

  Serial.println("Starting multiple datastream upload to Cosm...");
  Serial.println();

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

void loop() {

  GetClock();
  PrintDate;

  sensors.requestTemperatures();
  Serial.println("Read sensor value ");

  InTemp = (sensorValue(InThermo));
  OutTemp = (sensorValue(OutThermo));  
  // float Drain = (sensorValue(DrainThermo));  

  datastreams[0].setFloat(InTemp);
  datastreams[1].setFloat(OutTemp);

  Serial.println(datastreams[0]);
  Serial.println(datastreams[1]);
  /*
  datastreams[2].setFloat(DrainTemp);
   Serial.println(datastreams[2].getFloat(DrainTemp));
   */
  // LCD stuff will go here

  if (second == 0 || second == 10 || second == 20 || second == 30 || second == 40 || second == 50) 
  {
    myFile = SD.open("data.csv", FILE_WRITE);//<<<<<<<<<<<<< OPEN
    WriteSD;
    int ret=0;
    delay(200);// Delay... must not be too short.
    Serial.println("Uploading it to Cosm");
    ret = cosmclient.put(feed, cosmKey);    // SEND FEED TO COSM
    Serial.print("cosmclient.put returned "); // tell us about it
    Serial.println(ret);                      // pray to God it says 200
    myFile.println();
    myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
  }
    delay(200);// Delay... must not be too short.
    Serial.println();
    delay(800);
}

//sensorValue function
float sensorValue (byte deviceAddress[])
{
  float tempC = sensors.getTempC (deviceAddress);
  return tempC;
}


byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void GetClock(){
  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  monthDay = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

void PrintDate () {
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(month);
  Serial.print("/");
  Serial.print(year);
  Serial.print("     ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");

  if (second < 10)
  {
    Serial.print("0");
  };

  Serial.print(second);
  Serial.print("         ");
}

void WriteSD () {

  myFile.print(monthDay);
  myFile.print("/");
  myFile.print(month);
  myFile.print("/");
  myFile.print(year);
  myFile.print(",  ");
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",         ");

  myFile.print(InTemp);
  myFile.print(",    ");
  myFile.print(OutTemp);
  myFile.print(",    ");
}

@NickPyner: I don't think the OP is sending the csv file like in an FTP sense, which I do with Mega/Ethernet shield on a regular basis.
http://www.arduino.cc/playground/Code/FTP

I think he is opening the file and sending the text from the file to the server. I do that too. On big html pages on a server, I can save a bunch of both program and SRAM by putting the header and footer of my html page in files on the SD.