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.
Dependencies: ATCommand Azure_HTTPS_SIMCOM
Dependents: Azure_SIM800_HelloWorld
Fork of SIMInterface by
Revision 0:f0ed40fee75d, committed 2017-08-10
- Comitter:
- BorjaTarazona
- Date:
- Thu Aug 10 10:46:40 2017 +0000
- Child:
- 1:31e884326b43
- Commit message:
- Creation;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ATCommand.lib Thu Aug 10 10:46:40 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/BorjaTarazona/code/ATCommand/#6f42bbd5eb48
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPS.lib Thu Aug 10 10:46:40 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/BorjaTarazona/code/HTTPS/#3cf9be45a676
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SIMInterface.cpp Thu Aug 10 10:46:40 2017 +0000
@@ -0,0 +1,133 @@
+#define _DEBUG 1
+
+#if _DEBUG
+//Enable debug
+#define __DEBUG__
+#include <cstdio>
+#define DBG(x, ...) printf("[SIMInterface : DBG] "x"\r\n", ##__VA_ARGS__);
+#define WARN(x, ...) printf("[SIMInterface : WARN] "x"\r\n", ##__VA_ARGS__);
+#define ERR(x, ...) printf("[SIMInterface : ERR] "x"\r\n", ##__VA_ARGS__);
+
+#else
+//Disable debug
+#define DBG(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#endif
+
+#include "SIMInterface.h"
+
+char* responseInterface;
+
+/** An Interface for SIMCOM modules
+ *
+ * @brief Currently tested on SIM900, SIM800, SIM800L and SIM800F
+ *
+ */
+
+SIMInterface::SIMInterface(PinName tx, PinName rx, int baudrate, PinName pwr) // ATSerial
+: sim800Interface(tx, rx, baudrate), PWRKEY(pwr)
+{
+
+}
+
+/** Function to check if the module is on
+ *
+ * @param timeout is the time in ms that we will wait for the module to answer
+ *
+**/
+
+int SIMInterface::SIMOnOff(int timeout)
+{
+ int count = 0;
+ sim800Interface.sendCmd("AT\r\n");
+ count = sim800Interface.getResponseLength(timeout);
+ DBG("%d", count);
+ if(count>0)
+ return 1;
+ else
+ return 0;
+}
+
+/** Function to wake up the SIM module
+**/
+
+void SIMInterface::wakeUp()
+{
+ while(SIMOnOff(2000) == 0)
+ {
+ PWRKEY = 0;
+ wait_ms(1000);
+ PWRKEY = 1;
+ wait_ms(1000);
+ PWRKEY = 0;
+ wait_ms(2000);
+ }
+ sim800Interface.clearBuffer();
+}
+
+/** Function to reset the module
+**/
+
+void SIMInterface::reset()
+{
+ PWRKEY = 0;
+ wait_ms(1000);
+ PWRKEY = 1;
+ wait_ms(1000);
+ PWRKEY = 0;
+ wait_ms(1000);
+
+ wakeUp();
+}
+
+/** Function to set the date on the module
+*
+* @param Date is a char in the format "17/08/10,10:27:00+00"
+*
+**/
+
+void SIMInterface::setDateRTC(char* Date) // char* Date has to be in this format 17/07/28,19:59:00+00
+{
+ char dateCmd [60];
+ DBG("%s", Date);
+ sprintf(dateCmd, "AT+CCLK=\"%s\"\r\n", Date);
+ DBG("AT+CLTS=1");
+ responseInterface = sim800Interface.sendCmdAndWaitForResp("AT+CLTS=1\r\n", 200);
+ DBG("%s", responseInterface);
+ DBG("AT+CCLK");
+ responseInterface = sim800Interface.sendCmdAndWaitForResp(dateCmd, 1000);
+ DBG("%s", responseInterface);
+}
+
+/** Function to get the date from the module
+**/
+
+char* SIMInterface::getDateRTC()
+{
+ responseInterface = sim800Interface.sendCmdAndWaitForResp("AT+CCLK?\r\n", 80);
+ DBG("%s", responseInterface);
+ return responseInterface;
+}
+
+/** Function to turn the module off
+**/
+
+void SIMInterface::turnOff()
+{
+ if(SIMOnOff(2000) == 0)
+ {
+
+ }else
+ {
+ PWRKEY = 0;
+ wait_ms(1000);
+ PWRKEY = 1;
+ wait_ms(1000);
+ PWRKEY = 0;
+ wait_ms(1000);
+ }
+ sim800Interface.clearBuffer();
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SIMInterface.h Thu Aug 10 10:46:40 2017 +0000
@@ -0,0 +1,67 @@
+#ifndef _SIMInterface_H
+#define _SIMInterface_H
+
+#include "mbed.h"
+#include "ATCommand.h"
+
+/** An Interface for SIMCOM modules
+ *
+ * @brief Currently tested on SIM900, SIM800, SIM800L and SIM800F
+ *
+ */
+
+class SIMInterface
+{
+
+ protected:
+ /** Serial port for UART Communication
+ **/
+ ATSerial sim800Interface;
+
+ /** Digital pin to turn on and off
+ **/
+ DigitalOut PWRKEY;
+
+ public:
+ /** Create a SIMCOM Interface
+ *
+ * @param tx Tx pin for the UART, rx RX pin for the UART, baudrate Baudrate for the UART, pwr PWRKEY pin of the SIM module
+ *
+ **/
+ SIMInterface(PinName tx, PinName rx, int baudrate, PinName pwr);
+
+ /** Function to wake up the SIM module
+ **/
+ void wakeUp();
+
+ /** Function to reset the module
+ **/
+ void reset();
+
+ /** Function to set the date on the module
+ *
+ * @param Date is a char in the format "17/08/10,10:27:00+00"
+ *
+ **/
+ void setDateRTC(char* Date);
+
+ /** Function to get the date from the module
+ **/
+ char* getDateRTC();
+
+ /** Function to turn the module off
+ **/
+ void turnOff();
+
+ /** Function to check if the module is on
+ *
+ * @param timeout is the time in ms that we will wait for the module to answer
+ *
+ **/
+ int SIMOnOff(int timeout);
+
+ private:
+};
+
+#endif
+
