Hi,
I was trying the new GPRS module and it works but I am having an error when I want to post to Xampp.
Please find attached the code and the error from serial monitor.
#include <SoftwareSerial.h>
#include <String.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
SoftwareSerial mySerial(7, 8); //your pins to serial communication
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
String result;
int valor;
String token = "608c1cdaa6f94e98cd34541ef6c43aee"; //your token to post a value
//String result = "96307f50"; //ID of your variable
void setup()
{
mySerial.begin(9600); //the GPRS baud rate
Serial.begin(9600);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
delay(500);//the serial communication baud rate
Serial.println("Starting");
delay(2000);
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("tag_id="));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
result += String(buffer[i], HEX);
Serial.print(String(buffer[i] < 0x10 ? " 0" : " "));
Serial.print(String(buffer[i], HEX));
}
Serial.println();
mfrc522.PICC_HaltA(); // Stop reading
Serial.println("Sending to xampp Value="+ result);
save_value(String(result)); //call the save_value function
if (mySerial.available())
Serial.write(mySerial.read());
}
//this function is to send the sensor data to Ubidots, you can see the new value in Ubidots after running this function
void save_value(String result)
{
int num;
String le;
String data;
// data="tag_id = "+ result;
data="{\"tag_id\":"+ result + "}";
num=data.length();
le=String(num);
mySerial.println("AT+CGATT?"); //this is better made repeatedly because it is unstable
delay(2000);
ShowSerialData();
// mySerial.println("AT+CSTT=\"www\",\"\",\"\""); //start task and set the APN
// delay(1000);
// ShowSerialData();
// mySerial.println("AT+CIICR"); //bring up wireless connection
// delay(3000);
// ShowSerialData();
// mySerial.println("AT+CIFSR"); //get local IP adress
// delay(2000);
// ShowSerialData();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSTART=\"tcp\",\"49.207.183.202\",\"4000\""); //start up connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSEND=18"); //begin sendiing data to the remote server
delay(5000);
ShowSerialData();
mySerial.print("POST /gprs_rfid/rest/insertrfiddata HTTP/1.1\n");
delay(100);
ShowSerialData();
mySerial.println("tag_id = " + String(result));
delay(100);
ShowSerialData();
mySerial.println("Content-Type: application/json");
delay(100);
ShowSerialData();
mySerial.println("Content-Length: "+le);
delay(100);
ShowSerialData();
mySerial.print("X-Auth-token: ");
delay(100);
ShowSerialData();
mySerial.println(token);
delay(100);
ShowSerialData();
mySerial.println("Host: 49.207.183.202");
delay(100);
ShowSerialData();
mySerial.println();
delay(100);
ShowSerialData();
mySerial.println(data);
delay(100);
ShowSerialData();
mySerial.println();
delay(100);
ShowSerialData();
mySerial.println((char)26);
delay(7000);
mySerial.println();
ShowSerialData();
mySerial.println("AT+CIPCLOSE"); //close communication
delay(1000);
ShowSerialData();
}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}
and i’m getting the error,
Starting
tag_id=e3 8a 44 02
Sending to xampp value=e38a4402
AT+CGATT?
+CGATT: 1
OK
AT+CIPSPRT=0
OK
AT+CIPSTART="tcp","49.207.183.202","4000"
OK
AT+CIPSEND=18
ERROR
POST /gprs_rfid/rest/insertrfiddata HTTP/1.1
tag_id = e38a442
Content-Type: application/json
Content-Length: 18
X-Auth-token: 608c1cdaa6f94e98cd34541ef6c43aee
Host: 49.207.183.202
{"tag_id":e38a442}
ERROR
plz help me out from this.