Go Down

Topic: Ethernet shield+Pachube.com (Read 654 times) previous topic - next topic


Mar 14, 2010, 03:18 pm Last Edit: Mar 14, 2010, 03:21 pm by zyberb Reason: 1
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

  double Thermister(double RawADC) {


/* ==============================
 * 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()

  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


  // 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() {

void loop() {
 Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit

  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);
  digitalWrite(6, LOW);



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.


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.


#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);
 if (client.connect()) {
   client.println("GET /search?q=arduino HTTP/1.0");
 } else {
   Serial.println("connection failed");//all the time i get this

void loop()
 if (client.available()) {
   char c = client.read();
 if (!client.connected()) {

Go Up