我想让洛拉接收器在将洛拉消息发送到firebase的地方,但我总是失败

发布于 2025-02-11 05:29:15 字数 2932 浏览 1 评论 0原文

这是我的代码。我失败了很多次。我设法在Lora接收器和Lora发射器之间发送了消息,但未能上传到Firebase。据说我需要主表达式,但是当我查看其他代码并遵循该代码时,它不使用Arduino IDE推荐的代码。

我正在使用,ESP32和RFM95 SX1276。

#include <SPI.h>
#include <LoRa.h>

#include <WiFi.h>
#include <WiFiClient.h>
const char* ssid = "*******"; 
const char* password = "******";

#include <Firebase.h>
#define FIREBASE_HOST "************************"
#define FIREBASE_AUTH "************"

#define ss 5
#define rst 14
#define dio0 2
#define BAND 915E6

// Initialize variables to get and save LoRa data
int rssi;
String loRaMessage;
String temperature;
String humidity;
String readingID;
String suhu;
String lembab;
FirebaseData data;

String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATURE"){
    return temperature;
  }
  else if(var == "HUMIDITY"){
    return humidity;
  } else if (var == "RRSI") {
    return String(rssi);
  }
  return String();
}

void startLoRA(){
  int counter;
  LoRa.setPins(ss, rst, dio0);
  while (!LoRa.begin(BAND) && counter < 10) {
    Serial.print(".");
    counter++;
    delay(500);
  }
  if (counter == 10) {
    // Increment readingID on every new reading
    Serial.println("Starting LoRa failed!"); 
  }
  Serial.println("LoRa Initialization OK!");
}

void setup(){
  Serial.begin(115200);
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  //WIFI 
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() !=WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("Connected to the Network");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  startLoRA();
}

void loop(){
  // Check if there are LoRa packets available
  int packetSize = LoRa.parsePacket();
  if (packetSize){ 
    String LoRaData = LoRa.readString();
    while (LoRa.available()){
      Serial.print((char)LoRa.read());
    }

   // Get RSSI
    rssi = LoRa.packetRssi();
    Serial.print("With RSSI ");
    Serial.println(rssi);

    int pos1 = LoRaData.indexOf('/');
    int pos2 = LoRaData.indexOf('&');
    
    readingID = LoRaData.substring(0,pos1);
    temperature = LoRaData.substring(pos1 + 1, pos2);
    humidity = LoRaData.substring(pos2 + 1, LoRaData.length());

    if (readingID =="001"){
      suhu= temperature;
      Serial.print(F("Suhu :"));
      Serial.println(suhu);
      Serial.println(F("C"));

      lembab= humidity;
      Serial.print(F("Kelembaban : "));
      Serial.print(lembab);
      Serial.println("%");
      
   
   String fbsuhu = String (suhu) + String("C");
   String fblembab = String (lembab) + String("%");
   Firebase.setString (FirebaseData, "Suhu :", fbsuhu);
   Firebase.setString (FirebaseData, "Lembab :", fblembab);
  }
 }
}

Here's my code. I failed so many times. I managed to send the message between the LoRa receiver and the LoRa transmitter, but failed to upload to Firebase. It's said that I need primary expression, but when I look at other code and follow that, it doesn't use the code recommended by Arduino IDE.

I'm using and ESP32 and RFM95 SX1276.

Error

#include <SPI.h>
#include <LoRa.h>

#include <WiFi.h>
#include <WiFiClient.h>
const char* ssid = "*******"; 
const char* password = "******";

#include <Firebase.h>
#define FIREBASE_HOST "************************"
#define FIREBASE_AUTH "************"

#define ss 5
#define rst 14
#define dio0 2
#define BAND 915E6

// Initialize variables to get and save LoRa data
int rssi;
String loRaMessage;
String temperature;
String humidity;
String readingID;
String suhu;
String lembab;
FirebaseData data;

String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATURE"){
    return temperature;
  }
  else if(var == "HUMIDITY"){
    return humidity;
  } else if (var == "RRSI") {
    return String(rssi);
  }
  return String();
}

void startLoRA(){
  int counter;
  LoRa.setPins(ss, rst, dio0);
  while (!LoRa.begin(BAND) && counter < 10) {
    Serial.print(".");
    counter++;
    delay(500);
  }
  if (counter == 10) {
    // Increment readingID on every new reading
    Serial.println("Starting LoRa failed!"); 
  }
  Serial.println("LoRa Initialization OK!");
}

void setup(){
  Serial.begin(115200);
  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  //WIFI 
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi");
  while (WiFi.status() !=WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("Connected to the Network");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
  startLoRA();
}

void loop(){
  // Check if there are LoRa packets available
  int packetSize = LoRa.parsePacket();
  if (packetSize){ 
    String LoRaData = LoRa.readString();
    while (LoRa.available()){
      Serial.print((char)LoRa.read());
    }

   // Get RSSI
    rssi = LoRa.packetRssi();
    Serial.print("With RSSI ");
    Serial.println(rssi);

    int pos1 = LoRaData.indexOf('/');
    int pos2 = LoRaData.indexOf('&');
    
    readingID = LoRaData.substring(0,pos1);
    temperature = LoRaData.substring(pos1 + 1, pos2);
    humidity = LoRaData.substring(pos2 + 1, LoRaData.length());

    if (readingID =="001"){
      suhu= temperature;
      Serial.print(F("Suhu :"));
      Serial.println(suhu);
      Serial.println(F("C"));

      lembab= humidity;
      Serial.print(F("Kelembaban : "));
      Serial.print(lembab);
      Serial.println("%");
      
   
   String fbsuhu = String (suhu) + String("C");
   String fblembab = String (lembab) + String("%");
   Firebase.setString (FirebaseData, "Suhu :", fbsuhu);
   Firebase.setString (FirebaseData, "Lembab :", fblembab);
  }
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2025-02-18 05:29:15

据我了解,Firebase库是firebase.setstring(key,value);。因此只有两个论点。你经过三个。

As far as I understand the Firebase library, it's Firebase.setString(key, value);. So only two arguments. You are passing three.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文