Send SMS with UBlox-C027 controlled by BBB and monitored by PC
Dependencies: C027_Support mbed
main.cpp@0:af2a3f44ce5e, 2015-10-02 (annotated)
- Committer:
- MrGu
- Date:
- Fri Oct 02 09:50:39 2015 +0000
- Revision:
- 0:af2a3f44ce5e
Send SMS with UBlox-C027 controlled by BBB and monitored by PC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MrGu | 0:af2a3f44ce5e | 1 | #include "mbed.h" |
MrGu | 0:af2a3f44ce5e | 2 | #include "MDM.h" |
MrGu | 0:af2a3f44ce5e | 3 | #include "C027_api.h" |
MrGu | 0:af2a3f44ce5e | 4 | //------------------------------------------------------------------------------------ |
MrGu | 0:af2a3f44ce5e | 5 | // You need to configure these cellular modem / SIM parameters. |
MrGu | 0:af2a3f44ce5e | 6 | //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. |
MrGu | 0:af2a3f44ce5e | 7 | #define SIMPIN NULL |
MrGu | 0:af2a3f44ce5e | 8 | /*! The APN of your network operator SIM, sometimes it is "internet" check your |
MrGu | 0:af2a3f44ce5e | 9 | contract with the network operator. You can also try to look-up your settings in |
MrGu | 0:af2a3f44ce5e | 10 | google: https://www.google.co.uk/search?q=APN+list */ |
MrGu | 0:af2a3f44ce5e | 11 | #define APN NULL |
MrGu | 0:af2a3f44ce5e | 12 | //! Set the user name for your APN, or NULL if not needed |
MrGu | 0:af2a3f44ce5e | 13 | #define USERNAME NULL |
MrGu | 0:af2a3f44ce5e | 14 | //! Set the password for your APN, or NULL if not needed |
MrGu | 0:af2a3f44ce5e | 15 | #define PASSWORD NULL |
MrGu | 0:af2a3f44ce5e | 16 | //------------------------------------------------------------------------------------ |
MrGu | 0:af2a3f44ce5e | 17 | Serial pc(USBTX, USBRX); |
MrGu | 0:af2a3f44ce5e | 18 | Serial bbb(P4_28, P4_29); |
MrGu | 0:af2a3f44ce5e | 19 | int main(void) |
MrGu | 0:af2a3f44ce5e | 20 | { |
MrGu | 0:af2a3f44ce5e | 21 | // Create the modem object |
MrGu | 0:af2a3f44ce5e | 22 | MDMSerial mdm; |
MrGu | 0:af2a3f44ce5e | 23 | // initialize the modem |
MrGu | 0:af2a3f44ce5e | 24 | MDMParser::DevStatus devStatus = {}; |
MrGu | 0:af2a3f44ce5e | 25 | MDMParser::NetStatus netStatus = {}; |
MrGu | 0:af2a3f44ce5e | 26 | bool mdmOk = false; |
MrGu | 0:af2a3f44ce5e | 27 | while (!mdmOk) |
MrGu | 0:af2a3f44ce5e | 28 | { |
MrGu | 0:af2a3f44ce5e | 29 | mdmOk=mdm.init(SIMPIN, &devStatus); |
MrGu | 0:af2a3f44ce5e | 30 | } |
MrGu | 0:af2a3f44ce5e | 31 | do |
MrGu | 0:af2a3f44ce5e | 32 | { |
MrGu | 0:af2a3f44ce5e | 33 | mdmOk = mdm.registerNet(&netStatus); |
MrGu | 0:af2a3f44ce5e | 34 | } |
MrGu | 0:af2a3f44ce5e | 35 | while (!mdmOk); |
MrGu | 0:af2a3f44ce5e | 36 | mdm.dumpNetStatus(&netStatus); |
MrGu | 0:af2a3f44ce5e | 37 | mdm.dumpDevStatus(&devStatus); |
MrGu | 0:af2a3f44ce5e | 38 | printf("SMS and GPS Loop\r\n"); |
MrGu | 0:af2a3f44ce5e | 39 | char* num = "+447923598328"; |
MrGu | 0:af2a3f44ce5e | 40 | char* reply; |
MrGu | 0:af2a3f44ce5e | 41 | int n; |
MrGu | 0:af2a3f44ce5e | 42 | printf("Please input the content.\n"); |
MrGu | 0:af2a3f44ce5e | 43 | bbb.putc('o'); |
MrGu | 0:af2a3f44ce5e | 44 | while (bbb.getc() != 'S') |
MrGu | 0:af2a3f44ce5e | 45 | { |
MrGu | 0:af2a3f44ce5e | 46 | continue; |
MrGu | 0:af2a3f44ce5e | 47 | } |
MrGu | 0:af2a3f44ce5e | 48 | send: |
MrGu | 0:af2a3f44ce5e | 49 | pc.puts("New SMS\n"); |
MrGu | 0:af2a3f44ce5e | 50 | n = 0; |
MrGu | 0:af2a3f44ce5e | 51 | reply = new char [140]; |
MrGu | 0:af2a3f44ce5e | 52 | reply[0] = '\0'; |
MrGu | 0:af2a3f44ce5e | 53 | char tmpc = bbb.getc(); |
MrGu | 0:af2a3f44ce5e | 54 | while (true) |
MrGu | 0:af2a3f44ce5e | 55 | { |
MrGu | 0:af2a3f44ce5e | 56 | if (tmpc == ' ' or tmpc == '\n') |
MrGu | 0:af2a3f44ce5e | 57 | { |
MrGu | 0:af2a3f44ce5e | 58 | bbb.puts(reply); |
MrGu | 0:af2a3f44ce5e | 59 | char tmp = bbb.getc(); |
MrGu | 0:af2a3f44ce5e | 60 | while(tmp != 'T' and tmp != 'F') |
MrGu | 0:af2a3f44ce5e | 61 | { |
MrGu | 0:af2a3f44ce5e | 62 | tmp = bbb.getc(); |
MrGu | 0:af2a3f44ce5e | 63 | continue; |
MrGu | 0:af2a3f44ce5e | 64 | } |
MrGu | 0:af2a3f44ce5e | 65 | pc.puts(reply); |
MrGu | 0:af2a3f44ce5e | 66 | pc.putc('\n'); |
MrGu | 0:af2a3f44ce5e | 67 | if (tmp == 'T') |
MrGu | 0:af2a3f44ce5e | 68 | { |
MrGu | 0:af2a3f44ce5e | 69 | mdm.smsSend(num, reply); |
MrGu | 0:af2a3f44ce5e | 70 | pc.puts(reply); |
MrGu | 0:af2a3f44ce5e | 71 | pc.putc('\n'); |
MrGu | 0:af2a3f44ce5e | 72 | if ( tmpc == '\n') |
MrGu | 0:af2a3f44ce5e | 73 | { |
MrGu | 0:af2a3f44ce5e | 74 | delete [] reply ; |
MrGu | 0:af2a3f44ce5e | 75 | bbb.putc('o'); |
MrGu | 0:af2a3f44ce5e | 76 | goto finish; |
MrGu | 0:af2a3f44ce5e | 77 | } |
MrGu | 0:af2a3f44ce5e | 78 | } |
MrGu | 0:af2a3f44ce5e | 79 | else |
MrGu | 0:af2a3f44ce5e | 80 | { |
MrGu | 0:af2a3f44ce5e | 81 | pc.puts("Discard\n"); |
MrGu | 0:af2a3f44ce5e | 82 | } |
MrGu | 0:af2a3f44ce5e | 83 | delete reply; |
MrGu | 0:af2a3f44ce5e | 84 | bbb.putc('o'); |
MrGu | 0:af2a3f44ce5e | 85 | goto send; |
MrGu | 0:af2a3f44ce5e | 86 | } |
MrGu | 0:af2a3f44ce5e | 87 | reply[n] = tmpc; |
MrGu | 0:af2a3f44ce5e | 88 | reply[n+1] = '\0'; |
MrGu | 0:af2a3f44ce5e | 89 | ++n; |
MrGu | 0:af2a3f44ce5e | 90 | tmpc = bbb.getc(); |
MrGu | 0:af2a3f44ce5e | 91 | } |
MrGu | 0:af2a3f44ce5e | 92 | finish: |
MrGu | 0:af2a3f44ce5e | 93 | pc.puts(reply); |
MrGu | 0:af2a3f44ce5e | 94 | pc.putc('\n'); |
MrGu | 0:af2a3f44ce5e | 95 | pc.puts("SMS sent\n"); |
MrGu | 0:af2a3f44ce5e | 96 | mdm.powerOff(); |
MrGu | 0:af2a3f44ce5e | 97 | return 0; |
MrGu | 0:af2a3f44ce5e | 98 | } |