Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 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. void setup(){
  46. Serial.begin(9600); // only for debug the results .
  47. //SPI.begin();
  48. randomSeed(analogRead(0));
  49.  
  50. get_sys_var(); // Initialization of System Variable Database and read of liquid price from the SD Card
  51.  
  52. Sim800l.begin(); // initialize the library.
  53. Serial.println("Initialization Complete");
  54. }
  55.  
  56. void loop(){
  57. Serial.println("Starting to Read");
  58.  
  59. text=Sim800l.readSms(index); //Code hangs here and does not read the SMS.
  60. phone_no=Sim800l.getNumberSms(index);
  61.  
  62. Serial.println("Read Message");
  63. } //end of loop
  64.  
  65. void get_sys_var()
  66. {
  67. if (!SD.begin(SD_PIN)){
  68. Serial.println("No SD-card.");
  69. return;
  70. }
  71.  
  72. if (!SD.exists("/db")){
  73. Serial.println("Error: System Variable Database Does not Exist...");
  74. exit;
  75. }
  76.  
  77. if (SD.exists(sys_var)){
  78. dbFile = SD.open(sys_var, FILE_WRITE);
  79.  
  80. if (!dbFile){
  81. Serial.println("Error: System Variable Database Does not Exist...");
  82. exit;
  83. }
  84. if (dbFile){
  85. Serial.print("Opening current table... ");
  86. EDB_Status result = db.open(0);
  87. if (result == EDB_OK){
  88. Serial.println("DONE");
  89. }else {
  90. Serial.println("ERROR");
  91. Serial.println("Did not find database in the file " + String(sys_var));
  92. exit;
  93. return;
  94. }
  95. }else {
  96. Serial.println("Could not open file " + String(sys_var));
  97. return;
  98. }
  99. }else {
  100. Serial.println("Error: System Variable Database Does not Exist...");
  101. exit;
  102. }
  103. //-------------------------------------------------------------------------------
  104. // Read function of liquid price
  105. //---------------------------------------------------------------------------------
  106.  
  107. Serial.println("Reading Liquid Price: ");
  108.  
  109. EDB_Status result = db.readRec(1, EDB_REC logEventgetsysvar);
  110. if (result == EDB_OK)
  111. {
  112. memcpy(session_username, logEventgetsysvar.username, 11);
  113. memcpy(session_password, logEventgetsysvar.password, 5);
  114. session_liquid_price = logEventgetsysvar.liquid_price;
  115. }
  116. Serial.print("Username: ");
  117. Serial.println(session_username);
  118.  
  119. Serial.print("Password: ");
  120. Serial.println(session_password);
  121.  
  122. Serial.print("Liquid Price: ");
  123. Serial.println(session_liquid_price);
  124. }
  125.  
  126. get_sys_var()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement