节点 MCU(ESP 8266)与火力 [英] Node MCU(ESP 8266) with firebase

查看:32
本文介绍了节点 MCU(ESP 8266)与火力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我上传到 ESP8266 以连接到 Firebase 的代码.

 #include #include <FirebaseArduino.h>#define FIREBASE_HOST "*******.firebaseio.com"#define FIREBASE_AUTH "68GM**************m4k0IPLXF4G1"#define WIFI_SSID "IDR"#define WIFI_PASSWORD "****"#define LED 2无效设置(){pinMode(LED,输出);数字写入(LED,0);数字写入(LED,0);Serial.begin(9600);WiFi.begin(WIFI_SSID, WIFI_PASSWORD);Serial.print("连接");而(WiFi.status()!= WL_CONNECTED){Serial.print(".");延迟(500);}Serial.println();Serial.print("已连接:");Serial.println(WiFi.localIP());Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);Firebase.setInt("LEDStatus",0);}无效循环(){if(Firebase.getInt("LEDStatus")){数字写入(LED,高);}别的{数字写入(LED,低);}延迟(1000);}

使用此代码,我的 NodeMCU 可以毫无问题地连接到 Internet.
问题是 LEDStatus 在 firebase 数据库中没有更新.

我的 FirebaseArduino.h 参考库有问题吗?

任何帮助将不胜感激.

解决方案

我在这里回答了一个类似的问题.>

基本上,由于数据库机密已被弃用(正如在以前的答案中指出的那样),我无法找不到支持新 Firebase Admin SDK 的 Arduino 库,我使用了 Firebase Cloud Functions, 使用 http 触发器 来存储和检索实时数据库中的数据.

您可以在链接的答案中看到 Arduino 草图和云函数的示例.

This is the code I upload to the ESP8266 to connect to firebase.

 #include <ESP8266WiFi.h>
 #include <FirebaseArduino.h>

 #define FIREBASE_HOST "*******.firebaseio.com"
 #define FIREBASE_AUTH "68GM**************m4k0IPLXF4G1"
 #define WIFI_SSID "IDR"
 #define WIFI_PASSWORD "****"

 #define LED 2

 void setup() {
    pinMode(LED,OUTPUT);
    digitalWrite(LED,0);
    digitalWrite(LED,0);
    Serial.begin(9600);
    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);
    Firebase.setInt("LEDStatus",0);
 }   

 void loop() {
    if(Firebase.getInt("LEDStatus"))
    {                            
       digitalWrite(LED,HIGH);
    }
    else
    {
       digitalWrite(LED,LOW);
    }
    delay(1000);
 }

With this code, my NodeMCU can connect to the internet without any issue.
The problem is that the LEDStatus does not update in the firebase database.

Is there something wrong with my FirebaseArduino.h reference library?

Any help would be appreciated.

解决方案

I answered a similar question here.

Basically, as the database secrets are depracated (as it was pointed out in a previus answer), and I couldn't find an Arduino library, that supports the new Firebase Admin SDK, I used Firebase Cloud Functions, with http triggers to store and retrive data from the realtime database.

You can see an example for the Arduino sketch and the cloud function in the linked answer.

这篇关于节点 MCU(ESP 8266)与火力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆