Hi,
It´s a long time that i was trying to send data to Ubidots by SIM800L EVB module with example codes in Ubidots_arduino_GPRS library. But it didn´t work. I am not a programmer (that is a big problem ) but i think that the issue is that library is for SIM900 module. So after that i found a code for sending data to Ubidots without library, just with AT commands, and it works! Problem is that to send data of 7 variables takes about 90 seconds, and it is really bad for my low-energy project. Can anyone please help with shorter code ? Or anyone know how to make example code MultiVariables working with SIM800L EVB?
There is code that i am using:
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
int value1;
int value2;
int value3;
int value4;
int value5;
int value6;
int value7;
String token = “// PLACE FOR YOUR TOKEN //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
String id_value1 = “// PLACE FOR YOUR ID //”;
void setup()
{
mySerial.begin(19200);
Serial.begin(19200);
delay(10000);
}
void loop()
{
value1 = random(36, 39);
value2 = random(24, 30);
value3 = random(65, 75);
value4 = random(50, 60);
value5 = random(12, 13);
value6 = random(45, 48);
value7 = random(85, 87);
comunication_start();
send_value(value1, idvariable1);
send_value(value2, idvariable2);
send_value(value3, idvariable3);
send_value(value4, idvariable4);
send_value(value5, idvariable5);
send_value(value6, idvariable6);
send_value(value7, idvariable7);
comunication_end();
if (mySerial.available())
Serial.write(mySerial.read());
}
void comunication_start()
{
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CGATT?”);
delay(2000);
ShowSerialData();
mySerial.println(“AT+CSTT=”//PLACE FOR YOUR APN//""); // Replace with your APN
delay(1000);
ShowSerialData();
mySerial.println(“AT+CIICR”); // Bring up the 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”,“things.ubidots.com”,“80"”); // Start the connection to Ubidots
delay(3000);
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”); // Start to send data to remote server
delay(3000);
ShowSerialData();
mySerial.print(“POST /api/v1.6/variables/”+idvariable);
delay(100);
ShowSerialData();
mySerial.println("/values HTTP/1.1");
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: things.ubidots.com”);
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();
}
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());
```
}
Thank you for your time and help!