summaryrefslogtreecommitdiff
path: root/libraries/SIM800/examples
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-05-24 23:43:54 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-05-24 23:43:54 +1000
commit4c0720c8dd80bb6d54109a85e779a4008d7e3295 (patch)
treeb3d5785901cf9bbe3d27488fd0f0f25e4a9bcfc9 /libraries/SIM800/examples
parent2dcc86309bff8eeeb90c9a58b60c5e8ce0d8aa53 (diff)
download2021-arduino-obd-4c0720c8dd80bb6d54109a85e779a4008d7e3295.tar.gz
2021-arduino-obd-4c0720c8dd80bb6d54109a85e779a4008d7e3295.tar.bz2
2021-arduino-obd-4c0720c8dd80bb6d54109a85e779a4008d7e3295.zip
Add SIM800 library
Diffstat (limited to 'libraries/SIM800/examples')
-rw-r--r--libraries/SIM800/examples/GPRSTest/GPRSTest.ino126
1 files changed, 126 insertions, 0 deletions
diff --git a/libraries/SIM800/examples/GPRSTest/GPRSTest.ino b/libraries/SIM800/examples/GPRSTest/GPRSTest.ino
new file mode 100644
index 0000000..e752166
--- /dev/null
+++ b/libraries/SIM800/examples/GPRSTest/GPRSTest.ino
@@ -0,0 +1,126 @@
+/*************************************************************************
+* Test sketch for SIM800 library
+* Distributed under GPL v2.0
+* Written by Stanley Huang <stanleyhuangyc@gmail.com>
+* For more information, please visit http://arduinodev.com
+*************************************************************************/
+
+#include "SIM800.h"
+
+#define APN "connect"
+static const char* url = "http://arduinodev.com/datetime.php";
+
+
+CGPRS_SIM800 gprs;
+uint32_t count = 0;
+uint32_t errors = 0;
+
+void setup()
+{
+ con.begin(9600);
+ while (!con);
+
+ con.println("SIM800 TEST");
+
+ for (;;) {
+ con.print("Resetting...");
+ while (!gprs.init()) {
+ con.write('.');
+ }
+ con.println("OK");
+
+ con.print("Setting up network...");
+ byte ret = gprs.setup(APN);
+ if (ret == 0)
+ break;
+ con.print("Error code:");
+ con.println(ret);
+ con.println(gprs.buffer);
+ }
+ con.println("OK");
+ delay(3000);
+
+ if (gprs.getOperatorName()) {
+ con.print("Operator:");
+ con.println(gprs.buffer);
+ }
+ int ret = gprs.getSignalQuality();
+ if (ret) {
+ con.print("Signal:");
+ con.print(ret);
+ con.println("dB");
+ }
+
+#if 0
+ sendCommand("AT+CSQ");
+ lcd.println("Dialing...");
+ if (sendCommand("ATD + +61402533012;", 10000)) {
+ lcd.println(buffer);
+ }
+ if (sendCommand("ATH"))
+ lcd.println(buffer);
+ delay(1000);
+#endif
+
+ gprs.sendCommand("AT+CMGF=1"); // sets the SMS mode to text
+ gprs.sendCommand("AT+CPMS=\"SM\",\"SM\",\"SM\""); // selects the memory
+
+ for (;;) {
+ if (gprs.httpInit()) break;
+ con.println(gprs.buffer);
+ gprs.httpUninit();
+ delay(1000);
+ }
+ delay(3000);
+}
+
+void loop()
+{
+ count++;
+
+ char mydata[16];
+ sprintf(mydata, "t=%lu", millis());
+ con.print("Requesting ");
+ con.print(url);
+ con.print('?');
+ con.println(mydata);
+ gprs.httpConnect(url, mydata);
+ while (gprs.httpIsConnected() == 0) {
+ // can do something here while waiting
+ con.write('.');
+ for (byte n = 0; n < 25 && !gprs.available(); n++) {
+ delay(10);
+ }
+ }
+ if (gprs.httpState == HTTP_ERROR) {
+ con.println("error");
+ errors++;
+ delay(3000);
+ return;
+ }
+ gprs.httpRead();
+ int ret;
+ while ((ret = gprs.httpIsRead()) == 0) {
+ // can do something here while waiting
+ }
+ if (gprs.httpState == HTTP_ERROR) {
+ con.println("error");
+ errors++;
+ delay(3000);
+ return;
+ }
+
+ // now we have received payload
+ con.print("\n[Payload]");
+ con.println(gprs.buffer);
+
+ // show stats
+ con.print("Total Requests:");
+ con.print(count);
+ if (errors) {
+ con.print(" Errors:");
+ con.print(errors);
+ }
+ con.println();
+}
+