Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. #include <Sim800l.h>
  2. #include <SoftwareSerial.h>
  3. #include <EDB.h>
  4.  
  5. #include <SPI.h>
  6. #include <SD.h>
  7.  
  8. #define SD_PIN 4
  9. #define TABLE_SIZE 3686793216
  10. Sim800l Sim800l;
  11. String text; // to storage the text of the sms
  12. int index = 1; // to indicate the message to read.
  13.  
  14. String phone_no;
  15.  
  16. //database initialization
  17. char* sys_var = "/db/sys_var.db";
  18. File dbFile;
  19.  
  20. struct logEventgetsysvar{
  21. int id;
  22. char username[11];
  23. char password[5];
  24. float liquid_price;
  25. bool delivered;
  26. }
  27. logEventgetsysvar;
  28.  
  29. void writer(unsigned long address, byte data){
  30. digitalWrite(13, HIGH);
  31. dbFile.seek(address);
  32. dbFile.write(data);
  33. dbFile.flush();
  34. digitalWrite(13, LOW);
  35. }
  36. byte reader(unsigned long address){
  37. digitalWrite(13, HIGH);
  38. dbFile.seek(address);
  39. byte b = dbFile.read();
  40. digitalWrite(13, LOW);
  41. return b;
  42. }
  43. EDB db(&writer, &reader);
  44.  
  45.  
  46.  
  47. void setup(){
  48. Serial.begin(9600); // only for debug the results .
  49. //SPI.begin();
  50. randomSeed(analogRead(0));
  51.  
  52. get_sys_var(); // Initialization of System Variable Database and read of liquid price from the SD Card
  53.  
  54. Sim800l.begin(); // initialize the library.
  55. Serial.println("Initialization Complete");
  56. }
  57.  
  58. void loop(){
  59.  
  60. Serial.println("Starting to Read");
  61.  
  62.  
  63. text=Sim800l.readSms(index); //Code hangs here and does not read the SMS.
  64. phone_no=Sim800l.getNumberSms(index);
  65.  
  66. Serial.println("Read Message");
  67.  
  68. } //end of loop
  69.  
  70. void get_sys_var()
  71. {
  72.  
  73. if (!SD.begin(SD_PIN)){
  74. Serial.println("No SD-card.");
  75. return;
  76. }
  77.  
  78. if (!SD.exists("/db")){
  79. Serial.println("Error: System Variable Database Does not Exist...");
  80. exit;
  81. }
  82.  
  83. if (SD.exists(sys_var)){
  84. dbFile = SD.open(sys_var, FILE_WRITE);
  85.  
  86. if (!dbFile){
  87. Serial.println("Error: System Variable Database Does not Exist...");
  88. exit;
  89. }
  90. if (dbFile){
  91. Serial.print("Opening current table... ");
  92. EDB_Status result = db.open(0);
  93. if (result == EDB_OK){
  94. Serial.println("DONE");
  95. }else {
  96. Serial.println("ERROR");
  97. Serial.println("Did not find database in the file " + String(sys_var));
  98. exit;
  99. return;
  100. }
  101. }else {
  102. Serial.println("Could not open file " + String(sys_var));
  103. return;
  104. }
  105. }else {
  106. Serial.println("Error: System Variable Database Does not Exist...");
  107. exit;
  108. }
  109. //-------------------------------------------------------------------------------
  110. // Read function of liquid price
  111. //---------------------------------------------------------------------------------
  112.  
  113. Serial.println("Reading Liquid Price: ");
  114.  
  115. EDB_Status result = db.readRec(1, EDB_REC logEventgetsysvar);
  116. if (result == EDB_OK)
  117. {
  118. memcpy(session_username, logEventgetsysvar.username, 11);
  119. memcpy(session_password, logEventgetsysvar.password, 5);
  120. session_liquid_price = logEventgetsysvar.liquid_price;
  121. }
  122. Serial.print("Username: ");
  123. Serial.println(session_username);
  124.  
  125. Serial.print("Password: ");
  126. Serial.println(session_password);
  127.  
  128. Serial.print("Liquid Price: ");
  129. Serial.println(session_liquid_price);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement