Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:ab9e1950496a, 2020-03-17 (annotated)
- Committer:
- irsanjul
- Date:
- Tue Mar 17 09:22:42 2020 +0000
- Revision:
- 1:ab9e1950496a
- Parent:
- 0:dab8b518248d
tes II;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| irsanjul | 0:dab8b518248d | 1 | #include "mbed.h" |
| irsanjul | 1:ab9e1950496a | 2 | #include "SIM5360.h" |
| irsanjul | 0:dab8b518248d | 3 | #include "myDebug.h" |
| irsanjul | 0:dab8b518248d | 4 | #include <string> |
| irsanjul | 0:dab8b518248d | 5 | |
| irsanjul | 0:dab8b518248d | 6 | #define APN "TELKOMSEL"//NULL |
| irsanjul | 0:dab8b518248d | 7 | #define USERNAME NULL |
| irsanjul | 0:dab8b518248d | 8 | #define PASSWORD NULL |
| irsanjul | 0:dab8b518248d | 9 | |
| irsanjul | 0:dab8b518248d | 10 | #define SERVER "192.168.0.111" |
| irsanjul | 0:dab8b518248d | 11 | #define PORT 80 |
| irsanjul | 0:dab8b518248d | 12 | |
| irsanjul | 0:dab8b518248d | 13 | GSM mdm(D1, D0, 115200, NULL); |
| irsanjul | 0:dab8b518248d | 14 | Serial dbg(USBTX, USBRX); |
| irsanjul | 0:dab8b518248d | 15 | |
| irsanjul | 0:dab8b518248d | 16 | int main() |
| irsanjul | 0:dab8b518248d | 17 | { |
| irsanjul | 0:dab8b518248d | 18 | INFO("<PROGRAM START>\r\n"); |
| irsanjul | 0:dab8b518248d | 19 | char buf[512] = ""; |
| irsanjul | 0:dab8b518248d | 20 | |
| irsanjul | 0:dab8b518248d | 21 | int ret = mdm.init(); |
| irsanjul | 0:dab8b518248d | 22 | if(ret < 0) |
| irsanjul | 0:dab8b518248d | 23 | { |
| irsanjul | 0:dab8b518248d | 24 | ERROR("Failed modem init!\r\n"); |
| irsanjul | 0:dab8b518248d | 25 | return -1; |
| irsanjul | 0:dab8b518248d | 26 | } |
| irsanjul | 0:dab8b518248d | 27 | TRACE("Success Modem Init...\r\n"); |
| irsanjul | 0:dab8b518248d | 28 | |
| irsanjul | 1:ab9e1950496a | 29 | ret = mdm.registerNet(); |
| irsanjul | 0:dab8b518248d | 30 | if(ret < 0) |
| irsanjul | 0:dab8b518248d | 31 | { |
| irsanjul | 1:ab9e1950496a | 32 | ERROR("Failed register network!\r\n"); |
| irsanjul | 1:ab9e1950496a | 33 | return -1; |
| irsanjul | 1:ab9e1950496a | 34 | } |
| irsanjul | 1:ab9e1950496a | 35 | TRACE("Success register network...\r\n"); |
| irsanjul | 1:ab9e1950496a | 36 | |
| irsanjul | 1:ab9e1950496a | 37 | ret = mdm.join(APN, USERNAME, PASSWORD); |
| irsanjul | 1:ab9e1950496a | 38 | if(ret < 0) |
| irsanjul | 1:ab9e1950496a | 39 | { |
| irsanjul | 1:ab9e1950496a | 40 | ERROR("Failed join network!\r\n"); |
| irsanjul | 0:dab8b518248d | 41 | return -1; |
| irsanjul | 0:dab8b518248d | 42 | } |
| irsanjul | 1:ab9e1950496a | 43 | TRACE("Success Join Network...\r\n"); |
| irsanjul | 0:dab8b518248d | 44 | |
| irsanjul | 1:ab9e1950496a | 45 | mdm.SetBlocking(); |
| irsanjul | 1:ab9e1950496a | 46 | |
| irsanjul | 1:ab9e1950496a | 47 | INFO("Ready to post...\r\n"); |
| irsanjul | 1:ab9e1950496a | 48 | if(!mdm.connectTCP(SERVER, PORT)) |
| irsanjul | 0:dab8b518248d | 49 | { |
| irsanjul | 1:ab9e1950496a | 50 | string buff; |
| irsanjul | 1:ab9e1950496a | 51 | buff += "kirim-kirim\r\n"; |
| irsanjul | 1:ab9e1950496a | 52 | |
| irsanjul | 1:ab9e1950496a | 53 | INFO("Sending request...\r\n"); |
| irsanjul | 1:ab9e1950496a | 54 | if(!mdm.sendTCPData(const_cast<char *>(buff.c_str()), buff.size())) |
| irsanjul | 0:dab8b518248d | 55 | { |
| irsanjul | 1:ab9e1950496a | 56 | TRACE("Berhasil-berhasil...hore...hore...\r\n"); |
| irsanjul | 1:ab9e1950496a | 57 | ret = mdm.receivedTCPData(buf, sizeof(buf)-1); |
| irsanjul | 1:ab9e1950496a | 58 | if(ret > 0) |
| irsanjul | 0:dab8b518248d | 59 | { |
| irsanjul | 1:ab9e1950496a | 60 | FLOW("Socket Recv \"%*s\"\r\n", ret, buf); |
| irsanjul | 1:ab9e1950496a | 61 | if(strstr(buf, "HTTP/1.0 200") || strstr(buf, "HTTP/1.0 201")) |
| irsanjul | 0:dab8b518248d | 62 | { |
| irsanjul | 1:ab9e1950496a | 63 | INFO("Data success\r\n"); |
| irsanjul | 0:dab8b518248d | 64 | } |
| irsanjul | 0:dab8b518248d | 65 | else |
| irsanjul | 0:dab8b518248d | 66 | { |
| irsanjul | 1:ab9e1950496a | 67 | ERROR("Data failed\r\n"); |
| irsanjul | 0:dab8b518248d | 68 | } |
| irsanjul | 0:dab8b518248d | 69 | } |
| irsanjul | 0:dab8b518248d | 70 | else |
| irsanjul | 0:dab8b518248d | 71 | { |
| irsanjul | 1:ab9e1950496a | 72 | ERROR("have not return\r\n"); |
| irsanjul | 0:dab8b518248d | 73 | } |
| irsanjul | 0:dab8b518248d | 74 | } |
| irsanjul | 0:dab8b518248d | 75 | else |
| irsanjul | 0:dab8b518248d | 76 | { |
| irsanjul | 1:ab9e1950496a | 77 | ERROR("Failed to send\r\n"); |
| irsanjul | 0:dab8b518248d | 78 | } |
| irsanjul | 1:ab9e1950496a | 79 | } |
| irsanjul | 1:ab9e1950496a | 80 | else |
| irsanjul | 1:ab9e1950496a | 81 | { |
| irsanjul | 1:ab9e1950496a | 82 | ERROR("Failed to connect\r\n"); |
| irsanjul | 1:ab9e1950496a | 83 | } |
| irsanjul | 1:ab9e1950496a | 84 | INFO("Disconnect...\r\rn"); |
| irsanjul | 1:ab9e1950496a | 85 | mdm.closeTCP(); |
| irsanjul | 1:ab9e1950496a | 86 | mdm.disconnect(); |
| irsanjul | 1:ab9e1950496a | 87 | wait_ms(5000); |
| irsanjul | 1:ab9e1950496a | 88 | |
| irsanjul | 1:ab9e1950496a | 89 | while(true) |
| irsanjul | 1:ab9e1950496a | 90 | { |
| irsanjul | 1:ab9e1950496a | 91 | |
| irsanjul | 0:dab8b518248d | 92 | } |
| irsanjul | 0:dab8b518248d | 93 | } |