-->
Page 1 of 1

how to connect to google firebase by editting this code?

PostPosted: Wed Dec 28, 2022 2:00 am
by KUGAN MORGAN
I've made a project by using 3 slave nodemcu to collect current reading using ACS712 and send it to master nodemcu. The master nodemcu should send data to phone to view the data through a mobile application. I used Thingspeak at first to view data of the power consumption but i want to use google firebase to view the power consumption easier for my application view. Any help?

#include <ESP8266WiFi.h>;

#include <WiFiClient.h>;

#include <ThingSpeak.h>;

const char* ssid = "Wifi_Project"; //Your Network SSID

const char* password = "1111aaaa"; //Your Network Password

WiFiClient client;

unsigned long myChannelNumber = 1947152; //Your Channel Number (Without Brackets)

const char * myWriteAPIKey = "QA02MFMGFJVIDBZR"; //Your Write API Key

#include <SoftwareSerial.h>
SoftwareSerial SMESerial (D6, D7);
int xVal, yVal, zVal;
float xtotal,ytotal,ztotal,xprice,yprice,zprice;

void setup() {
Serial.begin(9600);
SMESerial.begin(9600);
WiFi.begin(ssid, password);
ThingSpeak.begin(client);

}

void loop() {

if (SMESerial.available()<1) return;
char R=SMESerial.read();
int data=SMESerial.parseInt();

if (R == 'x')
xVal = data;
xtotal = xVal + xtotal;
xprice = xtotal*0.1;

Serial.print("X = ");
Serial.println(xtotal);

ThingSpeak.setField(1, xtotal);
ThingSpeak.setField(2, xprice);

if (R == 'y')
yVal = data;
ytotal = yVal + ytotal;
yprice = ytotal*0.1;

Serial.print("Y = ");
Serial.println(ytotal);

ThingSpeak.setField(3, ytotal);
ThingSpeak.setField(4, yprice);

if (R == 'z')
zVal = data;
ztotal = zVal + ztotal;
zprice = ztotal*0.1;

Serial.print("Z = ");
Serial.println(ztotal);

ThingSpeak.setField(5, ztotal);
ThingSpeak.setField(6, zprice);

ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

}

Re: how to connect to google firebase by editting this code?

PostPosted: Fri Jan 13, 2023 7:48 am
by rooppoorali
You have to download, install and include the FirebaseArduino.h library.
You can use this code for reference: https://how2electronics.com/led-control ... e-esp8266/