Pages: 1 ... 3 4 [5] 6   Go Down
Author Topic: [SOLVED]Logging multiple temp sensors questions(step by step)  (Read 4393 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry for my english...I'm not sending a file, I'm just sending the values ( char ) to the server as the API needs...
about cosm...all is in your comment int the code : "pray to God it says 200" smileysmileysmiley
I have already created a cosm feeding, but I prefer Thingspeak because it can be open on android too..and dynamic...
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry for my english...I'm not sending a file, I'm just sending the values ( char ) to the server as the API needs...

OK, I'm glad we have that sorted out. Actually I was just thinking about this under the shower and, if the time intervals are OK, there really shouldn't be any problem reading the datastream off the SD card and the code I posted should be adaptable. In my case the intervals are the same and I will try that out.

Quote
about cosm...all is in your comment int the code : "pray to God it says 200" smileysmileysmiley
I have already created a cosm feeding, but I prefer Thingspeak because it can be open on android too..and dynamic...

I have had some bumps with cosm, but it ran perfectly for several days when I last used it. I will try Thingspeak soon.
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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

Fine, but I don't see any evidence therein of communication with cosm or the like, which is what this is about. However, it turns out that you are correct, he is not engaging in FTP after all, which is proabaly a good thing.  I am yet to be convinced of any merit in sending a datastream off the card, but maybe the OP can adapt the code I posted.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am going to suggest doing what PaulS recommended. This works on my Mega2560.
Code:
// include the freeRam function in your sketch
int freeRam() {
  extern int __heap_start,*__brkval;
  int v;
  return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval); 
}

void setup() {
  Serial.begin(9600);

  // then use it like this
  Serial.print("SRAM free: ");
  Serial.println(freeRam()); 
}

void loop() {
}
Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Free SRAM is 6063.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that at the end of the setup function? Or just before the logFile call?
Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

at end of the setup is 6063.
during loop after some cycles 5910.

anyway is the pageadd size ok?? now it is 140.  strange was if I tried to modify to 139 or 141  log has been failed.. ( just a guess...)

update: maybe pageadd size can be tricky, but I don't understand at the moment...if the size changed to 60, log failed all the time...changing to 128, just 3-4 lines in the log and then no more...??? smiley-confuse  trying with size 128 and external power supply, not usb...-->log is empty...
« Last Edit: December 04, 2012, 02:42:27 pm by vespapierre » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try reducing it. Set pageAdd[64]. I don't see anything you are putting in that array that would be that big.

Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not ok...

2012-12-04,20:47:19,15,3,3;

2012-12-04,20:47:52,15,3,3;





Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Back to basics. This does just the SD and ethernet, and works good on my Mega. I used my server with a php page, and pin 4 for my SD card. I sent the same parameters as below.
Code:
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

//variables

int temp0;
int temp1;
int temp2;
char pageAdd[64];

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// change to your server
IPAddress server(184,106,153,149);
EthernetClient client;

// **********************************SETUP*****************************************************
void setup(void)
{

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

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  //start SD
  Serial.print(F("Starting SD..."));
  if(!SD.begin(8)) Serial.println(F("failed"));
  else Serial.print(F("ok "));

  // Start w5100
  Serial.print(F("Starting w5100..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else Serial.print(F("ok "));

  // this corrects a bug in the Ethernet.begin() function
  digitalWrite(10,HIGH);

  Serial.print(F("IP: "));
  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));

}


//********************************************LOOP**************************************

void loop(void)
{
  delay(5000);

  temp0 = 1;
  temp1 = 2;
  temp2 = 3;
 
  //datetime
  char sdate[11] = "2012-12-04";
  char stime[9] ="12:34:56";
  Serial.print(stime);
  Serial.print(" ");
  Serial.print(sdate);
  Serial.println(); 
   
  if(!logFile(sdate,stime,temp0,temp1,temp2)) Serial.println(F("Log failed"));
  else Serial.println(F("Log ok"));
 
  sprintf(pageAdd,"/update?key=XXXXXXXXXXXXXXX&field1=%u&field2=%u&field3=%u",temp0,temp1,temp2);

  if(!getPage(server,pageAdd)) Serial.print(F("Fail "));
  else Serial.print(F("Pass "));
 
}
int logFile(char* sdate, char* stime, int temp0, int temp1, int temp2) {
  File fh = SD.open("test.txt",FILE_WRITE);
  if(!fh) {
    Serial.println(F("Open fail"));
    return 0;
  }

  sprintf(pageAdd,"%s,%s,%i,%i,%i;",sdate,stime,temp0,temp1,temp2);
  fh.println(pageAdd);
  fh.close();
  return 1;
}
byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,80))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
    client.write(outBuf);
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}
This works, correct?
Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

after deleting logfile, first two attempt was fail, than log ok on serial...logfile looks:

2012-12-04,12:34:56,1,2,3;

2012-12-04,12:34:56,1,2,3;


so this is not ok!
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is mine using that code:
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
2012-12-04,12:34:56,1,2,3;
Logged

Hungary
Offline Offline
Full Member
***
Karma: 0
Posts: 136
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ohh...bad news... means I have problems with the hw ?

edit: I'm using arduino 102....is it a problem?? or should I change the sd card? it is 128 mb.
« Last Edit: December 04, 2012, 04:21:01 pm by vespapierre » Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5367
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know about the smaller SD cards. I use a 2GB SanDisk, and it is working good.

I noticed the SD card adapter uses voltage divider resistors instead of a logic level converter. I hear that will cause problems too.
Logged

Pages: 1 ... 3 4 [5] 6   Go Up
Jump to: