CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help with sending temperature by GSM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bdurgaharikiran



Joined: 16 Feb 2008
Posts: 2

View user's profile Send private message

Need help with sending temperature by GSM
PostPosted: Sat Feb 16, 2008 10:43 pm     Reply with quote

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








PostPosted: Mon Apr 07, 2008 5:23 pm     Reply with quote

is this code working?
dont you need to put #int_rda to read the sms?
pattousai



Joined: 23 Aug 2006
Posts: 37

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 5:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 7:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 11:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 08, 2008 12:25 pm     Reply with quote

Most phones use AT-commands. Have a look at the Nokia developer site for more info: http://www.forum.nokia.com/

Here is a link to the specifications of your phone: http://www.forum.nokia.com/devices/2610

And a link to a page where you can download a description of the Nokia AT-commandset: http://www.forum.nokia.com/info/sw.nokia.com/id/95672052-6c77-488d-a055-acef77e4cdc5/AT_Command_Set_For_Nokia_GSM_And_WCDMA_Products_v1_2_en.pdf.html
elektrol
Guest







tc35 sms
PostPosted: Wed Apr 30, 2008 1:36 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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