Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2022sric:weatherly-local-station [2023/06/01 18:56]
andreea.miu [Schematics]
iothings:proiecte:2022sric:weatherly-local-station [2023/06/01 21:45] (current)
andreea.miu [Introduction]
Line 1: Line 1:
-===== Local weather station with BME280 =====+===== Local weather station with BME280 ​& Android integration ​=====
   * Student: Andreea Miu   * Student: Andreea Miu
   * Master: SAS   * Master: SAS
Line 8: Line 8:
 The purpose of this project is to provide a proof-of-concept for adding local weather stations to standard weather applications,​ in order to have a more granular approach on weather based on customizable location and measured data. The purpose of this project is to provide a proof-of-concept for adding local weather stations to standard weather applications,​ in order to have a more granular approach on weather based on customizable location and measured data.
  
 +I have also uploaded this project on [[https://​github.com/​miuAndreea/​Weatherly|Github]],​ for easier access to the full code and to provide the possibility of testing and reproducing the application.
 +
 +===== Project demo =====
 +
 +A demo video of the application running can be found at the following [[https://​drive.google.com/​file/​d/​1CsQ8dCcg7jKgNMY-_ueiRhcQsAjqJyS8/​view|link]].
 ===== Hardware Setup ===== ===== Hardware Setup =====
  
Line 24: Line 29:
   * SDI/SDA of BME280 - IO21 / GPIO pin 21 of ESP32 (default GPIO ppin for I2C SDA)   * SDI/SDA of BME280 - IO21 / GPIO pin 21 of ESP32 (default GPIO ppin for I2C SDA)
  
 +==== Physical setup ====
 +The physical setup is easily reproducible. This allows for scalability if creating multiple local weather stations is desired. The BME280 sensor used comes with female-to-male jumper wires that form a connection port suitable for the sensor. The female end of each wire can be connected to the ESP32 board pins, according to the schematics described above.
 +
 +{{weatherly-fizic.jpeg?​500 |}}
  
 ===== Software Setup ===== ===== Software Setup =====
Line 29: Line 38:
  
 ==== Arduino code ==== ==== Arduino code ====
 +The Arduino code consists of a few key elements used, from both a Firebase connection perspective,​ and a BME280 sensor perspective. The full code can be found on [[https://​github.com/​miuAndreea/​Weatherly/​|this]] Github repository.
 +
 +In order to measure altitude correctly, BME280 needs a reference pressure for sea level:
 +<​code>​
 +#define SEALEVELPRESSURE_HPA (1013.25)
 +</​code>​
 +
 +BME280 can transmit data using either I2C or SPI. For this project, I2C was used. By default, the sensor uses I2C, but if the user would like to use SPI, this is possible by editing the if structure and calling //bme// using the SPI pins as parameters.
 +
 +<​code>​
 +#define USEIIC 1
 +
 +#if(USEIIC)
 +  Adafruit_BME280 bme;
 +#else
 +  // define SPI pins
 +#endif
 +</​code>​
 +
 +In order to use Firebase and connect to WiFi for data transmission,​ multiple defines are used.
 +
 +In the setup function, the BME280 sensor is initialized and the network connection is established.
 +
 +<​code>​
 +void setup(){
 +    Serial.begin(115200);​
 +
 +    // Init the BME280 sensor
 +    bool rslt;
 +    rslt = bme.begin();  ​
 +    if (!rslt) {
 +      Serial.println("​Could not initialize sensor, make sure it is properly connected!"​);​
 +      while(1);
 +    }
 +    Serial.println("​BME280 successfully initialized"​);​
 +    ​
 +    .......
 +
 +    // Start connecting to WiFi network
 +    WiFi.begin(WIFI_SSID,​ WIFI_PASSWORD);​
 +    Serial.print("​Connecting to Wi-Fi"​);​
 +    while (WiFi.status() != WL_CONNECTED){
 +      Serial.print("​."​);​
 +      delay(300);
 +    }
 +    Serial.println();​
 +    Serial.print("​Connected with IP: ");
 +    Serial.println(WiFi.localIP());​
 +    Serial.println();​
 +    ​
 +    /* Assign the api key (required) */
 +    config.api_key = API_KEY;
 +    ​
 +    /* Assign the RTDB URL (required) */
 +    config.database_url = DATABASE_URL;​
 +    ​
 +    /* Sign up */
 +    if (Firebase.signUp(&​config,​ &auth, "",​ ""​)){
 +      Serial.println("​ok"​);​
 +      signupOK = true;
 +    }
 +    ​
 +    .......
 +  }
 +</​code>​
 +
 +In the //loop()// function, I call the //​sendValues()//​ function, which sends values for temperature,​ humidity, pressure and altitude respectively. For example, temperature can be fetched and sent to the Firebase database in the following way:
 +
 +<​code>​
 +if (Firebase.RTDB.setFloat(&​fbdo,​ "​temperature",​ bme.readTemperature())){
 +      Serial.println("​PASSED"​);​
 +      Serial.println("​PATH:​ " + fbdo.dataPath());​
 +      Serial.println("​TYPE:​ " + fbdo.dataType());​
 +    }
 +    else {
 +      Serial.println("​FAILED"​);​
 +      Serial.println("​REASON:​ " + fbdo.errorReason());​
 +    }
 +</​code>​
 +
 +
 +
  
 ==== Firebase ==== ==== Firebase ====
 +The Firebase database is a real-time database, which stores the values captured by the sensor in respective nodes: temperature,​ humidity, pressure and altitude respectively.
 +The below picture gives a look into the database from an admin perspective:​
  
 +{{weatherly-firebase.png?​500}}
 ==== Android application ==== ==== Android application ====
 The Android application used is part of a larger project, which also provides access to global weather forecast using an API. By using the data collected by the BME280 sensor and stored in the Firebase database, the granularity of data (across a city, for example) is increased. The screenshots below illustrate how the app can be navigated in order to access the local weather station in Bucharest. A different forecast can also be retrieved for Bucharest using the API, thus providing two points of data collection in Bucharest. The Android application used is part of a larger project, which also provides access to global weather forecast using an API. By using the data collected by the BME280 sensor and stored in the Firebase database, the granularity of data (across a city, for example) is increased. The screenshots below illustrate how the app can be navigated in order to access the local weather station in Bucharest. A different forecast can also be retrieved for Bucharest using the API, thus providing two points of data collection in Bucharest.
  
 +For developing the application,​ I used Android Studio, and Java as the programming language.
 +
 +After configuring the connection to Firebase using Android Studio'​s Firebase plugin, the nodes and values of the nodes can be retrieved in real-time using a //​ValueEventListener//​. For example, getting the temperature value and showing it in a //​TextView//​ can be done in the below manner:
 +
 +<​code>​
 +databaseReference = FirebaseDatabase.getInstance().getReference();​
 +
 +// Event listener
 +databaseReference.addValueEventListener(
 +    new ValueEventListener() {
 +    @Override
 +    public void onDataChange(@NonNull DataSnapshot snapshot) {
 +        temp_val =
 +            snapshot.child("​temperature"​).getValue(Float.class);​
 +        temperatureTxt.setText(temp_val.toString() + "​°C"​);​
 +    }
 +</​code>​
 +
 +The full application can be viewed using [[https://​github.com/​miuAndreea/​Weatherly/​|this link]]. Below are some screenshots that illustrate how to navigate the app for viewing information from the local weather station.
  
 {{ weatherly-app-1.png?​500 |}} {{ weatherly-app-1.png?​500 |}}
Line 42: Line 155:
 ===== References =====  ​ ===== References =====  ​
   * https://​easyeda.com/​editor   * https://​easyeda.com/​editor
 +  * https://​github.com/​miuAndreea/​Weatherly/​
 +  * https://​www.waveshare.com/​bme280-environmental-sensor.htm
 +  * https://​ocw.cs.pub.ro/​courses/​iothings/​laboratoare/​2022/​lab4
 +  * https://​ocw.cs.pub.ro/​courses/​smd
 +  * https://​firebase.google.com/​docs/​database/​android/​read-and-write
  
  
iothings/proiecte/2022sric/weatherly-local-station.1685635001.txt.gz · Last modified: 2023/06/01 18:56 by andreea.miu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0