我创建了一个程序来显示从 nodemcu ESP8266 + PZEM-004T 发送的实时 firebase 数据,但数据没有出现在实时数据库中,但在串行监视器 Arduino IDE 上它工作正常。
我的输出:
我的草图:
#include <PZEM004Tv30.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST "iotmonitor-d8aee-default-rtdb.firebaseio.com" //Firebase url non SSL(https://)
#define FIREBASE_AUTH "C7j...Gid" //Secret Key Database
#define WIFI_SSID "IKWAN_BRILink" //Nama WiFi
#define WIFI_PASSWORD "Orbit121" // Password Wifi
PZEM004Tv30 pzem(12, 13);
float harga_KWh = 1.444; //Biaya per KWh
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float energy = pzem.energy();
if (isnan(voltage) ) {
voltage = 0;
}
if (isnan(current) ) {
current = 0;
}
if (isnan(power) ) {
power = 0;
}
if (isnan(energy) ) {
energy = 0;
}
float totalHarga = energy * harga_KWh;
Firebase.setString("volt", String(voltage));
Firebase.setString("current", String(current));
Firebase.setFloat("watt", power);
Firebase.setString("kwh", String(energy, 1));
Firebase.setString("rp", String(totalHarga, 3));
Serial.print("Voltage = ");
Serial.print(voltage);
Serial.println("v");
Serial.print("Current = ");
Serial.print(current, 2);
Serial.println("A");
Serial.print("Watt = ");
Serial.print(power);
Serial.println("watt");
Serial.print("KWh = ");
Serial.print(energy, 1);
Serial.println("KWh");
Serial.print("Harga = Rp ");
Serial.print(totalHarga, 3);
Serial.println();
delay(2000);
}