|
|
View previous topic :: View next topic |
Author |
Message |
bdurgaharikiran
Joined: 16 Feb 2008 Posts: 2
|
Need help with sending temperature by GSM |
Posted: Sat Feb 16, 2008 10:43 pm |
|
|
i had a program (c program)which will send sms (temperature) using a phone and pic 16F876A when we send get to that phone using another cell, it also switch on ac machine when send sms as acon and also acoff it switches off ac machine
In my program initially we set a value for temp.
Microcontroller sense temperature but does nothing until we send get.
On sending get, it will send sms as high temp or low then it will waits
further for commands.
When we send acon or acoff it does respective action but i want to
implement a control system in it when we set a value for temperature.
When temperature is less than the set value the program should send us
temperature is low and also the value to us via sms and it also should
make a pin in B or C high i.e output of that pin should be 5v.
When temperature is greater than the set value the program should send
us temperature is high and also the value to us via sms the program
should do nothing but wait for our command.
I'm sending my program.
In it already one of pin in B port is high please make a new pin high.
Code: |
#include <16F876A.h>
#include <string.h>
#include <stdlib.h>
#fuses HS,NOWDT,PROTECT,brownout,put
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_B3, rcv=PIN_B2, stream=GSM)
int count = 0;
float tem = 0;
byte ch = 0;
byte data[95]; //For storing SMS
byte err[] = { "ERR" };
byte read[] = { "READ" };
byte acon[] = { "acon" };
byte acoff[] = { "acoff" };
byte gettmp[] = { "get" };
byte settmp[] = { "set" }; //set25
byte num[12] ; //For Storing Incoming Phone Number
long setvalue = 25; //default Temperature
int flag = 0;
float read_temperature()
{
int i;
int value;
tem = 0;
for(i=0;i<20;i++)
{
delay_ms(10);
value = Read_ADC();
tem = (tem + value)/2;
}
tem = tem + 12; //add constant to get actual temperature
return tem;
}
void call_num()
{
delay_ms(2000);
fprintf(GSM,"ATD%s;\r\n",num);
delay_ms(9000);
fprintf(GSM,"ATH\r\n");
delay_ms(2000);
}
void main()
{
float tmp_send = 0;
int i = 0;
int j = 0;
char *ptr;
long setvalue;
SET_TRIS_B(0b00000100);
SET_TRIS_C(0x00); //Pin-4 for AC Relay Control
OUTPUT_B(0x00);
OUTPUT_C(0x00);
delay_ms(1000);
//For Temperature Reading
setup_port_a( ALL_ANALOG );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel(0);
//Microcontroller Health check indicator start
output_high(PIN_B7);
delay_ms(1000);
output_low(PIN_B7);
delay_ms(1000);
output_high(PIN_B7);
delay_ms(1000);
output_low(PIN_B7);
//Health check end
delay_ms(1000);
while(1)
{
delay_ms(1000);
count = 0; //reset data buffer count
fprintf(GSM,"ATE0\r\n"); //Echo Off
delay_ms(3000);
fprintf(GSM,"AT+CMGF=1\r\n"); //Set to text format
delay_ms(3000);
fprintf(GSM,"AT+CPMS=\"ME\"\r\n"); //Preferred Message Store is Mobile phone
delay_ms(5000);
if(flag == 1)
{
tmp_send = read_temperature();
if(tmp_send > (setvalue+1))
{
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num); //SMS to Number
delay_ms(1000);
fprintf(GSM,"High Temperature : %f\r\n",tmp_send);
delay_ms(1000);
fputc(0x1A,GSM); //^Z to send SMS
delay_ms(30000); //long wait for second check
continue;
}
else if(tmp_send < (setvalue-1))
{
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num); //SMS to Number
delay_ms(1000);
fprintf(GSM,"Low Temperature : %f\r\n",tmp_send);
delay_ms(1000);
fputc(0x1A,GSM); //^Z to send SMS
delay_ms(30000); //long wait for second check
continue;
}
}
fprintf(GSM,"AT+CMGR=1\r\n"); //Read SMS at location 1
delay_ms(10);
while(1)
{
ch = fgetc(GSM); //Read a character
data[count] = ch;
count++;
if(ch == '\r')
{
break;
}
if(count > 93)
{
count = 93; //If SMS length exceeds override last byte
}
}
data[count] = 0; //end of string
delay_ms(1000);
if(strstr(data,err))
{
delay_ms(1000);
continue; //If No Messages at location 1, continue
}
//Message Available
if(strstr(data,read))
{
i = 0;
//extract the number from SMS data
while(data[i] != '9')
{
i++;
if(i > 250) //for extra safety
break;
}
if((data[i] == '9') && (data[i+1] == '1'))
{
i++;
i++;
for(j=0;j<10;j++)
{
num[j] = data[i]; //num got the phone number
i++;
}
num[j] = 0;
flag = 1; //Got the destination phone number
}
}
//delete the message to accommodate the new message
fprintf(GSM,"AT+CMGD=1\r\n");
delay_ms(3000);
if(strstr(data,acon))
{
output_high(PIN_C4);
output_high(PIN_B7);
call_num();
}
else if(strstr(data,acoff))
{
output_low(PIN_C4);
output_low(PIN_B7);
call_num();
}
else if(strstr(data,settmp))
{
ptr = strtok(data, settmp);
ptr = strtok(0, settmp);
setvalue = strtoul(ptr,NULL,10);
delay_ms(1000);
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num); //SMS to Number
delay_ms(2000);
fprintf(GSM,"Temperature Setting changed to: %Lu\r\n",setvalue);
delay_ms(2000);
fputc(0x1A,GSM); //^Z to send SMS
delay_ms(30000);
}
else if(strstr(data,gettmp))
{
tmp_send = read_temperature();
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num); //SMS to Number
delay_ms(3000);
fprintf(GSM,"Live Temperature is: %f\r\n",tmp_send);
delay_ms(3000);
fputc(0x1A,GSM); //^Z to send SMS
delay_ms(30000);
}
else
{
fprintf(GSM,"AT+CMGS=\"%s\"\r\n",num);
delay_ms(2000);
fprintf(GSM,"Invalid Command Mr.%s We are from Eluru :-)\r\n",num);
delay_ms(2000);
fputc(0x1A,GSM);
delay_ms(30000);
}
delay_ms(1000);
}
} |
|
|
|
Guest
|
|
Posted: Mon Apr 07, 2008 5:23 pm |
|
|
is this code working?
dont you need to put #int_rda to read the sms? |
|
|
pattousai
Joined: 23 Aug 2006 Posts: 37
|
|
Posted: Tue Apr 08, 2008 5:13 am |
|
|
sorry to come with no help
but... i'm wondering... your code is base on at commands, isn't that right?
well, i don't know much of that stuff (almost nothing) and i think i will have to learn that, so, by any chance you have any tutorial, book or site to indicate?
thank you very much |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Apr 08, 2008 7:50 am |
|
|
AT-commands are based on the GSM standards but every manufacturer adds their own commands and limitations. Check your modem manufacturer's website for a command manual. If you can't find the command manual then post your modem type here and we might be able to provide you with a link. |
|
|
pattousai
Joined: 23 Aug 2006 Posts: 37
|
|
Posted: Tue Apr 08, 2008 11:12 am |
|
|
humm... actually, i want to use a simple cell phone, like nokia 2610.
those phones are compatible with AT-commands?
thanks again |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
elektrol Guest
|
tc35 sms |
Posted: Wed Apr 30, 2008 1:36 am |
|
|
hello boys, I have compile the code but it have a problem becouse the complier send this message:
Error 74 "tc35_5_seriale.c" Line 211(1,2): Not enough RAM for all variables
the problem is this line: byte data[95]; //For storing SMS
Why my compiler sends this error? please help me?
thanks |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|