[SOLVED] Noob need help with codes (Solar Weather Station)

Hello i need help with a Project:
If i verify the Project it comes with Compile Errors… what is here the problem
The Error´s:
BlynkProtocol.h:225: undefined reference to BME280::init()' sketch\Solar_Powered_Weather_Station.ino.cpp.o: In functionBlynkProtocol<BlynkArduinoClientGen >::begin(char const*)’:
BlynkProtocol.h:88: undefined reference to BME280::init()' sketch\Solar_Powered_Weather_Station.ino.cpp.o: In functionBlynkWifi::begin(char const*, char const*, char const*, char const*, unsigned short)’:
BlynkSimpleEsp8266.h:74: undefined reference to BME280::getTemperature()' BlynkSimpleEsp8266.h:74: undefined reference toBME280::getPressure()’
sketch\Solar_Powered_Weather_Station.ino.cpp.o: In function BlynkProtocol<BlynkArduinoClientGen<Client> >::connect(unsigned int)': BlynkProtocol.h:56: undefined reference toBME280::calcAltitude(float)’
sketch\Solar_Powered_Weather_Station.ino.cpp.o: In function setup': Solar_Powered_Weather_Station.ino:53: undefined reference toBME280::getHumidity()’
sketch\Solar_Powered_Weather_Station.ino.cpp.o:(.text.loop+0x60): undefined reference to BME280::getTemperature()' sketch\Solar_Powered_Weather_Station.ino.cpp.o:(.text.loop+0xa2): undefined reference toBME280::getPressure()’
sketch\Solar_Powered_Weather_Station.ino.cpp.o: In function loop': Solar_Powered_Weather_Station.ino:62: undefined reference toBME280::calcAltitude(float)’
Solar_Powered_Weather_Station.ino:69: undefined reference to `BME280::getHumidity()’
collect2.exe: error: ld returned 1 exit status

Here the Code from the .ino

//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "Seeed_BME280.h"
#include <Wire.h>


BME280 bme280;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "3df5f636c7dc464a457a32e382c4796xx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SSID";
char pass[] = "PASS WORD";
void setup()
{
  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
  if(!bme280.init()){
  Serial.println("Device error!");
  }
}

void loop()
{
  Blynk.run();
  
  //get and print temperatures
  float temp = bme280.getTemperature();
  Serial.print("Temp: ");
  Serial.print(temp);
  Serial.println("C");//The unit for  Celsius because original arduino don't support speical symbols
  Blynk.virtualWrite(0, temp); // virtual pin 0
  Blynk.virtualWrite(4, temp); // virtual pin 4
  
  
  //get and print atmospheric pressure data
  float pressure = bme280.getPressure(); // pressure in Pa
  float p = pressure/100.0 ; // pressure in hPa
  Serial.print("Pressure: ");
  Serial.print(p);
  Serial.println("hPa");
  Blynk.virtualWrite(1, p); // virtual pin 1

  
  //get and print altitude data
  float altitude = bme280.calcAltitude(pressure);
  Serial.print("Altitude: ");
  Serial.print(altitude);
  Serial.println("m");
  Blynk.virtualWrite(2, altitude); // virtual pin 2

  //get and print humidity data
  float humidity = bme280.getHumidity();
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println("%");
  Blynk.virtualWrite(3, humidity); // virtual pin 3
  ESP.deepSleep(5 * 60 * 1000000); // // deepSleep time is defined in microseconds. Multiply seconds by 1e6

This forum is not a code mechanic’s shop :wink: We all have our own code to troubleshoot for syntax issues.

However, assuming you posted the whole code, then your void loop() is missing a closing bracket.

The code seems to come from here:


although the original code from the Instructable does have the bracket at the end that’s missing here.

In the Instructable comments others seem to have similar issues with the code and there aren’t any follow-up to this.

Pete.

Feeling a bit board, so I tested the code… after I installed the Seeed_BME280.h library and closed the void loop() with the missing bracket, it compiled without error.

So nothing wrong with the code from a compiling standpoint. Of course I have absolutely none of the hardware, so that’s as far as I can test :wink:

@Icesoldier looks like you have something wrong/missing in your libraries and/or IDE setup.

3 Likes

@ Gunner - Thanks for the feedback… it was a problem with missing libraries… now it works
Thanks for the help :slight_smile: