Arduino IDE连接esp8266到Firebase时出现错误

huangapple go评论107阅读模式
英文:

Arduino IDE error when trying to connect esp8266 to firebase

问题

你好,下面是翻译好的部分:

"hello guys i was trying to connect my project to firebase as showed in this video https://youtu.be/Xj1kuApmRCw
but got this erorrs:

d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp: In member function 'int FirebaseRequest::sendRequest(const string&, const string&, char*, const string&, const string&)':
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp:78:1: error: no return statement in function returning non-void [-Werror=return-type]
   78 | }
      | ^

...

Compilation error: exit status 1

i've installed the latest version of esp8266 and "Firebase Arduino Client Library for ESP8266 By Mobitz" but the error still occured. please help

here's my full code:

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <FirebaseArduino.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include<DHT.h>

...

// Your code continues...

and here is the screenshot of my firebase for better understanding:

Arduino IDE连接esp8266到Firebase时出现错误

英文:

hello guys i was trying to connect my project to firebase as showed in this video https://youtu.be/Xj1kuApmRCw
but got this erorrs:

d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp: In member function 'int FirebaseRequest::sendRequest(const string&, const string&, char*, const string&, const string&)':
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp:78:1: error: no return statement in function returning non-void [-Werror=return-type]
   78 | }
      | ^
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp: In member function 'void FirebaseStream::startStreaming(const string&, const string&, const string&)':
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\Firebase.cpp:91:16: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
   91 |   analyzeError("STREAM", status, path_with_auth);
      |                ^~~~~~~~
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp: In member function 'virtual void FirebaseHttpClientEsp8266::begin(const string&)':
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:47:50: error: no matching function for call to 'begin(const char*, const char [60])'
   47 |     http_.begin(url.c_str(), kFirebaseFingerprint);
      |                                                  ^
In file included from d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\NyK\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266.1.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: candidate: 'bool HTTPClient::begin(String, uint16_t, String)' (near match)
  166 |     bool begin(String host, uint16_t port, String uri = "/")  __attribute__ ((error("obsolete API, use ::begin(WiFiClient, host, port, uri)")));
      |          ^~~~~
C:\Users\NyK\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266.1.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note:   conversion of argument 2 would be ill-formed:
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from 'const char*' to 'uint16_t' {aka 'short unsigned int'} [-fpermissive]
   47 |     http_.begin(url.c_str(), kFirebaseFingerprint);
      |                              ^~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              const char*
In file included from d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\NyK\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266.1.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: candidate: 'bool HTTPClient::begin(String, const uint8_t*)' (near match)
  167 |     bool begin(String url, const uint8_t httpsFingerprint[20])  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |          ^~~~~
C:\Users\NyK\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266.1.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note:   conversion of argument 2 would be ill-formed:
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
   47 |     http_.begin(url.c_str(), kFirebaseFingerprint);
      |                              ^~~~~~~~~~~~~~~~~~~~
      |                              |
      |                              const char*
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp: In member function 'virtual void FirebaseHttpClientEsp8266::begin(const string&, const string&)':
d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:51:60: error: invalid conversion from 'const char*' to 'const uint8_t*' {aka 'const unsigned char*'} [-fpermissive]
   51 |     http_.begin(host.c_str(), kFirebasePort, path.c_str(), kFirebaseFingerprint);
      |                                                            ^~~~~~~~~~~~~~~~~~~~
      |                                                            |
      |                                                            const char*
In file included from d:\Kuliah\Mata Kuliah\Internet of Things\Arduino\libraries\FirebaseArduino\src\FirebaseHttpClient_Esp8266.cpp:9:
C:\Users\NyK\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266.1.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:168:70: note:   initializing argument 4 of 'bool HTTPClient::begin(String, uint16_t, String, const uint8_t*)'
  168 |     bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20])  __attribute__ ((error("obsolete API, use ::begin(WiFiClientSecure, ...)")));
      |                                                        ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors

exit status 1

Compilation error: exit status 1

i've installed the latest version of esp8266 and "Firebase Arduino Client Library for ESP8266 By Mobitz" but the error still occured. please help

here's my full code:


#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <FirebaseArduino.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include<DHT.h>

#define FIREBASE_HOST "*****firebaseio.com"
#define FIREBASE_AUTH "*****UKBpSMo07nUT8ZWYS9"

#define WIFI_SSID "******"
#define WIFI_PASSWORD "******"

#define DHTPIN D5
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

bool light;
bool fan;

unsigned long previousMillis = 0;
const long interval = 10000;

void setup() {
  pinMode(D1, OUTPUT);
  Serial.begin(115200);
  delay(500);
  WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
  Serial.println("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);
  dht.begin();

  delay(2000);
  // put your setup code here, to run once:
}

void readDatas(){
  float h=dht.readHumidity();
  float t=dht.readTemperature(); 

  Firebase.setFloat("Data/Temperature:",t);
  Firebase.setFloat("Data/Humidity:",h); 
}

void loop() {
  light = Firebase.getBool("LightStates/switch");
  Serial.println(light);
  if(light==true){
    digitalWrite(D6, HIGH);
  }
  if(light==false){
    digitalWrite(D6, LOW);
  }

  fan = Firebase.getBool("FanStates/switch");
  Serial.println(fan);
  if(fan==true){
    digitalWrite(D7, HIGH);
  }
  if(fan==false){
    digitalWrite(D7, LOW);
  }

  unsigned long currentMillis = millis();
  if(currentMillis-previousMillis>=interval){
    readDatas();
    previousMillis=currentMillis;
  }

}

and here is the screenshot of my firebase for better understanding:

Arduino IDE连接esp8266到Firebase时出现错误

答案1

得分: 0

将我的 esp8266 版本降级到 2.7 即可解决。

英文:

fixed by downgrading my esp8266 version to 2.7

huangapple
  • 本文由 发表于 2023年6月27日 20:23:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定