hi,
i am at final year student doing a project using a 8051 microcontroller control a model house .
1st part of my program is to read the sms from the modem. I do so by sending ("at+cmgr=1 \r") reading location 1 and after i read it , i send ("AT+CMGD=1 \r") to delete location. my program will keep on doing this to check the sms
2nd part of my program is to detect any gas leak in the model house. if there is a gas leak , the modem will then send a sms to the modem And the alarm will ring.
they work fine when they are standalone, however when i put both into one program only the 1st part of my program work. when there is a gas leak , only the alarm will ring and i did not receive any sms.
please advise where i can start to troubleshoot? is it the way i using to read the sms is wrong ? or ?
thanks alot
exactly wat is ur doubt. First make it clear. you are explaining regarding the receiving and deleting the sms. But you are asking about sending the message. For sending the message you should use AT+CMGS="mobilenumber" press enter you will get ">" prompt enter the message which you have to send and press ctrl+Z your message will be send...
If still you have any queries post your code.
i am actually writing code for my microcontroller , it have been interface to a modem.
1st part of the code , is to receive sms and carry out the action .
2nd part of the code , if there is a gas leak, the alarm will sound and micontroller will send a sms out to the user .
they worked fine as standalone program . As I join the program together , i am able to send sms to control the model house. however when there is gas leakage , the alarm will sound but the sms is not send out.
so i am wondering , is it because i keep on reading the incoming sms therefore it cause the modem unable to send out sms or there is some other problem.
thanks for your help.
I have for car tyres in good shape.
I have a car in good shape.
When I join them, it doesn't work.
Oops - did I forgot to mention that the tyres was of a completely different dimension and intended for a lorry?
It doesn't matter how much you tell about your program having multiple modules. We can't guess how you have coded your modules, so we can't guess how mudule A may muck up the operation of module B.
Either post code, or spend your time debugging your application. Debugging should tell you exactly what your code is busy doing - or not doing - when there is a gas alarm. But don't expect us to be able to guess what your code is busy doing.
thanks for the advise , here is the code .
while (1) { putStr("at+cmgr=1 \r"); // read from location 1 of modem , start of receiving while (receiverRdy()) { get = getCh(); // get char from modem if (get == '*'){ putStr("AT+CMGF=1 \r"); // set to text mode response[0] = getCh(); response[1] = getCh(); lcdPutCh(response[0]); lcdPutCh(response[1]); delayms(500); putStr("AT+CMGD=1 \r"); // clear location 1 } if ((response[0] == 'o')&& (response[1] == 'l')){ lcdClrScr(); lcdSetXY(0,1); lcdPutStr("light on"); led1 = 0; delayms(500); putStr("AT+CMGD=1 \r"); response[0] = '0'; response[1] = '0'; } else if ((response[0] == 'l')&& (response[1] == 'o')){ lcdClrScr(); lcdSetXY(0,1); lcdPutStr("light off"); led1 = 1; delayms(500); putStr("AT+CMGD=1 \r"); response[0] = '0'; response[1] = '0'; } else if ((response[0] == 'c')&& (response[1] == 'w')){ lcdClrScr(); lcdSetXY(0,1); closeWin(); delayms(500); stopWin(); lcdPutStr("close window"); delayms(1000); putStr("AT+CMGD=1 \r"); response[0] = '0'; response[1] = '0'; } } // end of reciving sms if (i2cRecData(ADDR,1,&c) != 1) { rain = (c & 0x08)>>3 ; help = (c & 0x04) >>2 ; winc = (c & 0x02) >>1; wino = (c & 0x01) >>0; if (gasin == 1){ // start gas alarm = 0; if (countWin == 1){ lcdClrScr(); lcdPutStr("Status :gas leak"); lcdSetXY(0,1); lcdPutStr("window opening"); openWin(); delayms(500); stopWin(); countWin = 0; if (smsglf ==0){ putStr("AT+CMGS="); // set the number to sms putCh('"'); // " putStr("90687566"); putCh('"'); putCh(0x0D); delayms(1000); putStr("gas leaking in your house"); // sms message putCh(0x1A ); // crtl + Z putStr("\r"); smsglf = 1; } } else { alarm = 0; lcdClrScr(); lcdPutStr("Status :gas leak"); lcdSetXY(0,1); lcdPutStr("window opened"); if (smsglf ==0){ putStr("AT+CMGS="); // set the number to sms putCh('"'); // " putStr("90687566"); putCh('"'); putCh(0x0D); delayms(1000); putStr("gas leaking in your house"); // sms message putCh(0x1A ); // crtl + Z putStr("\r"); smsglf = 1; } } // stop gas
You don't seem to synchronize the access to your modem. Remember that it takes time from sending a command to the modem until the last character of the response has been received.
Make sure that your code is either looking for an SMS - and doesn't make the modem available for other tasks until done. Or trying to send an SMS - and doesn't release the modem until done.
By the way - if you indent with spaces (most programmers editors has a setting to use space instead of tab), your posts will look better. Right now, the indent is jumping all over. Probably because some of the lines contains tabs and some contains spaces.
thanks you :) solve it by adding a delay
A delay is a kludge - not a solution!
You need to think about how to properly synchronise your processes.
If you just insert an arbitrary delay, then you will be wasting time in most cases, and you still have the risk that some cases may still take longer than your chosen delay!