Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Sim800l.h>
- #include <SoftwareSerial.h>
- #include <EDB.h>
- #include <SPI.h>
- #include <SD.h>
- #define SD_PIN 4
- #define TABLE_SIZE 3686793216
- Sim800l Sim800l;
- String text; // to storage the text of the sms
- int index = 1; // to indicate the message to read.
- String phone_no;
- //database initialization
- char* sys_var = "/db/sys_var.db";
- File dbFile;
- struct logEventgetsysvar{
- int id;
- char username[11];
- char password[5];
- float liquid_price;
- bool delivered;
- }
- logEventgetsysvar;
- void writer(unsigned long address, byte data){
- digitalWrite(13, HIGH);
- dbFile.seek(address);
- dbFile.write(data);
- dbFile.flush();
- digitalWrite(13, LOW);
- }
- byte reader(unsigned long address){
- digitalWrite(13, HIGH);
- dbFile.seek(address);
- byte b = dbFile.read();
- digitalWrite(13, LOW);
- return b;
- }
- EDB db(&writer, &reader);
- void setup(){
- Serial.begin(9600); // only for debug the results .
- //SPI.begin();
- randomSeed(analogRead(0));
- get_sys_var(); // Initialization of System Variable Database and read of liquid price from the SD Card
- Sim800l.begin(); // initialize the library.
- Serial.println("Initialization Complete");
- }
- void loop(){
- Serial.println("Starting to Read");
- text=Sim800l.readSms(index); //Code hangs here and does not read the SMS.
- phone_no=Sim800l.getNumberSms(index);
- Serial.println("Read Message");
- } //end of loop
- void get_sys_var()
- {
- if (!SD.begin(SD_PIN)){
- Serial.println("No SD-card.");
- return;
- }
- if (!SD.exists("/db")){
- Serial.println("Error: System Variable Database Does not Exist...");
- exit;
- }
- if (SD.exists(sys_var)){
- dbFile = SD.open(sys_var, FILE_WRITE);
- if (!dbFile){
- Serial.println("Error: System Variable Database Does not Exist...");
- exit;
- }
- if (dbFile){
- Serial.print("Opening current table... ");
- EDB_Status result = db.open(0);
- if (result == EDB_OK){
- Serial.println("DONE");
- }else {
- Serial.println("ERROR");
- Serial.println("Did not find database in the file " + String(sys_var));
- exit;
- return;
- }
- }else {
- Serial.println("Could not open file " + String(sys_var));
- return;
- }
- }else {
- Serial.println("Error: System Variable Database Does not Exist...");
- exit;
- }
- //-------------------------------------------------------------------------------
- // Read function of liquid price
- //---------------------------------------------------------------------------------
- Serial.println("Reading Liquid Price: ");
- EDB_Status result = db.readRec(1, EDB_REC logEventgetsysvar);
- if (result == EDB_OK)
- {
- memcpy(session_username, logEventgetsysvar.username, 11);
- memcpy(session_password, logEventgetsysvar.password, 5);
- session_liquid_price = logEventgetsysvar.liquid_price;
- }
- Serial.print("Username: ");
- Serial.println(session_username);
- Serial.print("Password: ");
- Serial.println(session_password);
- Serial.print("Liquid Price: ");
- Serial.println(session_liquid_price);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement