Hi, there. I have tested the sim800L with AT commands. The AT commands work but i received bad request after SEND OK (sending to Ubidots) was received. Any idea why? Attach is the error message and codes.
Error message:
SEND OK
400 Bad Request</hea AT+CIPSHUT SHUT OK ----------------------------------------------------#include <SoftwareSerial.h>
#include <String.h>
//SoftwareSerial mySerial(7, 8);
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
int value7;
String idvariable1, idvariable2, idvariable3, idvariable4, idvariable5, idvariable6, idvariable7;
String token = "BBFF-xxxxxxxxxxxxxxxxxxxxxxx";
String id_value1 = "12345";
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
delay(10000);
}
void loop()
{
value1 = random(36, 39);
value2 = random(24, 30);
value3 = random(65, 75);
comunication_start();
send_value(value1, idvariable1);
comunication_end();
comunication_start();
send_value(value2, idvariable2);
comunication_end();
comunication_start();
send_value(value3, idvariable3);
comunication_end();
if (mySerial.available())
Serial.write(mySerial.read());
}
void comunication_start()
{
mySerial.println("AT");
delay(1000);
mySerial.println("AT+CPIN?");
delay(1000);
mySerial.println("AT+CREG?");
delay(1000);
mySerial.println("AT+CGATT?");
delay(1000);
mySerial.println("AT+CIPSHUT");
delay(1000);
mySerial.println("AT+CIPSTATUS");
delay(2000);
mySerial.println("AT+CIPMUX=0");
delay(2000);
ShowSerialData();
mySerial.println("AT+CSTT=\"xxxxxxx\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
mySerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIFSR"); // Get IP adress
delay(2000);
ShowSerialData();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
//mySerial.println("AT+CIPSTART=\"TCP\",\"industrial.api.ubidots.com\",\"80\""); // Start the connection to Ubidots
mySerial.println("AT+CIPSTART=\"tcp\",\"industrial.api.ubidots.com\",\"80\"");
delay(6000);
ShowSerialData();
}
void send_value(int value, String idvariable)
{
int num;
String le;
String var;
var="{\"value\":" + String(value)+"}";
num=var.length();
le=String(num);
mySerial.println("AT+CIPSEND\n"); // Start to send data to remote server
delay(3000);
ShowSerialData();
mySerial.println("POST /api/v1.6/variables/"+idvariable);
delay(200);
ShowSerialData();
mySerial.println("/values HTTP/1.1 \n");
delay(200);
ShowSerialData();
mySerial.println("Content-Type: application/json\n");
delay(100);
ShowSerialData();
mySerial.println("Content-Length: "+le);
delay(100);
mySerial.print("\n");
delay(100);
ShowSerialData();
mySerial.print("X-Auth-Token: ");
delay(100);
ShowSerialData();
mySerial.print(token);
delay(100);
mySerial.print("\n");
delay(100);
ShowSerialData();
mySerial.println("Host: things.ubidots.com\n");
delay(100);
ShowSerialData();
mySerial.println();
delay(100);
ShowSerialData();
mySerial.println(var);
delay(100);
ShowSerialData();
mySerial.println();
delay(100);
ShowSerialData();
mySerial.println((char)26); // Sending the HTTP request
delay(7000); // Waiting for a reply. Important! tweak this time depending on the latency of your mobile Internet connection
mySerial.println();
ShowSerialData();
mySerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}
void comunication_end()
{
mySerial.println("AT+CIPCLOSE"); // Close the connection
delay(1000);
ShowSerialData();
}
// This function is to show the response in your serial terminal
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}