GSM2 Click Interfacing.

Posted on
  • Hi All,

    I'm a bit stuck when trying to send a text message via my GSM2 Click device which uses the M95 chip.

    I have the module accepting AT commands through Serial4 however I really can't get the syntax working correctly to send a SMS message sucesfully.

    I can carry out the following commands:

    I firstly set the chip to Text Mode:

    >Serial4.println("AT+CMGF=1"); 
    =undefined 
    �AT+CMGF=1
    

    I then set the number to send the SMS to (I have added in the xxx's for anonymity)

    >Serial4.println("AT+CMGS=\"078177xxxxx\"");
    =undefined
    uAT+CMGS="078177xxxxx"
    
    > ���+���������r�:ֿ�{�m�I���}Δ�{�ϧ�uI�m�C��_o��������u�ݵ��Ͽ�+�����+ɷ�������{�x�>_E�w���������Y�+>����ጒ���v?�7�흶i��q~��&��|�{-����nzn�����{��Jo��]��}v�!>�+������Mx����w��u��sC+M��������NAWޘ+~��w�B������l
    
    U������M��{�D�������Uj���/ػa�k����}?�r���d�,5�#۝��C����y�$~nޯ���}�������������|k��ױw�+߿�n��moP�ַ��������3�w����=�4���U���/���������(w{�X�����^
    
    ����z�U��^�����\�O�־�����5������aוl����.Vݽ�E=�����ξa�b�'��{��?n���j�
                                                                            }��g�����ս�������3E�a��Re}��ݘޙj�zO�Ӧ��7��}��^����'��w^������e����q;��m�������l~��^��y����~����Î�������~�o���!{�������y��ͽoo�ck�yM��.�}���L���߳C�}���<w���K�w������|��gn��巹9��w���w��{��������u�v������k��{G��x?�����k����{��ݟ���|��K��������d������߿��������������߻9n�������Y{?����f����ge�E�g�Ƛ�������}Y���FV�}��_(��g�~�?��������(�������$������|���*y����?�>����o��
                      ����������{����{���k�[z��^m����گ���/��=ߞ�����݀[��k�u����{���o��C��/�7���&z����?����]�׃���~�������{��{��~?��z���~g�f��
    
    �����b������W�nag����l�JgO�O{ۼ�����^���v}n�r?Ϸ��7��˸�v������w�w���'���7�|L��}�o�}�no}��������������D���?�����k��L�����:O���퇻����].ߏ��������x��������-���]�>�9���g_oKӯ����q�
    
    ����������~>K�Kl���>�����~��k����+�m���������U뿶"�������W���?ۿ{�=_ˣ�w�ׯ����~'���mn��U��o��u峣���w��V����}���ߞ�_�������ݥ7��
                                                                                                                                    ����������e���]i��b���{ϟ_|��'�j|{no��o�}~��<����v~���޶��{����¯����M���~��6�����������ׯ�Ǯ����������u����B����?0���|����'�ݼ��߷�����s�����g?S�WЏ���5ڣ���
                                                                                                                                             �����:��v�w���������W�ᆵ�7�3��������ۺ���??�����ϳ���}��~���������������ۻW����5
    
    OK
    

    As you can see there is a lot of garbled characters but the output is an "OK" at the end.

    I then assume that the Serial4 is sat at the ">" prompt where I would then enter the text for the text message so I go ahead with the following command:

    >Serial4.println("testing a sms message");
    =undefined
    

    From here I know I need to send a CTRL+Z character at the prompt to send the message so I carry out the following:

    >Serial4.write(0x1A);
    =undefined
    

    However.. I receive nothing. I would expect to see an ID number pop up and the message to go through to my phone.

    Any ideas where I am going wrong here I've been messing around with all the variants I can think of - changing the Serial.write to print and print to println with no luck.

  • Hi,

    My Sim900 does not accept the newline character. If you try :

    Serial.print("AT\r");
    ...
    Serial.print("0x1A");
    

    The problem persits ?

    Best regards,
    @nicolasc_eu

  • It could well be the newlines that are causing problems. As @nicolasc_eu says, try using Serial.print and explicitly sending the newline character that you want.

    Just a note that if you want to send 0x1A, you can do:

    Serial4.write(0x1A);
    Serial4.print("\x1A")
    Serial4.print(myOtherData + "\x1A")
    

    but the following won't work:

    Serial4.print(0x1A);
    Serial4.print("0x1A");
    
  • Oh, sorry for the mistake

  • Thanks for the replies will give this a go tonight and let you know the outcome.

  • I've managed to get a couple of messages to come through based on the following code:

    Serial4.print('AT+CMGS=\"078177XXXXX\"\r')
    Serial4.print(msg + "\x1a")
    

    Where msg is just a string of text to test with.

    However it is hit or miss it seems whether a message sends. I get a SMS probably once every 4 or 5 restarts of the device and re-flashing with the code.

    I seem to be getting loads of garbled text coming back from the GSM module as I had in my first post. This seems to mess up the commands being sent also as sometimes if I send a command using Serial4.print("AT+blahcommand"); I then see in my terminal a mash e.g.:

    ÿ¬þ¾ÿÿ·ýÛÅ'ÿ翼†ïõ
    OK
    °ªþÿ€ÃÀþYg:K
    blèó@¨èÿ!’£æþ;AAT+CMGS="078177XXXXX"
    >
    

    I never sent "AAT+CMGS" I actually sent "AT+CMGS".

    Also the spurious data coming back is everywhere.. I've tried messing with the baud rates to no avail. Further example:

    |   __|___ ___ ___ _ _|_|___ ___ 
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v51 Copyright 2014 G.Williams
    >echo(0);
    GSM Starting..
    =undefined
    AT+CMGF=1
    >
    >
    OK
    >
    AT+IPR=2400
    >
    >
    OK
    >
    ü_ö’ÿþþ×÷ýŸÿŸºþéÞ¹}uæÏ×ÿÿožŸç»ãÔîwgò]¥wæ³×‰7½×:Åž¬^\mu£ê½Oð¯dX×ÿ¿°íÛþ®µ».ënýûWï÷ïíÿÿ÷ú?ÿöýæó¦øÿf*‘ëû¾¿ÿOÛ§ÿ½ÕýÞöçs«=öú÷»9¾¿GýËçüí•“ºÏ½ßÜËËÿöÿûWo?¾ÝŸýú>
    ýëÿÿ?Í¿}ÿßÿýÿ>
    Ïf;sÞ÷ÛßêôwAT+CMGS="07817XXXXXX"
    >
    >
    +CMS ERROR: 3765
    >
    ÿ®ÿŸ?÷¿ÿÿïþv_«¿ÏÛûvžùß}öûþ¿×­ßu÷ýø¹}¿ÿ»þ_ÿ¿YþýßýÎ}½ø›Ïï|úõÞÿ§¿¿Þº/_»ßçü¶ÿú_¿Ûiñ®”Þ]ßgÝõ~Û?ÿýo?}½ôþ~ûßgõÿûùß1á¿à§uù\û”íîö«ÉœþžUßë»ÿ·¼G˜7=ÝýþéöÕó^ñ“ã£mÆó=¾ø³å¸ŸÎ»Ö]móoÓj·æv3}ÿÃß$ùü}Æ_ó´÷ÎüS~tøÙíïÿ¢ŸeÛëØýfyóë´ùïûRßÃÿzb¿ÉÝów|}±=a_1ÛÊrðýùö3oço6ôPgÿY¶;?¸=3Ýÿÿ—ÖÿÛÙ²~óí/ûä¾Bo/Ÿî¸îÛûw{^÷/ÿåݟ„Vúïß¹AJçÞ)^½ùÍû~ï›öèùÖ³ÓÆAwÿ”¿Ï~˜øÿçåÝ?çÞèiZï_«®¿×Vüò_àøÏÛïë»:þ.íã?“½üÿÿ<ì=)ý‰Ëîÿëø~ßßÿ¿ùõËûsç÷ßÙ¡¿ößëéÿ›ž½ÿÛþÿ÷¿¿³÷ÿüÿ[ѯc¿âåíïúZï›ã]÷ÿ›íǘí¡õy=õŸø.«{ìŽçog©k:µï¶_õÈôÖ÷Ófªï¿Uµÿ¯×?ù3_þü/ïßÿ®ó»Ë¿ûÿï;??÷ÿ·ÿGëWz×ïiãú1·Htû“½ÝÿñÏßïß¼=œý?÷þõ?s¿êÿóíÓî‹ýúÅî9WWžæ6«ïʶð§ôüÏOºjæ|YTw-ÏßÛë¼Õ<ÇÔׅìùºY.—ü:Çß
    ERROR
    >
    

    That is using a low baud of 2400. I get similar issues with high baud. The lower baud however always results in the "ERROR" message, the higher bauds atleast register something but I still get the garbled outputs which means nothing.

    The parsing script I use for Serial4.ondata is:

    function handler(c){
      ms=ms+c;
      if (c=='\r' || c=="\n" || c==">"){
        console.log(ms);
        ms="";
      }
    }
    Serial4.onData(function (d) {handler(d.data);});
    

    Im attempting to pick up /n /r and > (which is returned when the GSM wants you to enter the SMS text).

    Sorry for the long and incoherent post but theres lots of small issues. I know the module is functioning at least as I have received text messages, saying that though the messages are also garbled e.g.

    "i@@@f@@?@y@@@@@test"

    It seems to be sending the messed up text and then appending my actual "test" message on the end.

  • Have you read this thread, particularly the bit about PDU encoding? http://forum.espruino.com/conversations/626/#comment7811

  • It's possible that it's also just a bad electrical connection from TX of the module to the Espruino...

  • I'll check the tx connection and also the board power. I need Max of 2amps and also 5v. I've been using the bat pin on the espruino and I think it isn't strong enough to meet these requirements.

    I'll also have a mess with the tx line. I'll try it on a different serial first to see if the spurious data coming back drops off.

  • @Hardware_Hacks there's a 1 Amp thermal fuse on the Espruino board, so that could cause you problems. If powering from USB, the PC is only guaranteed to provide 500mA too.

  • Thanks for all the help on this guys.

    I have just wired up the GSM module to a 1000mAh battery with 3A output and only using the Espruino for reading the RX and TX lines. The text messages now come through it seems every time and the AT commands are more responsive.

    I am still getting some spurious data coming through the lines but not half as bad as before here is what I am seeing:

    =undefined
     _____                 _ 
    |   __|___ ___ ___ _ _|_|___ ___ 
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v52 Copyright 2014 G.Williams
    >>echo(0);
    GSM Starting..
    =undefined
    AT+CMGF=1
    >
    OK
    AT+IPR=9600
    OK
    >Serial1.print("AT+CMGS=\"07817xxxxx\"\r");
    =undefined
    AT+CMGS="07817xxxxxx"
    >
    >Serial1.print("testing a message" + "\x1a");
    =undefined
     ÿÿÿýýÿÿÿòÿïÿÿÿþûÿÿþýÿûÿýýìÿÿÿþÿÿöóýÿÿøüóüÿÿþûÿýýÿûýÿýûÿùûÿúÿû÷testing a messageÿÿÿÿÿÿýÿýýÿÿÿÿûþÿ
    +CMGS: 9
    >
    OK
    > 
    

    The text message I receive is:

     ÿÿÿýýÿÿÿòÿïÿÿÿþûÿÿþýÿûÿýýìÿÿÿþÿÿöóýÿÿøüóüÿÿþûÿýýÿûýÿýûÿùûÿúÿû÷testing a message
    

    Subsequent messages are better:

    >Serial1.print("testing a message again" + "\x1a"); 
    =undefined
     testing a message againÿÿÿÿÿÿÿÿÿÿÿþÿÿ÷ÿ
    

    With the message received at the phone being:

    testing a message again
    

    Is there a check I can put in place to remove these weird characters?

    Currently using:

    function handler(c){
      ms=ms+c;
      if (c=='\r' || c=="\n" || c==">"){
        console.log(ms);
        ms="";
      }
    }
    
    Serial1.onData(function (d) {handler(d.data);});
    
    

    For serial data handling.

    For anyone else with similar issues to this thread, power was the killer for me it seems.

  • Ignore the last message.. It now seems to be working fine. Must have been some dodgy wiring!

  • :) Great, glad it's going! It's really good to see some GSM stuff.

    Hopefully soon we could get some kind of library working - being able to read text messages would be awesome.

  • Just found this library which I think I might butcher up and create a module for us:

    https://github.com/emilsedgh/modem/blob/master/lib/modem.js

  • Just had a quick look through and since I'm still a js newbie I'm guessing I need to do the following:

    • remove the serial port require
    • replace all serial port references with similar serial references as per espruino serial.setup etc
    • remove event emitter?! or does espruino have this lib in place already? and replace with ..?

    Ok I'm stuck already @Gordon any tips? I don't mind doing the leg work :)

  • That sounds about right... There is some basic event emitter stuff - check the reference (however it applies to all objects right now, not via a special EventEmitter class).

    However you might be best off using callbacks instead... Especially as there's no bind function yet. By the way, it uses regex too, and Espruino can't do that yet.

    Personally I'd just look at what it's doing and reimplement it... That would probably be easier than trying to convert, and you'd probably get a nicer result

  • I agree and its kind of what I was doing in my basic set up. Time to brush up on callbacks then :)

    Thanks for the pointers

  • Hi Gordon,
    Not to hijack a thread but I searched for the bind() functionality in the forums, is this still coming? I'm in the process of adapting our software to run on espruinos but I do really seem to require function.bind().

    Thanks for all the great work so far!

  • @Alex: I've just created an issue for this: https://github.com/espruino/Espruino/issues/318

    I'm not 100% sure when it will come - will you need to bind arguments, or just this?

    If you don't need args, you can always workaround it for now by doing:

    Function.prototype.bind = function(thisArg) {
      var f = this;
      return function() { return f.apply(thisArg, arguments); };
    };
    
  • Hi Gordon, thanks for the reply! I'm dynamically constructing a function that is passed to an object. That object will then be free to call the function with it's own this. The reason why I dont simply use apply in the object (which will work too ofcourse) is that our current backend binds the this of the object to the function beforehand so the input files are already finalized.
    I'll try to see if your example works for me! Thank you so much :)

  • Hi Gordon, it seems using the code in your example crashed the espruino. I did find a workaround which will suffice for now but using the bind() function would be much neater. I have branched the bug off on my git, maybe it can help you identify a problem. I'm using the 1.60 firmware.

    My Git is here: https://github.com/AlexDM0/espruinoEVE
    The branch espruinoBug shows the problem. If you upload the entire code it hangs clearly. The bind command is on line 161.

  • Might be a 1v60 issue I guess... I'm using a pre-release build here with a few more fixes/changes.

    Maybe create a new post (this is getting a bit off topic ;) and try and narrow it down to a really simple bit of code that crashes - and then I can look at trying to fix it.

  • I'll keep it in mind, when I have time to narrow it down I'll make a new topic.
    Thank you for the help!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

GSM2 Click Interfacing.

Posted by Avatar for Hardware_Hacks @Hardware_Hacks

Actions