GSM Shield not sending Data after a day

Hi,

The code works fine for a day but after that it stops and when i run the serial monitor, it displays the temperature and humidity sensor value but it hangs on Starting arduino clinet in the below code. So, could someone let me know if there is an issue with the sketch or some problem with GSM Shield or Sim card ?

I am using Arduino Uno with the integrated GSM Shield.

// Adafruit_DHT library will be included
#include "DHT.h"
#include <Wire.h>
#include <SPI.h>
#include <PubSubClient.h>
#include <GSM.h>
#include <avr/pgmspace.h>

#define GPRS_APN       "web.vodafone.de" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password
#define PINNUMBER ""

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

// URL, path & port (for example: arduino.cc)
char server[] = "xxx.xx.xx.xx";
int port = 8883; // port 80 is the default for HTTP
PubSubClient client(server, port, gsmClient);
char message_buff[100];

//declare the triggered deviation for each sensor
float temp_dev0=0.5;
float hum_dev0=0.5;
float t1,h1;
int temp_delay=1000;
int hum_delay=2000;

// You can declare the input pin here
 #define DHTPIN 4     
 #define DHTTYPE DHT11
 DHT dht(DHTPIN, DHTTYPE);

void setup() {

 Serial.begin(9600);
 Serial.println(F("KY-015 test - temperature and humidity-test:"));

 dht.begin();
 h1 = dht.readHumidity();
 t1 = dht.readTemperature();

 Serial.println(F("temperature: "));
 Serial.println(t1);
 Serial.println(F("humidity: "));
 Serial.println(h1);

    while (!Serial) {
    }
  Serial.println(F("Starting Arduino web client."));
  boolean notConnected = true;
  while (notConnected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      notConnected = false;
    } else {
      Serial.println(F("Not connected"));
      delay(1000);
    }
  }
Serial.println(F("Connected")); 
}

void postdata(String sensorType, String sensorId,float value, String unit){
  String pubString = sensorType + "," + sensorId + "," + String(value) +"," + unit;  
  pubString.toCharArray(message_buff, pubString.length()+1);
  if (client.connect("MQTT")) {
    client.publish("test",message_buff);
  }
}

void check_temperature()
{
  delay(temp_delay);
  float t = dht.readTemperature();
  float temp_dev=t1-t;  
  if(abs(temp_dev)> abs(temp_dev0))
  {
    Serial.print(F("temperature: "));
    Serial.println(t);
    postdata("TemperatureSensor", "2", t , "DegreeCelsius" );
    t1=t; 
  }

}

void check_Humidity()
{
  delay(hum_delay);       
  float h = dht.readHumidity();
  float hum_dev=h1-h;
  if (abs(hum_dev) > abs(hum_dev0))
  {
    Serial.print(F("humidity: "));
    Serial.println(h);
    postdata("HumiditySensor", "1", h , "Percentage" );
    h1=h;
  }  
}





void loop() {
 check_Humidity();
 check_temperature();
}

Thanks.

I am using Arduino Uno with the integrated GSM Shield.

And pissing away resources uselessly using the String class. When you stop doing that, let us know if the problem persists.

Sorry I am new to arduino and C. I did not think it will affect so much. But, I got your point. Is the below code ok ? And are there any other mistakes I am doing right now ?

void postdata(char sensorType, char sensorId,float value, char unit){
  char data_all[100] = "";
  strcat(data_all,sensorType);
  strcat(data_all,",");
  strcat(data_all,sensorId);
  strcat(data_all,",");
  strcat(data_all,char(value));
  strcat(data_all,",");
  strcat(data_all,unit);
  String pubString = data_all;
  pubString.toCharArray(message_buff, pubString.length()+1);
  if (client.connect("MQTT")) {
    client.publish("test",message_buff);
  }
}

Is the below code ok ?

No. Did you print what ended up in data_all?

You can not make a string from a float by casting it to a char. Look at dtostrf().

    postdata("TemperatureSensor", "2", t , "DegreeCelsius" );

Does "TemperatureSensor" look like a (single) char to you? Does "DegreeCelsius" look like a (single) char to you?

You need to make your argument types match what you are actually using to call the function. char *, in the case of the first, second, and last arguments