Skip to main content
raissateke
Associate
October 1, 2014
Question

Code not working

  • October 1, 2014
  • 8 replies
  • 1730 views
Posted on October 01, 2014 at 23:11

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    October 2, 2014
    Posted on October 02, 2014 at 02:41

    You seems to be mixing a number of strategies here, you probably want to be getting ALL received characters via the interrupt, but you definitely don't want to echo those back to the modem.

    You need to think a little more about how you interact with the modem. It's going to respond with OK, ERROR or whatever, so delaying is not a effective strategy to deal with what comes back. You need to collect the data, and then pass it back to the main loop, and that loop is going to want to be able to synchronize and parse the returned data. Your rigid expectation for particular characters one after another is unlikely to work with the somewhat dynamic responses the modem may provide. ie you might get several different, but valid, responses and you need to handle them all.

    I'm also pretty sure sending hanging ''AT+CMGR='' and ''AT+CMGD=''' requests won't work. The modem almost certainly expects you to provide a message number, and the range of numbers will depend on the carrier/SIM, so you will need to enumerate a range of potential slots in-coming SMS will be directed to.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    raissateke
    Associate
    October 5, 2014
    Posted on October 05, 2014 at 13:18

    Good day Mr Clive,

    I am really struggling to fix that code, do you have a code you can upload to direct me? ok thanks

    raissateke
    Associate
    October 27, 2014
    Posted on October 27, 2014 at 11:01

    Hello Mr Clive

    I have managed to make it work :)

    Now im trying to send a notification message (msg) to my cellphone using GSM modem/AT commands with STM32F4

    the message i want to receive is ''A temperature of temp_c C was registered. please switch off geyser.'' but temp_c is an integer so it is giving errors ( i cant use an integer in a string.)

    so i used Strcpy

    but i only receive ''A temeperature of''

    i dont think my Strcpy is working, please help.

    msg=''A temperature of '';

    toString(temp_c,s);

    strcpy(s, msg);

    strcpy(msg, '' C was registered. Please switch off geyser'');

    SendNotification(msg);

    please help

    Tesla DeLorean
    Guru
    October 27, 2014
    Posted on October 27, 2014 at 11:21

    Consider if you should be using strcat() or sprintf() to construct your string.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    megahercas6
    Associate III
    October 27, 2014
    Posted on October 27, 2014 at 13:37

    void send_sms(volatile char *string,volatile char *number)

    { USART_puts(''AT+CMGF=1 ''); Delay(0xFFFFF); USART_puts(''AT+CMGS=''); while(!(USART1->SR & 0x00000040)); USART_SendData(USART1, 0x22); USART_puts(number); while(!(USART1->SR & 0x00000040)); USART_SendData(USART1, 0x22); USART_puts('' ''); Delay(0xFFFFF); USART_puts(string); Delay(0xFF); while(!(USART1->SR & 0x00000040)); USART_SendData(USART1, 0x1A);//CTRL+Z Delay(0xFFFFF); } This is how i do it of for GPS data that can be opened inside android browser, with little flag on spot

    void send_sms_GPS(volatile char *number,float x, float y)
    {
    char masyvas[160]={0};
    USART_puts(''AT+CMGF=1
    
    '');
    Delay(0xFFFFF);
    USART_puts(''AT+CMGS='');
    while(!(USART1->SR & 0x00000040));
    USART_SendData(USART1, 0x22);
    USART_puts(number);
    while(!(USART1->SR & 0x00000040));
    USART_SendData(USART1, 0x22);
    USART_puts(''
    
    '');
    Delay(0xFFFFF);
    sprintf(masyvas,''https://maps.google.com//maps?z=18&q=%f,%f'',x,y);
    USART_puts(masyvas);
    Delay(0xFF);
    while(!(USART1->SR & 0x00000040));
    USART_SendData(USART1, 0x1A);//CTRL+Z
    Delay(0xFFFFF);
    }

    Andrew Neil
    Super User
    October 27, 2014
    Posted on October 28, 2014 at 00:41

    Don't just use blind delays!

    As clive1 says, the modem gives a reply to every command - you should

    pay attention to those replies!

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    frankmeyer9
    Associate III
    October 28, 2014
    Posted on October 28, 2014 at 08:50

    And I guess that code example doesn't help the OP much, as he seems to have serious trouble understanding the inner workings of C strings and the

    strcpy()

    function.

    megahercas6
    Associate III
    October 28, 2014
    Posted on October 28, 2014 at 18:20

    As clive1 says, the modem gives a reply to every command - you should

    pay attention to those replies!

    Yes, it is possible to check each message, but with alot of functions, dealing with strings becomes complicated, in that case you must deal with answer each time you send command as well as keep track on receiver buffer in idle state, since modem time to time will push something. I know that this code is working, and i had no problems.