Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: Mega with wiznet shield (wire hack)+thingspeak+sd problem  (Read 4685 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 171
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

seems that I'm newbie...
I have checked the example method of post...

http://community.thingspeak.com/documentation/api/

How can I put that to your code Tim?

is this the sending to the server?:
<code>
sprintf(pageAdd,"/",totalCount);
    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

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

Should I use strcpy  to put the lines to pageAdd and then sprintf(pageAdd); ?

Sorry for the question...
 
 
« Last Edit: November 21, 2012, 10:33:40 am by vespapierre » Logged

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

The API says it will take GET or POST requests, so this should work. In loop() change the sprintf line.
Code:
sprintf(pageAdd,"/update?key=MyKey&test=%u",totalCount);

Change MyKey to your key. Change "test" to "Field", "Channel", etc. Change totalCount to the parameter you want to pass.

Insure there are no illegal characters in the parameters, like spaces.
Logged

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

Tim,

seems your code is working. Exactly did what you wrote. Serial monitor said:

Starting ethernet...
192.168.9.110
Starting SD...ok Ready
connecting...connected
HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Wed, 21 Nov 2012 19:01:40 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
Status: 200
ETag: "b4fd1d2cb085390fbbadae65e07876a7"
Cache-Control: max-age=0, private, must-revalidate

2809
disconnecting.
Pass 1

I have just add manually temp values.

Logged

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

Of all the things I enjoy seeing in the serial monitor, this is my favorite:
Quote
Pass 1
Logged

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

I have defined the temp0, temp1 ... values as "int". How can put them to sprintf(...)? Manual send was : &field1=200&field2=200 ....
instead of 200 i have to put the temp0, temp1 ....
Logged

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

That sounds like this:
Code:
sprintf(pageAdd,"/update?key=MyKey&field1=%u&field2=%u",temp0,temp1);
edit: Insure the character array pageAdd has enough storage for the string.
« Last Edit: November 21, 2012, 02:34:09 pm by SurferTim » Logged

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

I'm going to be happy smiley
current code is here:
SKETCH

answer is:
Starting ethernet...
192.168.9.110
Starting SD...ok Ready
Locating devices...Found 1 devices.
Parasite power is: OFF
Found device 0 with address: 1092942902080056
Getting temperatures...

Temperatures are 85 Celsius, 0 Celsius, 0 Celsius,

connecting...connected
HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Wed, 21 Nov 2012 19:36:14 GMT
Content-Type: text/html; charset=utf-8
Connection: close
Vary: Accept-Encoding
Status: 200
ETag: "d53697441ef12a45422f6660202f9840"
Cache-Control: max-age=0, private, must-revalidate

2818
disconnecting.
Pass 1

85 degrees is maybe some kind of delay I guess...
we are almost at the start of writing to SD smiley

edit: I have modified the char array to 140. As API documentation said that is the maximum.  Can I modify later the temp as float?
« Last Edit: November 21, 2012, 02:43:55 pm by vespapierre » Logged

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

Watch out for type float. If you try to use that type in sprintf, the result will be "?" where you expected the value to be. You need to convert that float to a string first.

Is the value returned from the temperature sensor a float type? Or integer?

edit: Some devices return the temperature in fractions of a degree, like half or quarter of a degree. 85 may be in quarter degrees. That would be 21.25 degrees Celsius.
« Last Edit: November 21, 2012, 03:08:00 pm by SurferTim » Logged

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

I have tried that, I will stay at integer ( i gues return value can be a float)...I hope it will show negative values.
Facing to SD writing...I have put the SD code what you wrote to the setup().
Can you help how should I go ahaed?

it was my original SD code:

Code:
#include <Wire.h>
#include <OneWire.h>
#include <Rtc_Pcf8563.h>
#include <SD.h>

//init the real time clock
Rtc_Pcf8563 rtc;

// Global variables
const int period = 30000;
const int chipSelect = 8;

//**************************SETUP*****************************
void setup()
{
  String message="";
  Serial.begin(9600);
  Wire.begin();
  pinMode(8, OUTPUT);
   if (!SD.begin(chipSelect))
    {
    Serial.println("Card failed");
    return;
    }
  Serial.println("Card init");
  File logFile = SD.open("errorlog.txt", FILE_WRITE);
  if (logFile)
  {
    message = String(rtc.formatDate(RTCC_DATE_ASIA)) + " " + String(rtc.formatTime());
    logFile.println("Progstart: " + message);
    logFile.close();
    Serial.println("Progrstart: "  + message);
  }  
// if the file isn't open, pop up an error:
  else
  {
    Serial.println("cannot open errorlog.txt");
  }
}

//********************LOOP**********************************
void loop()
{
  delay(period);  
// make a string for assembling the data to log:
  String dataString = "";
  String sDate = "";
  String sTime ="";
//-------------------------------------------------------------  
    sTime=rtc.formatTime();               //read formatted time from i2C RTC
    sDate=rtc.formatDate(RTCC_DATE_ASIA); //read formatted date from 12C RTC

  Serial.print(sTime);
  Serial.print(" ");
  Serial.print(sDate);
  Serial.println();
   dataString += String(sDate + ";" + sTime + ";");
    delay(100);
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile)
  {
    dataFile.println(dataString);
    dataFile.close();
// print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else
  {
    Serial.println("cannot open datalog.txt");
  }
}
// END LOOP


or should I use your ftp code?? Seems I will need your further help  smiley-red
« Last Edit: November 21, 2012, 03:11:19 pm by vespapierre » Logged

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

Did you see my edit to my last post? The value returned may be in 1/4 degrees Celsius.
85 / 4 = 21.25 degrees.
Is that about right?
Logged

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

oh yes...I will double check the DS18b20...now I'm excited about the SD smiley

Did you see my edit to my last post? The value returned may be in 1/4 degrees Celsius.
85 / 4 = 21.25 degrees.
Is that about right?

Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3732
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

85 is the value the DS18B20 returns when it hasn't read the temperature. Discussed again recently in this thread:
http://arduino.cc/forum/index.php/topic,133319.msg1003240.html#msg1003240
Logged

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

85 is the value the DS18B20 returns when it hasn't read the temperature. Discussed again recently in this thread:
http://arduino.cc/forum/index.php/topic,133319.msg1003240.html#msg1003240
And this seems to be the final piece of the puzzle for you.
Thanks, wildbill!  smiley
Logged

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

Thanks wildbill, I will put initial sensor readings to setup.

Tim,

can you help me out of this SD code? What and where should I put? Should I stay at my code or better to use your ftp like?

edit: after initial reading of sensors in setup() 85 degrees at the start disappeared, thanks again!
« Last Edit: November 21, 2012, 03:29:42 pm by vespapierre » Logged

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

Since you have the values in the loop() function, I would put the SD routine immediately after the getPage() call. Like this:

Code:
if(!logFile(temp0,temp1)) Serial.println("Log failed");
else Serial.println("Log ok");

Here is logFile:
Code:
int logFile(int temp0, int temp1) {
  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",temp0,temp1);
  fh.println(pageAdd);
  fh.close();
  return 1;
}
Logged

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