Hi, @Sebastian, I appreciate your help in checking through the codes. I have copied and paste you codes in to arduino. It didn’t give error but it didn’t post to ubidots still.
I have also tried to put CR LN after the send payload as below. It didn’t work also.
mySerial.println(var); // Begin send payload to remote server
mySerial.println("");
This is the output from the serial monitor:-
AT
OK
AT+CPIN?
+CPIN: READY
OAT+CSTT=“my3g.com”
OK
AT+CIICR
OK
AT+CIFSR
22.3.211.246
AT+CIPSPRT=0
OK
AT+CIPSTART=“TCP”,“industrial.api.ubidots.com”,“80”
OK
COAT+CIPSEND
POST /api/v1.6/devices/sim900 HTTP/1.1Host:industriAT+CIPCLOSE
CLOSE OK
The codes is exactly copied and pasted:-
#include <String.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
//SoftwareSerial mySerial(3, 2); //SIM900 Tx & Rx is connected to Arduino #3 & #2
int value1;
int value2;
int value3;
int num;
String le;
String var;
String token = “BBFF-GvHtRUwUsH7587lLf3ylaWxv1uosxl”;
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
delay(10000);
}
void loop()
{
value1 = random(36, 39);
value2 = random(24, 30);
value3 = random(65, 75);
var = "{\"temperature\":" + String(value1) + "}";
num = var.length();
le = String(num);
comunication_start();
send_value();
//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=\"my3g.com\""); //start task and setting the APN,
delay(1000);
ShowSerialData();
mySerial.println("AT+CIICR"); //bring up wireless connection
delay(2000);
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\",\"industrial.api.ubidots.com\",\"80\"");
delay(8000);
ShowSerialData();
}
void send_value()
{
mySerial.println("AT+CIPSEND"); //begin send data to remote server
delay(3000);
mySerial.print("POST /api/v1.6/devices/sim900 HTTP/1.1");
mySerial.println("Host:industrial.api.ubidots.com");
mySerial.println("User-Agent:arduino65437823/1.0");
mySerial.print("X-Auth-Token: ");
mySerial.println(token);
mySerial.println("Content-Type:application/json");
mySerial.println("Content-Length: " + le);
mySerial.println("");
mySerial.println(var); // Begin send payload to remote servr
//mySerial.println("");
mySerial.println((char)26);
delay(5000);
ShowSerialData();
mySerial.println("AT+CIPCLOSE"); //close the communication
delay(1000);
}
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());
}