# Problema Arduino+Pachube

**URL:** <https://forum.arduino.cc/t/problema-arduino-pachube/35388>\
**Category:** Italiano\
**Created:** [March 13, 2010, 10:15pm UTC](https://forum.arduino.cc/t/problema-arduino-pachube/35388 "2010-03-13T22:15:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Vanzati](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@Federico\_Vanzati](https://forum.arduino.cc/u/Federico_Vanzati)\
**Post date:** [March 13, 2010, 10:15pm UTC](https://forum.arduino.cc/t/problema-arduino-pachube/35388/1 "2010-03-13T22:15:28Z")

</div>

Volevo ampliare il tutorial che ho fatto con l' LM35 e far fare a pachube da datalogger per le temperature perchè quando l'ho provato tempo fa mi era parso semplice, però questa volta Arduino+Ethernet Shield mi manda in palla i router (di Alice) e non riesco a capire il perchè.  
Se qualcuno ha qualche dritta da darmi ne sarei felicissimo!!

Posto anche il codice:

Tab Pachube\_ethernet\_input\_output:

```cpp
/* ==============================
 * 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>

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

#define LM35_TEMP 0  // Pin analogico 0
#define LM35_REF 1   // Pin analogico 1

#define SHARE_FEED_ID              2413     // 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            "il mio API KEY" // fill in your API key 

byte mac[] = { 0xFE, 0xDE, 0xAA, 0xED, 0xEF, 0x85 }; // make sure this is unique on your network
byte ip[] = { 192, 168, 1, 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(); 
}

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();

}//Loop

```

Tab pachube\_functions:

```cpp
char pachube_data[70];

boolean found_status_200 = false;
boolean found_session_id = false;
boolean found_CSV = false;
char *found;
unsigned int successes = 0;
unsigned int failures = 0;
boolean ready_to_update = true;
boolean reading_pachube = false;

boolean request_pause = false;
boolean found_content = false;

unsigned long last_connect;

int content_length;

float temperatura; // variabile in cui viene salvata la temperatura in gradi centigradi 
float prev_temperatura = 0; // temperatura precendente
int ref; // valore della tensione di riferimento dei due diodi
int ref_medio = 0; // valore della tensione di riferimento medio
int sensoreTemperatura; // valore di tensione letto dal pin OUT del sensore 
int sensoreTemperatura_medio = 0; // valore sensoreTemperatura medio
int cont; //contatore usato per ottenere un valore medio

void pachube_in_out(){

  if (millis() < last_connect) last_connect = millis();

  if (request_pause){
    if ((millis() - last_connect) > interval){
      ready_to_update = true;
      reading_pachube = false;
      request_pause = false;
      found_status_200 = false;
      found_session_id = false;
      found_CSV = false;

      //Serial.print("Ready to connect: ");
      //Serial.println(millis());
    }
  }

  if (ready_to_update){
    Serial.println("Connecting...");
    if (localClient.connect()) {

      // here we assign comma-separated values to 'data', which will update Pachube datastreams
      // we use all the analog-in values, but could of course use anything else millis(), digital
      // inputs, etc. . i also like to keep track of successful and failed connection
      // attempts, sometimes useful for determining whether there are major problems.

      // vengono sommati 10 valori di temperatura per poi farne la media
      for( cont = 0; cont < 10; cont++)
      {
        sensoreTemperatura = analogRead(LM35_TEMP); // lettura della tensione del pin OUT LM35
        sensoreTemperatura_medio += sensoreTemperatura; //sommatoria dei valori

        ref = analogRead(LM35_REF); // lettura della tensione di riferimento
        ref_medio += ref; // sommatoria dei valori

        //  delay(500); // intervallo di campionamento
        //la lettura durera' 10 (numero di camoioni) x 500ms (intervallo tra due campioni) = 5000ms
      } 

      if(cont == 10) // quando ho sommato i dieci valori campionati si esegue:
      {
        cont = 0; // azzeramento contatore, per far ripartire il successivo campionamento

        // media della sommatoria dei dieci valori campionati di ref e sensoreTemperatura
        sensoreTemperatura_medio = sensoreTemperatura_medio / 10;
        ref_medio = ref_medio / 10;

        // conversione dei valori medi misurati in una temperatura in gradi centigradi
        temperatura = (sensoreTemperatura_medio - ref_medio) * 100/2.56;
        temperatura = temperatura * 5/1024;

        // valore di temperatura che verra' mostrato quando si e' in fase di campionamento
        //e non c'e' una temperatura disponibile
        prev_temperatura = temperatura; 

        // stampa su seriale dei due valori medi
        // Serial.print(" ref_medio: ");
        //Serial.print(ref_medio);
        //Serial.print(" temp_medio: ");
        //Serial.print(sensoreTemperatura_medio);

        // prima di un successiva acquisizione e media questi valori vanno azzerati
        sensoreTemperatura_medio = 0;
        ref_medio = 0;
      }
      else{
        temperatura = prev_temperatura;
      }
      // stampa su seriale della temperatura ottenuta in gradi centigradi
      //Serial.print(" gradi: ");
      //Serial.println(temperatura);

      sprintf(pachube_data,"%f,%d,%d", temperatura , successes + 1, failures);
      content_length = strlen(pachube_data);

      ... il resto è uguale

```

In pratica sulla seriale vedo :  
Connecting... connection failed

quindi non riesce mai ad entrare nell' " if (localClient.connect()) { "  
che si trova dopo l'istruzion " Serial.println("Connecting..."); "  
:-/

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 20, 2010, 9:49am UTC](https://forum.arduino.cc/t/problema-arduino-pachube/35388/2 "2010-05-20T09:49:16Z")

</div>

...

---

<div class="post-metadata">

**Author:** ![Federico\_Vanzati](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@Federico\_Vanzati](https://forum.arduino.cc/u/Federico_Vanzati)\
**Post date:** [May 20, 2010, 4:57pm UTC](https://forum.arduino.cc/t/problema-arduino-pachube/35388/3 "2010-05-20T16:57:15Z")

</div>

io non ho ancora risolto...per adesso ho accantonato

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 7:47pm UTC](https://forum.arduino.cc/t/problema-arduino-pachube/35388/4 "2021-05-06T19:47:44Z")

</div>

Closed on May 6, 2021, 7:47pm UTC


