Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #include <BearSSLHelpers.h>
  2. #include <CertStoreBearSSL.h>
  3. #include <ESP8266WiFi.h>
  4. #include <ESP8266WiFiAP.h>
  5. #include <ESP8266WiFiGeneric.h>
  6. #include <ESP8266WiFiMulti.h>
  7. #include <ESP8266WiFiScan.h>
  8. #include <ESP8266WiFiSTA.h>
  9. #include <ESP8266WiFiType.h>
  10. #include <WiFiClient.h>
  11. #include <WiFiClientSecure.h>
  12. #include <WiFiClientSecureAxTLS.h>
  13. #include <WiFiClientSecureBearSSL.h>
  14. #include <WiFiServer.h>
  15. #include <WiFiServerSecure.h>
  16. #include <WiFiServerSecureAxTLS.h>
  17. #include <WiFiServerSecureBearSSL.h>
  18. #include <WiFiUdp.h>
  19.  
  20. #include <Firebase.h>
  21. #include <FirebaseArduino.h>
  22. #include <FirebaseCloudMessaging.h>
  23. #include <FirebaseError.h>
  24. #include <FirebaseHttpClient.h>
  25. #include <FirebaseObject.h>
  26.  
  27. #include <ArduinoJson.h>
  28.  
  29. #include <SoftwareSerial.h>
  30. //firebase and wifi
  31. #define FIREBASE_HOST "my-shopping-bud.firebaseio.com"
  32. #define FIREBASE_AUTH "rkyF4AuzssSIO5VYRswiVtvA1mtmMBJ6uib0O6iP"
  33. #define WIFI_SSID "****"
  34. #define WIFI_PASSWORD "****"
  35.  
  36. const int disp=9;
  37. //int j;
  38. int tx=10,rx=13;
  39. SoftwareSerial emSerial(rx,tx); //EM18 Rx,Tx
  40. int buttonState2 = 0;
  41. int count = 0; // count = 0
  42. char input[12]; // character array of size 12
  43. int count_arr[5]={0,0,0,0,0};
  44. int i,cnt,total=0;
  45. int price[5]={295,20,50,500,15};
  46. char id_arr[6]={'2','F','7','E','3'};
  47. char *myStrings1[] = {"Rice Rs.295", "Oreo Rs.20", "Silk Rs.50",
  48. "Ghee Rs.500", "Nestle Rs.15", "TOTAL : "
  49. };
  50. char *myStrings2[] = {"Removed Rice Rs.295", "Removed Oreo Rs.20", "Removed Silk Rs.50",
  51. "Removed Ghee Rs.500", "Removed Nestle Rs.15", "TOTAL : "
  52. };
  53.  
  54. void setup()
  55. {
  56. Serial.begin(9600);
  57. emSerial.begin(9600);
  58.  
  59.  
  60. //connect to wi-fi
  61. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  62. Serial.print("connecting");
  63. while (WiFi.status() != WL_CONNECTED) {
  64. Serial.print(".");
  65. delay(500);
  66.  
  67. pinMode(disp,INPUT);
  68. }
  69. Serial.println();
  70. Serial.print("connected: ");
  71. Serial.println(WiFi.localIP());
  72.  
  73. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  74. Serial.println("Firebase Connected");
  75. }
  76.  
  77. int n = 0;
  78.  
  79. void loop()
  80. {
  81.  
  82.  
  83. if(emSerial.available())
  84. {
  85. Serial.println("Card reader");
  86. count=0;
  87. while(emSerial.available() && count < 12) // Read 12 characters and store them in input array
  88. {
  89. input[count] = emSerial.read();
  90. count++;
  91. delay(5);
  92. }
  93. Serial.print("id inpiut");
  94. Serial.println(input);
  95. for(i=0;i<5;i++)
  96. {
  97. if(input[10] == id_arr[i])
  98. {
  99. cnt=i;
  100. break;
  101. }
  102. }
  103.  
  104. if(count_arr[cnt] == 0)
  105. {
  106. total=total+price[cnt];
  107. Serial.println(myStrings1[cnt]);
  108. Serial.print("TOTAL : ");
  109. Serial.println(total);
  110. count_arr[cnt]=1;
  111. }
  112. else if(count_arr[cnt] == 1)
  113. {
  114. total=total-price[cnt];
  115. Serial.println(myStrings2[cnt]);
  116. Serial.print("TOTAL : ");
  117. Serial.println(total);
  118. count_arr[cnt]=0;
  119. }
  120.  
  121. }
  122. buttonState2 = digitalRead(disp); // read the state of the pushbutton value:
  123.  
  124. // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  125. if (buttonState2 == HIGH)
  126. {
  127.  
  128. j=1;
  129. for(i=0;i<5;i++)
  130. {
  131. if(count_arr[i]==1)
  132. {
  133.  
  134. Firebase.setString("Items in Cart: ", myStrings1[i]);
  135. // handle error
  136. if (Firebase.failed())
  137. {
  138. Serial.print("setting /message failed:");
  139. Serial.println(Firebase.error());
  140. return;
  141. }
  142. delay(1000);
  143. String name = Firebase.pushInt("Total: ",total);
  144. // handle error
  145. if (Firebase.failed())
  146. {
  147. Serial.print("pushing /logs failed:");
  148. Serial.println(Firebase.error());
  149. return;
  150. }
  151. //j++;
  152. }
  153. delay(2000);
  154.  
  155. }
  156. }
  157. int test = 5;
  158. String name = Firebase.pushInt("cart",test);
  159. // handle error
  160. if (Firebase.failed()) {
  161. Serial.print("pushing /logs failed:");
  162. Serial.println(Firebase.error());
  163. return;
  164. }
  165. Serial.print("pushed: /cart/");
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement