Pages: 1 2 3 [4] 5 6   Go Down
Author Topic: Mega with wiznet shield (wire hack)+thingspeak+sd problem  (Read 4745 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good! In your code now, add only this:
Code:
   // after this in loop...
    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");

    // add these two lines
    if(!logFile(1,2,3)) Serial.println("Log fail");
    else Serial.println("Log ok");
Does it still work?

edit: The log results should be in file "test.txt". You can change that later. I wanted to insure nothing was wrong with that file, so I used a new name.
« Last Edit: November 24, 2012, 09:04:00 am by SurferTim » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so adding those lines to the code looks like this:
Code:
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = {  0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };

// change to your network settings
IPAddress ip(192,168,9,108);
IPAddress gateway(192, 168, 9, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(184,106,153,149);

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[200];

//char pageAdd[140];

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

  // disable SD SPI
  pinMode(8,OUTPUT);
  digitalWrite(8,HIGH);

  // Start ethernet
  Serial.println("Starting ethernet...");
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println("failed");
  // else Serial.println("ok");
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());
//start SD
Serial.print("Starting SD...");
if(!SD.begin(8)) Serial.println("failed");
else Serial.print("ok ");
  delay(2000);
  Serial.println("Ready");
   
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
   
   
   sprintf(pageAdd,"/update?key=RNO8YHD647QKX5P2&field1=200&field2=200&field3=200");

    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");
    if(!logFile(1,2,3)) Serial.println("Log fail");
    else Serial.println("Log ok");
   
    totalCount++;
    Serial.println(totalCount,DEC);
  }   

  loopCount++;
}

byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];

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

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

    sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
    client.write(outBuf);
  }
  else
  {
    Serial.println("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("Timeout");
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

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

  return 1;
}

int logFile(int temp0, int temp1, int temp2) {
  File fh = SD.open("test.txt",FILE_WRITE);
  if(!fh) {
    Serial.println("Open fail");
    return 0;
  }

  // Use the same character array here to send stuff to the file.
  // pageAdd array is global
  sprintf(pageAdd,"Field1=%u,Field2=%u,Field3=%u",temp0,temp1,temp2);
  fh.println(pageAdd);
  fh.close();
  return 1;
}

at first: pass open fail log fail!  at the second time in the log : pass log ok.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and logfile looks like:

Field1=1,Field2=2,Field3=3

Field1=1,Field2=2,Field3=3
Field1=1,Field2=2,Field3=3
Field1=1,Field2=2,Field3=3


Logged

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

Better! Add this at the top:
Code:
#include <OneWire.h>
#include <DallasTemperature.h>
Does it still run?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok I am adding it, but there were empty lines in the logg as you can see. ok just a few seconds..
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just adding the include files, without actually instancing (and using the instance) the class won't tell you anything. The compiler will optimize them away as useless.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok it is not running...log is:
Starting ethernet...
192.168.9.108
Starting SD...ok Ready
connecting...connected
HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Sat, 24 Nov 2012 14:18:58 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
Status: 200
ETag: "cc06a6150b92e17dd3076a0f0f9d2af4"
Cache-Control: max-age=0, private, must-revalidate

6978
disconnecting.
Pass Open fail
Log fail
1



return code is 200 so it is sent to the server but after it is failed
« Last Edit: November 24, 2012, 09:21:20 am by vespapierre » Logged

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

Remove the new includes you just added. Upload the code and then power down the Arduino for a few seconds. Try it again. Does it fail?

Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no, it does not failed after removing the two includes. Pass log ok.
logfile:
"Field1=1,Field2=2,Field3=3
Field1=1,Field2=2,Field3=3

"
Logged

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

OK. Add the new includes one at a time. Try it after each add. Which include causes the fail?
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

after adding onewire.h

it is failed.

after adding just dallastemp  there was an error during compile...seems dallas needs onewire
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3744
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are indeed short of SRAM, you can benefit from the usual recommendation to use the F macro to wrap all your constant strings - you have rather a lot of them, particularly in your serial.prints
Logged

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

Which pin is the OneWire pin? That is the one with the Dallas temp sensor, correct?

Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wildbill, i should learn a lot I know but I don't know much about F macros. I gues mega should not run out of SRAM with this...

Tim,
yes,

this is pin 3.(digital)
Logged

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

OK, add just this. We'll try initializing the OneWire.
Code:
#include <OneWire.h>

// DS Temperature chip i/o
OneWire ds(3);  // on pin 3
Does that fail also?
Logged

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