//#include <Adafruit_ILI9341.h>
//#include <Keypad.h>
#include <ESP32Firebase.h>
//#include <WiFi.h>
#include <Arduino.h>
#include <ArduinoJson.h>
using namespace std;
//#include <FirebaseESP32.h>
#include <string>
/*-------Firebase Init------*/
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define API_KEY "AIzaSyAnIyBy4OkkpnzfaqwVfdFFsntPQZNqgoc"
#define DATABASE_URL "https://votersdatabase-default-rtdb.firebaseio.com/"
string defaultPath = "VotingMachine";
//FirebaseJson json;
//FirebaseData fbdo;
//FirebaseAuth auth;
//FirebaseConfig config;
Firebase firebase(DATABASE_URL);
/* Other veriable Initialization */
uint8_t state;
const char* ElectID;
unsigned long sendDataPrevMillis = 0;
bool signupOK = false;
DynamicJsonDocument FingerDatas(2048);
DynamicJsonDocument Candidates(2048);
DynamicJsonDocument VoteHistory(2048);
const char* SelectedVoterName;
const char* SelectedVoterID;
char ID_Value[10];
uint8_t b_len = 9;
uint8_t p_len = 5;
uint8_t ValueIndex;
int candidatecount = 5;
string CandidateID[50];
bool isPrint = true;
/*
void GetCandidateData()
{
string path = defaultPath + "/Candidates";
if (Firebase.ready() && signupOK )
{
sendDataPrevMillis = millis();
if (Firebase.getString(fbdo, path.c_str()))
{
Candidates.clear();
DeserializationError error1 = deserializeJson(Candidates, fbdo.stringData());
if (error1)
{
Serial.print("Failed to parse Candidates JSON: ");
Serial.println(error1.f_str());
}
int index = 1;
for (JsonVariant value : Candidates.as<JsonArray>())
{
if (!value.isNull())
{
value["IndexID"] = index++;
const char *CandicateID = value["CandicateID"];
const char *CandidateName = value["CandidateName"];
const char *Election = value["Election"];
Serial.print("CandicateID: ");
Serial.println(CandicateID);
Serial.print("CandidateName: ");
Serial.println(CandidateName);
Serial.print("Election: ");
Serial.println(Election);
Serial.println();
}
}
}
}
}
*/
void getvote()
{
DynamicJsonDocument object(2048);
string Path = defaultPath + "/Voting";
String data = firebase.getString(Path.c_str());
deserializeJson(VoteHistory, object);
Serial.println("DataFrom voting....");
Serial.println(data);
}
void StoreVote()
{
const char* ElectID = "E1";
const char* Candt = "C4";
const char* SelectedVoterID = "F1";
int cnt = 2;
string id = "V" + cnt;
// Create a JsonDocument
DynamicJsonDocument object(2048);
// Create an object within the document
//JsonPair object = doc.to<JsonObject>(); //CandiID, ElectID, FingID, ID
object["ID"] = id;
object["CandiID"] = Candt;
object["ElectID"] = ElectID;
object["FingID"] = SelectedVoterID;
// Serialize the object to a string
String data;
serializeJson(object, data);
// Print the serialized data
Serial.println(data);
// Construct the path for the database
string path = defaultPath + "/Voting/";
firebase.setString("Example/setString", "It's Working");
//firebase.setString(path.c_str(), data);
int res2 = firebase.pushString(path.c_str(), data);
Serial.print("data send to db");
//Serial.println(res);
Serial.println("//");
Serial.println(res2);
//serialize
//send
//
}
void setup()
{
Serial.begin(9600);
firebase.json(true);
//GetCandidateData();
StoreVote();
getvote();
//ElectID = "E1";
}
void loop()
{
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK