Skip to content

Commit

Permalink
Phonebook and other functionalities.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Oct 18, 2023
1 parent 35dc3a9 commit c405a6d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/arduino_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ jobs:
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/card_info/card_info.ino
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/handshake/handshake.ino
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/network_op/network_op.ino
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/phonebook_example/phonebook_example.ino
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/rtc_example/rtc_example.ino
arduino-cli compile --fqbn arduino:avr:uno --library src --build-path build examples/sms_send_example/sms_send_example.ino
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The SIM900 Arduino Shield Library is a versatile and powerful Arduino library fo
- **Real-Time Clock**: Update and extract real-time clock data from the module.
- **HTTP Requests**: Send HTTP requests and retrieve responses.
- **Information Retrieval**: Gather data about network operator, module status, SIM card information, and more.
- **Phonebook Management**: Store and retrieve phonebook accounts.
- **Extensive Documentation**: Well-documented code and usage examples.

## Getting Started
Expand Down
49 changes: 49 additions & 0 deletions examples/phonebook_example/phonebook_example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <SoftwareSerial.h>
#include <sim900.h>

SoftwareSerial shieldSerial(7, 8);

void setup() {
Serial.begin(9600);
SIM900 sim900(&shieldSerial);
uint8_t index = 1;

SIM900CardAccount account;
account.name = "Nathanne Isip";
account.number = "00000000000";
account.numberType = SIM900_PHONEBOOK_NATIONAL;

Serial.println(F("Storing to phonebook..."));
if(!sim900.savePhonebook(index, account)) {
Serial.println(F("Error saving to phonebook."));
return;
}

Serial.println(F("Stored!"));
Serial.println(F("--------------------------"));
Serial.println(F("Retrieving..."));

SIM900CardAccount retrieved = sim900.retrievePhonebook(index);
Serial.print(F("Name:\t"));
Serial.println(retrieved.name);

Serial.print(F("Number:\t"));
Serial.println(retrieved.number);

Serial.print(F("Type:\t"));
switch(retrieved.numberType) {
case SIM900_PHONEBOOK_INTERNATIONAL:
Serial.println("International");
break;

case SIM900_PHONEBOOK_NATIONAL:
Serial.println("National");
break;

default:
Serial.println("Unknown");
break;
}
}

void loop() { }
18 changes: 18 additions & 0 deletions src/sim900.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ bool SIM900::handshake() {
return this->isSuccessCommand();
}

bool SIM900::isCardReady() {
this->sendCommand(F("AT+CPIN?"));
return this->isSuccessCommand();
}

bool SIM900::changeCardPin(uint8_t pin) {
if(pin > 9999)
return false;

this->sendCommand("AT+CPIN=\"" + String(pin) + "\"");
return this->isSuccessCommand();
}

void SIM900::close() {
this->sim900->end();
}
Expand Down Expand Up @@ -313,6 +326,11 @@ SIM900CardAccount SIM900::retrievePhonebook(uint8_t index) {
return accountInfo;
}

bool SIM900::deletePhonebook(uint8_t index) {
this->sendCommand("AT+CPBW=" + String(index));
return this->isSuccessCommand();
}

SIM900CardAccount SIM900::cardNumber() {
this->sendCommand(F("AT+CNUM"));

Expand Down
6 changes: 5 additions & 1 deletion src/sim900.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class SIM900 {
bool handshake();
void close();

bool isCardReady();
bool changeCardPin(uint8_t pin);

SIM900DialResult dialUp(String number);
SIM900DialResult redialUp();
SIM900DialResult acceptIncomingCall();
Expand All @@ -43,7 +46,8 @@ class SIM900 {
bool updateRtc(SIM900RTC config);

bool savePhonebook(uint8_t index, SIM900CardAccount account);
SIM900CardAccount retrievePhonebook(uint8_t index);
bool deletePhonebook(uint8_t index);
SIM900CardAccount retrievePhonebook(uint8_t index);

String manufacturer();
String softwareRelease();
Expand Down

0 comments on commit c405a6d

Please sign in to comment.