Go Down

Topic: gsm shield - transfer data best option (Read 1 time) previous topic - next topic

ClapHen

Hi everyone!
thanks for the info in this fantastic forum.
I read a lot of info about "gsm shield" but i don't know how i can do this: (let me explain the situation)

ARDUINO + TEMPERATURE SENSOR + SD CARD SHIELD + GSM SHIELD

Arduino reads temperature every 30 mins.
Write on the SD the temperature.
and..... i want to send via gprs the last read to a web. (www.mywebtemperature.) only each read every 30 mins and in my web i'll store all the reads.

i use this fantastic tutorial:
http://learn.adafruit.com/adafruit-data-logger-shield/light-and-temperature-logger

but i don't know how can i send each read every 30 mins to myweb...

Thanks for your opinions!






davidgoth

Hi,

You can use a delay after each read & connection:
Code: [Select]

delay(1800000) // 1800000 miliseconds are 30 minutes


Also, you can use a while loop with time functions:
Code: [Select]

unsigned long timeToConnect = millis();
while((millis() - timeToConnect) < 1800000); 


For example (mixing GSM Web Client example and your link):
Code: [Select]


/* Sensor test sketch
  for more information see http://www.ladyada.net/make/logshield/lighttemp.html
  */

#include <GSM.h>
#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!

#define PINNUMBER ""

// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port
char server[] = "www.yourwebtemperature.com";
char path[] = ""; // Your path (For example: /temperature/receiver.php)
int port = 80; // port 80 is the default for HTTP
const unsigned int kNetworkTimeout = 30*1000;
const unsigned int kNetworkDelay = 1000;

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider

//TMP36 Pin Variables
int tempPin = 1;        //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures
int tempReading;        // the analog reading from the sensor
   
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);   

  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);

  boolean notConnected = true;
 
  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
}


void loop(void) {
  photocellReading = analogRead(photocellPin); 
 
  Serial.print("Light reading = ");
  Serial.print(photocellReading);     // the raw analog reading
 
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Dark");
  } else if (photocellReading < 200) {
    Serial.println(" - Dim");
  } else if (photocellReading < 500) {
    Serial.println(" - Light");
  } else if (photocellReading < 800) {
    Serial.println(" - Bright");
  } else {
    Serial.println(" - Very bright");
  }
 
  tempReading = analogRead(tempPin); 
 
  Serial.print("Temp reading = ");
  Serial.print(tempReading);     // the raw analog reading
 
  // converting that reading to voltage, which is based off the reference voltage
  float voltage = tempReading * aref_voltage / 1024;

  // print out the voltage
  Serial.print(" - ");
  Serial.print(voltage); Serial.println(" volts");

  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degrees C");

  // now convert to Fahrenheight
  float temperatureF = (temperatureC * 9 / 5) + 32;
  Serial.print(temperatureF); Serial.println(" degrees F");

  // if you get a connection, report back via serial:
  if (client.connect(server, port))
  {
    // Cast float to String for send temperature with 2 decimals (Example result: 23.34)
    char buffer[12];
    dtostrf(temperatureC, 4, 2, buffer);

    Serial.println("connected");
    // Make a HTTP request:
    // For example, a POST request with temperatureC data
    client.print("POST ");   
    client.print(path);
    client.println(" HTTP/1.0");
    client.print("Host: ");
    client.println(host);
    client.println("Content-Type: application/x-www-form-urlencoded"); // If you use a form in your website 
    client.print("Content-Length: ");
    client.println(strlen(buffer));  // Size (XX.XX = 5 characters)
    client.println();

    // Send temperature
    client.print(buffer);

    unsigned long timeoutStart = millis();

    // if there are incoming bytes available
    // from the server, read them and print them:
    while((client.connected() || client.available()) &&
    ((millis() - timeoutStart) < kNetworkTimeout))
    {   
      if (client.available())
      {
        char c = client.read();
        Serial.print(c);
      }
    }
    else
      delay(kNetworkDelay);

    client.stop();
 
    // If connection is finished succesfully, wait 30 minutes
    unsigned long timeToConnect = millis();
    while((millis() - timeToConnect) < 1800000);

  }
  else
  {
    Serial.println("connection failed");
    // if you didn't get a connection to the server, try again
  } 

}



ClapHen

:smiley-eek: :smiley-eek: :smiley-eek:
fantastic !!!
i'll try your solution.
really, really thanks!!!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy