Go Down

Topic: Mega with wiznet shield (wire hack)+thingspeak+sd problem (Read 5 times) previous topic - next topic

vespapierre

#30
Nov 21, 2012, 09:56 pm Last Edit: Nov 21, 2012, 09:59 pm by vespapierre Reason: 1
problems coming... test.txt created manually, but have errors.

Temperatures are 29 Celsius, 0 Celsius, 0 Celsius,

connecting...failed
Fail Open fail
Log failed
1

SurferTim

#31
Nov 21, 2012, 10:05 pm Last Edit: Nov 21, 2012, 10:11 pm by SurferTim Reason: 1
Post your current loop() function. That may help me troubleshoot it.
edit: Power it down for a few seconds. Try it again.

vespapierre

#32
Nov 21, 2012, 10:17 pm Last Edit: Nov 21, 2012, 10:26 pm by vespapierre Reason: 1
powerdown not helped.
Code: [Select]


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
//get temperatures
Serial.print("Getting temperatures...\n\r");
   sensors.requestTemperatures();            //issue global request for each temp sensor on network to return a temp
      if(sensors.getAddress(tempDeviceAddress, 0))
         temp0=(sensors.getTempC(tempDeviceAddress)); //read temp from sensor 0
      if(sensors.getAddress(tempDeviceAddress, 1))
         temp1=(sensors.getTempC(tempDeviceAddress)); //read temp from sensor 1
      if(sensors.getAddress(tempDeviceAddress, 2))
        temp2=(sensors.getTempC(tempDeviceAddress));  //read temp from sensor 2  
 
   Serial.print("Temperatures are ");
   Serial.print(temp0);
   Serial.print(" Celsius, ");
   Serial.print(temp1);
   Serial.print(" Celsius, ");
   Serial.print(temp2);
   Serial.print(" Celsius, ");
   Serial.print("\n\r");
   
  sprintf(pageAdd,"/update?key=XXXXXXXXXXXXXXXXXXXX&field1=%u&field2=%u&field3=%u",temp0,temp1,temp2);
// sprintf(pageAdd,"/",totalCount);

   // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

   if(!getPage(server,pageAdd)) Serial.print("Fail ");
   else Serial.print("Pass ");
   if(!logFile(temp0,temp1,temp2)) Serial.println("Log failed");
   else Serial.println("Log ok");
   
   totalCount++;
   Serial.println(totalCount,DEC);
 }    

 loopCount++;
}
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;
}





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;
}


UPDATE: strange...without the logfile modification, it is not connecting...that was working fine before...maybe thingspeak issue...

SurferTim

Back up then. Remove the call to logFile and the logFile function. Does it work then?

vespapierre

backed up... connection failed...tried to ping the server..got back answer after ping

Go Up