我正在使用nodemcu作为使用df机器人库从sim 808模块获取数据并将收集到的数据发送到Firebase实时数据库的一种方式。尽管代码中没有错误,但是我没有发送任何数据。下面的代码只是firebasearduino和dfrobot库的示例代码的修改版本。
这是我正在使用的代码:
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#define FIREBASE_HOST "mcuu-xxxx.firebaseio.com"
#define FIREBASE_AUTH "xxxxxxxxxxxxx"
#define WIFI_SSID "xxxxxxx"
#define WIFI_PASSWORD "xxxxxxxxxx"
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define PIN_TX 4
#define PIN_RX 5
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
// connect to wifi.
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);
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
}
int n = 0;
void loop() {
Serial.print("Latgps: ");
Serial.println(sim808.GPSdata.lat, 8);
Serial.print("Longps: ");
Serial.println(sim808.GPSdata.lon, 8);
// set value
Firebase.setFloat("latitude",sim808.GPSdata.lat);
// handle error
if (Firebase.failed()) {
Serial.print("firebase connection failed");
Serial.println(Firebase.error());
return;
}
delay(1000);
// update value
Firebase.setFloat("longitude", sim808.GPSdata.lon);
// handle error
if (Firebase.failed()) {
Serial.print("firebase connection failed");
Serial.println(Firebase.error());
return;
}
delay(1000);
// get value
Serial.print("latitudefire: ");
Serial.println(Firebase.getFloat("latitude"));
Serial.print("longitudefire: ");
Serial.println(Firebase.getFloat("longitude"));
delay(1000);
// set string value
Firebase.setString("message", "xxxxxxxx");
// handle error
if (Firebase.failed()) {
Serial.print("setting /message failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
}
SERIAL MONITOR:
connected: 192.168.1.6
Open the GPS power success
Latgps: 0.00000000
Longps: 0.00000000
latitudefire: 0.00
longitudefire: 0.00
Latgps: 0.00000000
Longps: 0.00000000
latitudefire: 0.00
longitudefire: 0.00
Latgps: 0.00000000
Longps: 0.00000000
latitudefire: 0.00
longitudefire: 0.00