Skip to content

Commit f283818

Browse files
authored
Merge pull request #5 from blemasle/features-optional-pins
Reduce required pin count
2 parents 19b5704 + 7125d00 commit f283818

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Build Status](https://travis-ci.org/blemasle/arduino-sim808.svg?branch=master)](https://travis-ci.org/blemasle/arduino-sim808)
33
[![License](https://img.shields.io/badge/license-MIT%20License-blue.svg)](http://doge.mit-license.org)
44

5-
This library allows to access some of the features of the [SIM808](https://simcom.ee/documents/?dir=SIM808) GPS & GPRS module. It requires at least 3 pins (power, status and reset pins) to work and a TTL Serial.
5+
This library allows to access some of the features of the [SIM808](https://simcom.ee/documents/?dir=SIM808) GPS & GPRS module. It requires only the `RESET` pin to work and a TTL Serial. `STATUS` pin can be wired to enhance the module power status detection, while wiring the `PWRKEY` adds the ability to turn the module on & off.
66

77
The library tries to reduces memory consumption as much as possible, but nonetheless use a 64 bytes buffer to communicate with the SIM808 module. When available, SIM808 responses are parsed to ensure that commands are correctly executed by the module. Commands timeouts are also set according to SIMCOM documentation.
88

@@ -46,17 +46,19 @@ It does *not* have the pretention to become the new SIM808 standard library, but
4646

4747
SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX)
4848
SIM808 sim808 = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);
49+
// SIM808 sim808 = SIM808(SIM_RST); // if you only have the RESET pin wired
50+
// SIM808 sim808 = SIM808(SIM_RST, SIM_PWR); // if you only have the RESET and PWRKEY pins wired
4951

5052
void setup() {
5153
simSerial.begin(SIM808_BAUDRATE);
5254
sim808.begin(simSerial);
5355

54-
sim808.powerOnOff(true); //power on the SIM808
56+
sim808.powerOnOff(true); //power on the SIM808. Unavailable without the PWRKEY pin wired
5557
sim808.init();
5658
}
5759

5860
void loop() {
59-
//whatever you need to do
61+
// whatever you need to do
6062
}
6163
```
6264
See examples for further usage.

examples/Tester/Tester.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void power() {
171171
return;
172172
}
173173

174-
Log.notice(S_F("%s : %S"), buffer, status ? TO_F(ON) : TO_F(OFF));
174+
Log.notice(S_F("%s : %S" NL), buffer, status ? TO_F(ON) : TO_F(OFF));
175175
}
176176
else if(BUFFER_IS_P(ON)) {
177177
readNext();

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SIM808
2-
version=1.0.1
2+
version=1.1.0
33
author=Bertrand Lemasle
44
maintainer=Bertrand Lemasle
55
sentence=Straightforward Arduino library for the SIM808

src/SIM808.Power.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ TOKEN_TEXT(CFUN, "+CFUN");
55

66
bool SIM808::powered()
77
{
8+
if(_statusPin == SIM808_UNAVAILABLE_PIN) {
9+
sendAT();
10+
return waitResponse(SIMCOMAT_DEFAULT_TIMEOUT) != -1;
11+
}
12+
813
return digitalRead(_statusPin) == HIGH;
914
}
1015

1116
bool SIM808::powerOnOff(bool power)
1217
{
18+
if (_pwrKeyPin == SIM808_UNAVAILABLE_PIN) return false;
19+
1320
bool currentlyPowered = powered();
1421
if (currentlyPowered == power) return false;
15-
22+
1623
SIM808_PRINT_P("powerOnOff: %t", power);
1724

1825
digitalWrite(_pwrKeyPin, LOW);

src/SIM808.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
TOKEN(RDY);
44

5-
SIM808::SIM808(uint8_t resetPin, uint8_t pwrKeyPin, uint8_t statusPin)
5+
SIM808::SIM808(uint8_t resetPin, uint8_t pwrKeyPin = SIM808_UNAVAILABLE_PIN, uint8_t statusPin = SIM808_UNAVAILABLE_PIN)
66
{
77
_resetPin = resetPin;
88
_pwrKeyPin = pwrKeyPin;
99
_statusPin = statusPin;
1010

1111
pinMode(_resetPin, OUTPUT);
12-
pinMode(_pwrKeyPin, OUTPUT);
13-
pinMode(_statusPin, INPUT);
12+
if(_pwrKeyPin != SIM808_UNAVAILABLE_PIN) pinMode(_pwrKeyPin, OUTPUT);
13+
if (_statusPin != SIM808_UNAVAILABLE_PIN) pinMode(_statusPin, INPUT);
1414

15-
digitalWrite(_pwrKeyPin, HIGH);
15+
if(_pwrKeyPin != SIM808_UNAVAILABLE_PIN) digitalWrite(_pwrKeyPin, HIGH);
1616
digitalWrite(_resetPin, HIGH);
1717
}
1818

src/SIM808.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#define HTTP_TIMEOUT 10000L
77
#define GPS_ACCURATE_FIX_MIN_SATELLITES 4
8+
#define SIM808_UNAVAILABLE_PIN 255
89

910
class SIM808 : public SIMComAT
1011
{
@@ -52,16 +53,18 @@ class SIM808 : public SIMComAT
5253
bool setBearerSetting(ATConstStr parameter, const char* value);
5354

5455
public:
55-
SIM808(uint8_t resetPin, uint8_t pwrKeyPin, uint8_t statusPin);
56+
SIM808(uint8_t resetPin, uint8_t pwrKeyPin = SIM808_UNAVAILABLE_PIN, uint8_t statusPin = SIM808_UNAVAILABLE_PIN);
5657
~SIM808();
5758

5859
/**
5960
* Get a boolean indicating wether or not the device is currently powered on.
61+
* The power state is read from either the statusPin if set, or from a test AT command response.
6062
*/
6163
bool powered();
6264
/**
6365
* Power on or off the device only if the requested state is different than the actual state.
64-
* Returns true if the power state has been changed has a result of this call.
66+
* Returns true if the power state has been changed as a result of this call.
67+
* Unavailable and returns false in all cases if pwrKeyPin is not set.
6568
*
6669
* See powered()
6770
*/

0 commit comments

Comments
 (0)