我想让洛拉接收器在将洛拉消息发送到firebase的地方,但我总是失败
这是我的代码。我失败了很多次。我设法在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.
#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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,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.