Anyone out there could shine some light!!!, I'm new to coding arduino and I have a problem sending data. for some reason that I cannot figure out, the data, im sending is getting truncated. if any one out there could help I will be greatly appreciated it!!!
This is the code I have and at the end of this post im posting the serial monitor output that shows the data that is getting truncated.
==============================
CODE
//TEMP - Define This Device Hardware Data Input Pins
#define DHTPIN 6 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
//End TEMP - Define This Device Hardware Data Input Pins
TinyGPS gps;
unsigned char buffer[400];
#define ApiKey "ea7591646d5177e7cfb4ceb50a612ab1"
#define User "email@server"
#define Pin "0"
#define host "server:82"
char ip_d2[] = {"
POST /index.php HTTP/1.0\n
Host: "host"\n
Content-Type: application/x-www-form-urlencoded;
"};
char ip_d3[] = {"
datastream={"Apeikey":""ApiKey"",\n
"User":""User"",\n
"Pin":""Pin"",\n
"};
const int RX_GPRS = 7;
const int TX_GPRS = 8;
const int RX_GPS = 10;
const int TX_GPS = 11;
//sprintf(ip_d5,"Data":{"Gps":"%s, %s"}}",Apeikey,User,Pin,bufflat,bufflon);
//GPRS - Define This Device Hardware Data Input Pins
SoftwareSerial GPRSinputSerial(RX_GPRS,TX_GPRS);
//GPS - Define This Device Hardware Data Input Pins
SoftwareSerial GPSinputSerial(RX_GPS, TX_GPS); //GPS Data Input
char aux_str[60];
char str_data[80];
float flat, flon;
char bufferlat[10];
char bufferlon[10];
float humidity;
float temperature;
char buffhum [9];//to parse humidity
char bufftemp [9];//to parse temperature
void setup()
{
//Set this to the Baud rate that you will use to monitor the serial monitor window
pinMode(RX_GPRS, INPUT);//7
pinMode(RX_GPS, INPUT);//10
pinMode(TX_GPRS, OUTPUT);//8
pinMode(TX_GPS, OUTPUT);//11
//GPSinputSerial.begin(19200);
Serial.begin(19200); // the GPRS baud rate
delay(1000);
Serial.println("Start...");
}
void loop()
{
GPSinputSerial.begin(9600);
GetGPSInfo();
delay(3000);
GetTempHumiInfo();
delay(3000);
GetGPSInfo();
smartdelay(4000);
GPSinputSerial.end();
GPRSinputSerial.begin(19200);
powerUpDown();
delay(5000);
Send2MeBlink();
delay(5000);
powerUpDown();
GPRSinputSerial.end();
} // End Loop
void GetGPSInfo()
{
gps.f_get_position(&flat, &flon);
//Convert flat and flon variable holding Lattitude and Longitude from float to string to be able to assign it to the output string variable for sending it on the data stream
//char bufferlat[10];
dtostrf(flat, 3, 6, bufferlat);
//Convert flon variable holding Lattitude from float to string to be able to sendit on the data stream
//char bufferlon[10];
dtostrf(flon, 3, 6, bufferlon);
smartdelay(5000);
}// End GetGPSInfo() Function
void GetTempHumiInfo()
{
// // Reading temperature or humidity takes about 250 milliseconds!
// // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
humidity = dht.readHumidity();
// // Read temperature as Celsius
temperature = (dht.readTemperature() * 18 + 5)/10 + 32;
dtostrf(humidity, 4, 2, buffhum);
dtostrf(temperature, 4, 2, bufftemp);
}
///Send2MebBlink()
///GPRS function to send the device service data to the MebBlink.com
void Send2MeBlink()
{
GPRSinputSerial.println("AT+CGATT?");
delay(2000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CSTT="epc.tmobile.com"");//start task and setting the APN,
delay(2000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIFSR");//get local IP adress
delay(2000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIPSPRT=0");
delay(3000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIPSTART="tcp","server","83"");//start up the connection
delay(2000);
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
GPRSShowSerialData();
sprintf(str_data,""Data":{"Gps":"%s, %s","Humidity":"%s","Temp":"%s"}}",bufferlat,bufferlon,buffhum,bufftemp);
GPRSinputSerial.println(ip_d2);
delay(500);
GPRSShowSerialData();
sprintf(aux_str,"Content-Length: %d",strlen(ip_d3) + strlen(str_data));
GPRSinputSerial.println(aux_str);
GPRSinputSerial.println("Connection: close");//
delay(500);
GPRSShowSerialData();
GPRSinputSerial.println();
GPRSinputSerial.print(ip_d3);
GPRSinputSerial.println(str_data);
delay(500);
GPRSShowSerialData();
GPRSinputSerial.println();//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
GPRSinputSerial.println();
GPRSShowSerialData();
GPRSinputSerial.println("AT+CIPCLOSE");//close the connection
delay(100);
GPRSShowSerialData();
}/// End Send2MebBlink() Function
void powerUpDown()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(2000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(20000); //We wait 20 second to allow the shild to be fully up and registered to the network
}
///GPRSShowSerialData() Function
///this function is to ????????
void GPRSShowSerialData()
{
while(GPRSinputSerial.available()!=0)
Serial.write(GPRSinputSerial.read());
}/// End GPRSShowSerialData() Function
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (GPSinputSerial.available())
gps.encode(GPSinputSerial.read());
} while (millis() - start < ms);
}/// End smartdelay() Function
====================================================
SERIAL MONITOR OUTPUT
23:14:57.789 -> Start...
23:15:48.794 -> `⸮⸮⸮⸮
23:15:48.794 -> RDY
23:15:48.794 ->
23:15:48.794 -> +CFUN: 1
23:15:48.794 ->
23:15:48.794 -> +CPIN: READY
23:15:48.840 ->
23:15:48.840 -> +PACSP: 1
23:15:48.840 ->
23:15:48.840 -> Call ReaAT+CSTT="server"
23:15:50.834 ->
23:15:50.834 -> OK
23:15:53.823 -> AT+CIICR
23:15:53.823 ->
23:15:53.823 -> OK
23:15:55.824 -> AT+CIFSR
23:15:55.824 ->
23:15:55.824 -> 26.110.12.110
23:15:58.847 -> AT+CIPSPRT=0
23:15:58.847 ->
23:15:58.847 -> OK
23:16:00.873 -> AT+CIPSTART="tcp","server","83"
23:16:00.873 ->
23:16:00.873 -> OK
23:16:04.866 -> AT+CIPSEND
23:16:04.866 ->
23:16:04.866 -> ERROR
23:16:04.866 ->
23:16:04.866 -> CONNECT OK
23:16:05.394 -> POST /index.php HTTP/1.0
23:16:05.439 -> Host: server:82
23:16:05.439 -> ContentContent-Length: 165
23:16:05.967 -> Connection: close
23:16:06.546 ->
23:16:06.546 -> datastream={"Apeikey":"ea7591646d5177e7cfb4ceb50a612ab1",
23:16:06.546 -> "Us <<<=== DATA STRING GETTING TRUNCATED HERE
23:16:11.650 ->
23:16:11.650 -> AT+CIPCLOSE