Tengo que responder a través de SMS el valor de una variable si la contraseña se envía a arduino con la ayuda de sim900. Soy capaz de encender un led con éxito. Ahora quiero que el arduino me responda el valor de la variable, pero tengo un problema de encasillamiento.
Aquí está el código que estoy usando:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
//Number of pulses, used to measure energy.
volatile unsigned int pulseCount1_Wh = 0;
volatile unsigned int pulseCount1_kWh = 0;
char number[]="8763983139";
char message[180];
char message1[180];
char pos;
char *p;
const int ledPin = 13;
void onPulse1()
{
//pulseCounter
pulseCount1_Wh++;
if(pulseCount1_Wh == 6400)
{
pulseCount1_Wh = 0;
pulseCount1_kWh++;
}
}
void setup()
{
// KWH interrupt attached to IRQ 0 = pin2
attachInterrupt(0, onPulse1, RISING);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
pos=sms.IsSMSPresent(SMS_UNREAD);
Serial.println((int)pos);
if((int)pos>0&&(int)pos<=20){
Serial.print("NUOVO MESSAGGIO, POS=");
Serial.println((int)pos);
message[0]='#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
//Number of pulses, used to measure energy.
volatile unsigned int pulseCount1_Wh = 0;
volatile unsigned int pulseCount1_kWh = 0;
char number[]="8763983139";
char message[180];
char message1[180];
char pos;
char *p;
const int ledPin = 13;
void onPulse1()
{
//pulseCounter
pulseCount1_Wh++;
if(pulseCount1_Wh == 6400)
{
pulseCount1_Wh = 0;
pulseCount1_kWh++;
}
}
void setup()
{
// KWH interrupt attached to IRQ 0 = pin2
attachInterrupt(0, onPulse1, RISING);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
if (gsm.begin(9600))
Serial.println("\nstatus=READY");
else Serial.println("\nstatus=IDLE");
};
void loop()
{
pos=sms.IsSMSPresent(SMS_UNREAD);
Serial.println((int)pos);
if((int)pos>0&&(int)pos<=20){
Serial.print("NUOVO MESSAGGIO, POS=");
Serial.println((int)pos);
message[0]='%pre%';
sms.GetSMS((int)pos,number,message,180);
p=strstr(message,"testpwd");
if(p){
Serial.println("PSWD OK");
digitalWrite(ledPin,HIGH);
p=strstr(message,"LEDON");
strcat(message1, pulseCount1_Wh);
strcat(message1,"PIN");
sms.SendSMS(number,message1);
delay(100);
if(p){
Serial.println("LED ON");
}
else{
p=strstr(message,"LEDOFF");
if(p){
Serial.println("LED OFF");
digitalWrite(ledPin,LOW);
delay(100);
}
}
}
sms.DeleteSMS((int)pos);
}
delay(5000);
};
';
sms.GetSMS((int)pos,number,message,180);
p=strstr(message,"testpwd");
if(p){
Serial.println("PSWD OK");
digitalWrite(ledPin,HIGH);
p=strstr(message,"LEDON");
strcat(message1, pulseCount1_Wh);
strcat(message1,"PIN");
sms.SendSMS(number,message1);
delay(100);
if(p){
Serial.println("LED ON");
}
else{
p=strstr(message,"LEDOFF");
if(p){
Serial.println("LED OFF");
digitalWrite(ledPin,LOW);
delay(100);
}
}
}
sms.DeleteSMS((int)pos);
}
delay(5000);
};