Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <BearSSLHelpers.h>
- #include <CertStoreBearSSL.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiAP.h>
- #include <ESP8266WiFiGeneric.h>
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266WiFiScan.h>
- #include <ESP8266WiFiSTA.h>
- #include <ESP8266WiFiType.h>
- #include <WiFiClient.h>
- #include <WiFiClientSecure.h>
- #include <WiFiClientSecureAxTLS.h>
- #include <WiFiClientSecureBearSSL.h>
- #include <WiFiServer.h>
- #include <WiFiServerSecure.h>
- #include <WiFiServerSecureAxTLS.h>
- #include <WiFiServerSecureBearSSL.h>
- #include <WiFiUdp.h>
- #include <Firebase.h>
- #include <FirebaseArduino.h>
- #include <FirebaseCloudMessaging.h>
- #include <FirebaseError.h>
- #include <FirebaseHttpClient.h>
- #include <FirebaseObject.h>
- #include <ArduinoJson.h>
- #include <SoftwareSerial.h>
- //firebase and wifi
- #define FIREBASE_HOST "my-shopping-bud.firebaseio.com"
- #define FIREBASE_AUTH "rkyF4AuzssSIO5VYRswiVtvA1mtmMBJ6uib0O6iP"
- #define WIFI_SSID "****"
- #define WIFI_PASSWORD "****"
- const int disp=9;
- //int j;
- int tx=10,rx=13;
- SoftwareSerial emSerial(rx,tx); //EM18 Rx,Tx
- int buttonState2 = 0;
- int count = 0; // count = 0
- char input[12]; // character array of size 12
- int count_arr[5]={0,0,0,0,0};
- int i,cnt,total=0;
- int price[5]={295,20,50,500,15};
- char id_arr[6]={'2','F','7','E','3'};
- char *myStrings1[] = {"Rice Rs.295", "Oreo Rs.20", "Silk Rs.50",
- "Ghee Rs.500", "Nestle Rs.15", "TOTAL : "
- };
- char *myStrings2[] = {"Removed Rice Rs.295", "Removed Oreo Rs.20", "Removed Silk Rs.50",
- "Removed Ghee Rs.500", "Removed Nestle Rs.15", "TOTAL : "
- };
- void setup()
- {
- Serial.begin(9600);
- emSerial.begin(9600);
- //connect to wi-fi
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- Serial.print("connecting");
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print(".");
- delay(500);
- pinMode(disp,INPUT);
- }
- Serial.println();
- Serial.print("connected: ");
- Serial.println(WiFi.localIP());
- Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
- Serial.println("Firebase Connected");
- }
- int n = 0;
- void loop()
- {
- if(emSerial.available())
- {
- Serial.println("Card reader");
- count=0;
- while(emSerial.available() && count < 12) // Read 12 characters and store them in input array
- {
- input[count] = emSerial.read();
- count++;
- delay(5);
- }
- Serial.print("id inpiut");
- Serial.println(input);
- for(i=0;i<5;i++)
- {
- if(input[10] == id_arr[i])
- {
- cnt=i;
- break;
- }
- }
- if(count_arr[cnt] == 0)
- {
- total=total+price[cnt];
- Serial.println(myStrings1[cnt]);
- Serial.print("TOTAL : ");
- Serial.println(total);
- count_arr[cnt]=1;
- }
- else if(count_arr[cnt] == 1)
- {
- total=total-price[cnt];
- Serial.println(myStrings2[cnt]);
- Serial.print("TOTAL : ");
- Serial.println(total);
- count_arr[cnt]=0;
- }
- }
- buttonState2 = digitalRead(disp); // read the state of the pushbutton value:
- // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
- if (buttonState2 == HIGH)
- {
- j=1;
- for(i=0;i<5;i++)
- {
- if(count_arr[i]==1)
- {
- Firebase.setString("Items in Cart: ", myStrings1[i]);
- // handle error
- if (Firebase.failed())
- {
- Serial.print("setting /message failed:");
- Serial.println(Firebase.error());
- return;
- }
- delay(1000);
- String name = Firebase.pushInt("Total: ",total);
- // handle error
- if (Firebase.failed())
- {
- Serial.print("pushing /logs failed:");
- Serial.println(Firebase.error());
- return;
- }
- //j++;
- }
- delay(2000);
- }
- }
- int test = 5;
- String name = Firebase.pushInt("cart",test);
- // handle error
- if (Firebase.failed()) {
- Serial.print("pushing /logs failed:");
- Serial.println(Firebase.error());
- return;
- }
- Serial.print("pushed: /cart/");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement