Go Down

Topic: unable to use ds18b20 temperature sensor with GSM shield (Read 934 times) previous topic - next topic

mancioman2

Hi guys... I'm trying every solution but no way....

I have the official Antenova gsm shield and the sensor ds18b20.

If I connect only the GSM shield without the sensor I get -127 from the sensor and the shield is able to do the http post to my server successfully. If the sensor is connected It return the right temperature but the client.connect(server, port) never return. I set the sensor pin to 12 instead of 2 to avoid problems, but seem like they are in conflict. I'm already using the external power supply.

Code: [Select]


// libraries
#include <GSM.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// PIN Number
#define PINNUMBER "1218"

// APN data
#define GPRS_APN       "web.omnitel.it" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 12
 
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


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

// URL, path & port (for example: arduino.cc)
char server[] = "mancioboxblog.altervista.org";
char path[] = "/add.php";
int port = 80; // port 80 is the default for HTTP

// check the connection status
int con = 0;

// string to save the temp
String data = "";

// temp random
long temp;

void setup() {

  //file version
  Serial.println("Version: 1.6");
  
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);

  

  /* only for old USB usually not required
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }*/


  Serial.println("Starting Arduino web client.");
  // connection state
  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) {

    Serial.println("I'm trying to connect");
        
    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);
    }
  }

  Serial.println("I'm connected");


  

  // this operation is faster than connect to sim card
  // Start up the temperature sensor library
  Serial.println("initialize sensors");
  sensors.begin();

  // wait the the gsm shield is initialized
  delay(1000);
  

}  

  
  

void loop() {


  /* GET THE TEMPERATURE */
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for Device 1 is: ");

  temp = sensors.getTempCByIndex(0);
  
  Serial.print(temp); // Why "byIndex"?
  // You can have more than one IC on the same bus.
  // 0 refers to the first IC on the wire
  

  //only for test
  //temp = random(33);
  
  data = "temp=" + (String)temp;

  Serial.println("temp stored = " + data);

  delay(2000);
  
  con = client.connect(server, port);
  

  // wait connection engaged
  delay(2000);
  
  // if you get a connection, report back via serial:
  if (con == 1) {
    
    Serial.println("connected");
    // Make a HTTP request:
    client.print("POST ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println("");
    client.println(data);
    client.println("");


    //what I'm sending
    Serial.print("POST ");
    Serial.print(path);
    Serial.println(" HTTP/1.1");
    Serial.print("Host: ");
    Serial.println(server);
    Serial.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    Serial.println("Connection: close");
    Serial.print("Content-Length: ");
    Serial.println(data.length());
    Serial.println("");
    Serial.println(data);
    Serial.println("");
  
  // if you didn't get a connection to the server:
  } else if(con == -1){
    Serial.println("connection failed: TIMED_OUT -1");
  } else if(con == -2){
    Serial.println("connection failed: INVALID_SERVER -2");
  } else if(con == -3){
    Serial.println("connection failed: TRUNCATED -3");
  } else if(con == -4){
    Serial.println("connection failed: INVALID_RESPONSE -4");
  }


  if(client.connected()){
    client.stop();  // DISCONNECT FROM THE SERVER
    Serial.println("enter in the if and stop the client");
  }else{
    Serial.println("the client is not connected");
  }
    
  //keep over 2 second otherwise is not able to close and reopen connection
  delay(2000); // WAIT MINUTES BEFORE SENDING AGAIN

  Serial.println("code repeat");

  
}






I included in the attachment the pictures when I run the sketch with the sensor and without.

Is a problem with the code? maybe stop sensor reading before client connect?

thanks.

Go Up