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.
Diff: main.cpp
- Revision:
- 0:dab8b518248d
- Child:
- 1:ab9e1950496a
diff -r 000000000000 -r dab8b518248d main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 12 08:08:38 2020 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+#include "GSM.h"
+#include "myDebug.h"
+#include <string>
+
+#define APN "TELKOMSEL"//NULL
+#define USERNAME NULL
+#define PASSWORD NULL
+
+#define SERVER "192.168.0.111"
+#define PORT 80
+
+GSM mdm(D1, D0, 115200, NULL);
+Serial dbg(USBTX, USBRX);
+
+int main()
+{
+ INFO("<PROGRAM START>\r\n");
+ char buf[512] = "";
+
+ int ret = mdm.init();
+ if(ret < 0)
+ {
+ ERROR("Failed modem init!\r\n");
+ return -1;
+ }
+ TRACE("Success Modem Init...\r\n");
+
+ ret = mdm.networkInit(APN, USERNAME, PASSWORD);
+ if(ret < 0)
+ {
+ ERROR("Failed network init!\r\n");
+ return -1;
+ }
+ TRACE("Success Network Init...\r\n");
+
+ while(true)
+ {
+ INFO("Ready to post...\r\n");
+ if(!mdm.connectTCP(SERVER, PORT))
+ {
+ string buff;
+ buff += "kirim-kirim\r\n";
+
+ INFO("Sending request...\r\n");
+ if(!mdm.sendTCPData(const_cast<char *>(buff.c_str())))
+ {
+ TRACE("Berhasil-berhasil...hore...hore...\r\n");
+ ret = mdm.receivedTCPData(buf, sizeof(buf)-1);
+ if(ret > 0)
+ {
+ FLOW("Socket Recv \"%*s\"\r\n", ret, buf);
+ if(strstr(buf, "HTTP/1.0 200") || strstr(buf, "HTTP/1.0 201"))
+ {
+ INFO("Data success\r\n");
+ }
+ else
+ {
+ ERROR("Data failed\r\n");
+ }
+ }
+ else
+ {
+ ERROR("have not return\r\n");
+ }
+ }
+ else
+ {
+ ERROR("Failed to send\r\n");
+ }
+ }
+ else
+ {
+ ERROR("Failed to connect\r\n");
+ }
+ INFO("Disconnect...\r\rn");
+ mdm.closeTCP();
+ mdm.shutTCP();
+ wait_ms(5000);
+ }
+}
\ No newline at end of file