Pages: [1]   Go Down
Author Topic: Ethernet shield+Pachube.com  (Read 530 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Helo!
Im new to Arduino but so far i have made Arduino read from water pressure sensor and a thermistor sucessfully!

I have now bought an ethernet shield i want to connect to pachube.com.
i went throught all the steps at:http://community.pachube.com/arduino/ethernet
But i get compiling problems when i but my code,where its stated put your code here??
the first error says:
In function 'void loop()':
error: a function-definition is not allowed here before '{' toke
Quote
  double Thermister(double RawADC) {


Quote
/* ==============================
 * This code, which assumes you're using the official Arduino Ethernet shield,
 * updates a Pachube feed with your analog-in values and grabs values from a Pachube
 * feed - basically it enables you to have both "local" and "remote" sensors.
 * 
 * Tested with Arduino 14
 *
 * Pachube is www.pachube.com - connect, tag and share real time sensor data
 * code by usman (www.haque.co.uk), may 2009
 * copy, distribute, whatever, as you like.
 *
 * v1.1 - added User-Agent & fixed HTTP parser for new Pachube headers
 * and check millis() for when it wraps around
 *
 * =============================== */


#include <Ethernet.h>
#include <string.h>
#include <math.h>
#undef int() // needed by arduino 0011 to allow use of stdio
#include <stdio.h> // for function sprintf

#define SHARE_FEED_ID              1872     // this is your Pachube feed ID that you want to share to
#define REMOTE_FEED_ID             256      // this is the ID of the remote Pachube feed that you want to connect to
#define REMOTE_FEED_DATASTREAMS    4        // make sure that remoteSensor array is big enough to fit all the remote data streams
#define UPDATE_INTERVAL            10000    // if the connection is good wait 10 seconds before updating again - should not be less than 5
#define RESET_INTERVAL             10000    // if connection fails/resets wait 10 seconds before trying again - should not be less than 5

#define PACHUBE_API_KEY            "ENTER_YOUR_API_KEY_HERE" // fill in your API key

byte mac[] = { 0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x91 }; // make sure this is unique on your network
byte ip[] = { 192, 168, 0, 144   };                  // no DHCP so we set our own IP address
byte remoteServer[] = { 209,40,205,190 };            // pachube.com

float remoteSensor[REMOTE_FEED_DATASTREAMS];        // we know that feed 256 has floats - this might need changing for feeds without floats

void setup()
{
  Serial.begin(57600);
  setupEthernet(); 

  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop()
{

  // call 'pachube_in_out' at the beginning of the loop, handles timing, requesting
  // and reading. use serial monitor to view debug messages

  pachube_in_out();

  // then put your code here, you can access remote sensor values
  // by using the remoteSensor float array, e.g.:
  
  double Thermister(double RawADC) {
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius

 return Temp;
}

void setup() {
 Serial.begin(19200);
}

void loop() {
 Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit
 Serial.println("grader");
 delay(2000);
}


  analogWrite(3, (int)remoteSensor[3] * 10); // remoteSensor is a float
  analogWrite(5, (int)remoteSensor[1]);

  // you can have code that is time sensitive (e.g. using 'delay'), but
  // be aware that it will be affected by a short pause during connecting
  // to and reading from ethernet (approx. 0.5 to 1 sec).
  // e.g. this code should carry on flashing regularly, with brief pauses
  // every few seconds during Pachube update.

  digitalWrite(6, HIGH);
  delay(100);
  digitalWrite(6, LOW);
  delay(100);

}

« Last Edit: March 14, 2010, 09:21:02 am by zyberb » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46266
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The function Thermistor is contained in the function loop. That is not allowed. The Thermistor function must be defined before or after loop. That's what the compiler is (trying to) tell(ing) you.

You also have two setup functions and two loop functions. You can only have one function with a given name in a sketch.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply:). i should have seen that:).i thought i was just supposed to put my entire code there. But it still does'nt work! so now im trying to make the basic testing code for the ethernet shield to work,but im just getting connection failed all the time.

Quote
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };/* i tested it my laptops mac,and plugged the laptop out of the network.
I also tried to give it a random mac. as i have read in the forums.
*/

byte ip[] = { 10, 0, 0, 177 };/* which ip should i use?
i tried my laptops ip and plugged it out of the network.i also tried a random ip.
*/
byte server[] = { 64, 233, 187, 99 }; // Google

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");//all the time i get this
    
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;smiley-wink
      ;
  }
}

Logged

Pages: [1]   Go Up
Jump to: