Hola muchachos, estoy haciendo un proyecto de temperatura con el sim900, ya pude conseguir enviar la temperatura mediante sms , pero no he podido lograr enviar datos a ubitos; les quedaria muy agradecido a los que me puedan ayudar.
este es el codigo que tengo :
#include <SoftwareSerial.h>
SoftwareSerial SIM900(2,3); // RX, TX
float temperatura;
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(2,3); //your pins to serial communication
int valor;
String token = "3TJzlxmV3sm6eOgLTutMwswOWIoDWX"; //your token to post value
String idvariable = "586341ad7625420f27dd200d";
void setup()
{
Serial.println("lm35 test 0.1.00");
Serial.begin(19200); // set the baud rate
SIM900.begin(19200); // for GSM shield
delay(20000); // give time to log on to network.
SIM900.print("ATE0\r");
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(1000);
SIM900.println("AT+CNMI=2,2,0,0,0\r");
delay(1000);
Serial.println("Finished Setup Section");
Serial.begin(19200); // the Serial port of Arduino baud rate.
{
mySerial.begin(19200); //the GPRS baud rate
Serial.begin(19200); //the serial communication baud rate
delay(10000);
}
}
/*
as your error information --> variable or field 'sendSMS' declared void
You should write "void sendSMS()"
*/
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(1000);
SIM900.println("AT + CMGS = \"+57311\""); // recipient's mobile number, in international format
delay(1000);
SIM900.print( " Temperatura : ");
SIM900.print(temperatura);
Serial.println(temperatura);
SIM900.println( "C");
delay(1000);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(1000);
SIM900.println();
Serial.println("Message sent");
delay(5000); // give module time to send SMS
}
void loop()
{
int val = analogRead(0);
float voltage = val * (4.9 /1023); // compiler can optimize the constant part
temperatura = voltage * 100; // 0.01V = 1C
Serial.print("Current Temp: ");
Serial.print(temperatura, 2); // Reading the temperature to 1 decimal point
Serial.println("C"); // ALT-0176 => °
delay(5000);
if (temperatura >= 18)
{
sendSMS();
delay(50000); // wait for 5 second
{
int value = analogRead(A0); //read pin A0 from your arduino
save_value(String(value)); //call the save_value function
if (mySerial.available())
Serial.write(mySerial.read());
}
}
}
void save_value( String value)
{
int num;
String le;
String var;
var="{\"value\":"+ value + "}";
num=var.length();
le=String(num);
for(int i = 0;i<7;i++)
{
mySerial.println("AT+CGATT?"); //this is made repeatedly because it is unstable
delay(2000);
ShowSerialData();
}
mySerial.println("AT+CSTT=\"internet.comcel.com.co\""); //replace with your providers' 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\",\"things.ubidots.com\",\"80\""); //start up the connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSEND"); //begin send data to remote server
delay(3000);
ShowSerialData();
mySerial.print("POST /api/v1.6/collections");
delay(100);
ShowSerialData();
mySerial.println("/values HTTP/1.1");
delay(100);
ShowSerialData();
mySerial.println("Content-Type: application/json");
delay(100);
ShowSerialData();
mySerial.println("Content-Length11:");
delay(100);
ShowSerialData();
mySerial.print("X-Auth-Token:3TJzlxmV3sm6eOgLTutMwswOWIoDWX");
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);
delay(7000);
mySerial.println();
ShowSerialData();
mySerial.println("AT+CIPCLOSE"); //close the communication
delay(1000);
ShowSerialData();
}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}
Monitor Serie:
FÚnished Setup Section
Current Temp: 26.34C
26.34
Message sent
OK
>
>
ERROR
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
OK
OK
OK
ERROR
ERROR
SIM900 R11.0
ERROR
ERROR
Current Temp: 25.87C
25.87
Message sent
OK
>
>
ERROR
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
+CGATT: 1
OK
ERROR
ERROR
10.204.44.128
OK
OK
CONNECT OK
Current Temp: 25.87C
25.87
Message sent