From 4c0720c8dd80bb6d54109a85e779a4008d7e3295 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Sun, 24 May 2015 23:43:54 +1000 Subject: Add SIM800 library --- libraries/SIM800/SIM800.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 libraries/SIM800/SIM800.h (limited to 'libraries/SIM800/SIM800.h') diff --git a/libraries/SIM800/SIM800.h b/libraries/SIM800/SIM800.h new file mode 100644 index 0000000..ca3104f --- /dev/null +++ b/libraries/SIM800/SIM800.h @@ -0,0 +1,55 @@ +/************************************************************************* +* Test sketch for SIM800 library +* Distributed under GPL v2.0 +* Written by Stanley Huang +* For more information, please visit http://arduinodev.com +*************************************************************************/ + +#include + +#define SIM800_RESET_PIN 7 +#define simser Serial1 +#define con Serial +#define DEBUG 0 + +typedef enum { + HTTP_DISABLED = 0, + HTTP_READY, + HTTP_CONNECTING, + HTTP_READING, + HTTP_ERROR, +} HTTP_STATES; + +class CGPRS_SIM800 { +public: + CGPRS_SIM800():httpState(HTTP_DISABLED) {} + bool init(); + byte setup(const char* apn); + bool getOperatorName(); + bool checkSMS(); + int getSignalQuality(); + void httpUninit(); + bool httpInit(); + bool httpConnect(const char* url, const char* args = 0); + // check if HTTP connection is established + // return 0 for in progress, 1 for success, 2 for error + byte httpIsConnected(); + void httpRead(); + // check if HTTP connection is established + // return 0 for in progress, -1 for error, number of http payload bytes on success + int httpIsRead(); + byte sendCommand(const char* cmd, unsigned int timeout = 2000, const char* expected = 0); + byte sendCommand(const char* cmd, const char* expected1, const char* expected2, unsigned int timeout = 2000); + bool available() + { + return simser.available(); + } + char buffer[256]; + byte httpState; +private: + byte checkbuffer(const char* expected1, const char* expected2 = 0, unsigned int timeout = 2000); + void purgeSerial(); + byte bytesRecv; + uint32_t checkTimer; +}; + -- cgit v1.2.3