Overview: LoRa Based Wireless Weather Station
In this project, we will learn how to make LoRa Based Wireless Weather Station using Arduino Pro Mini & ESP32 Wifi Module. You can keep the Weather Station Node on the roof of your house or any remote location just a few kilometers away from your home. You can use the sensor like BME280 Barometric Pressure Sensor along with a BH1750 Light sensor and also a Rain Sensor. Basically, this weather station can monitor the Environment parameters like Temperature, Humidity, Pressure, Altitude, Dew Point, Rainfall & Light Intensity.
Using the LoRa Module SX1278/RFM95 you can monitor the data from a few kilometer distances (up to 5Km). The device operates on a 3.7V lithium Ion Battery Battery and power consumption is low.
The Gateway can be placed indoors inside the house or can be placed at a certain height to achieve a long distance. The gateway is made using Lora SX1278/RFM95 and ESP32 Wifi Module. The receiver collects the data from the sender or Sensor Node and uploads it to the Server.
The received data can be observed in multiple ways. I will demonstrate how to show the data in 3 ways. The first method is to monitor the data on Webserver. Using the local IP of the ESP32 Board, you can monitor data on the Webpage. In the second method, you can upload the data to Thingspeak Server and monitor the logged data in a graphical format. In the third method, you can monitor the data online on the Blynk Application. You can choose any of the methods to monitor the weather data. Such a great wireless weather station, you can do it by yourself.
You can check some of our previous Weather Station Projects:
1. ESP8266 Live Weather Station on WebServer: Check Here
2. ESP32 BME280 Mini Weather Station: Check Here
3. IoT Based Weather Station using OpenWeatherMap: Check Here
4. MQTT Based Weather Station with GSM: Check Here
Bill of Materials
For Making LoRa Based Weather Station we need some microcotrollers board and few sensors. All the components that is needed for making this project is given below. You can purchase the components from Amazon.
S.N. | Components Name | Quantity | Purchase Links |
---|---|---|---|
1 | ESP32 Board | 1 | Amazon | AliExpress |
2 | Arduino Pro Mini 3.3V, 8MHz | 1 | Amazon | AliExpress |
3 | LoRa Module SX1278 | 2 | Amazon | AliExpress |
4 | BME280 Sensor | 1 | Amazon | AliExpress |
5 | BH1750 Light Sensor | 1 | Amazon | AliExpress |
6 | FC-37 Analog/Digital Rain Sensor | 1 | Amazon | AliExpress |
7 | 3.7V 1000mAh Lithium-Ion Battery | 1 | Amazon | AliExpress |
Sensors for Weather Station
BME280 Barometric Pressure Sensor
The BME280 is Barometric Pressure Sensor that can measure temperature, Humidity & Atmospheric Pressure. The Sensor has an I2C Bus and operates on 3.3V power Supply. The unit combines high linearity and high accuracy sensors and is perfectly feasible for low current consumption, long-term stability, and high EMC robustness.
The sensor is best for measuring humidity with ±3% accuracy, barometric pressure with ±1 hPa absolute accuracy, and temperature with ±1.0°C accuracy. Because pressure changes with altitude and the pressure measurements are so good, you can also use it as an altimeter with ±1 meter or better accuracy!.
Rain Sensor
Rain sensors are used in the detection of water beyond what a humidity sensor can detect.
The rain sensor detects water that completes the circuits on its sensor boards’ printed leads. The sensor board acts as a variable resistor that will change from 100k ohms when wet to 2M ohms when dry. In short, the wetter the board the more current that will be conducted.
BH1750 Ambient Light Sensor
The BH1750 light intensity sensor is a digital Ambient Light Sensor with an I2C bus interface. This sensor is best suited to get the ambient light data. This sensor can accurately measure the LUX value of light up to 65535. It consumes a very low amount of current & uses a photodiode to sense the light.
The Sensor works on 3.3V & using its I2C Pins you easily interface it with any microcontroller. To learn more about this sensor you can check this post: Light Meter using BH1750 & Arduino
Apart from all these sensors, you can also add Anemometer Sensor to this project. The Anemometer measures the wind speed and tells you the condition about the air moving speed.
LoRa Weather Station Node & Gateway Circuit
The Wireless Weather Station requires Sender and Receiver circuit to communicate wirelessly. So the Sender Circuit is called as Sensor Node and the Receiver Circuit is called as Gateway.
Sensor Node Circuit
We need to select a low power Arduino Board. So, Arduino Pro Mini is the best board that works on 3.3V & runs on 8 MHz Clock Frequency. We can use the LoRa Module SX1278 from Ai-Thinker. The BH1750 & BME280 Sensor works on I2C Protocol. The LoRa Module SX1278 works on SPI Protocol. The device is powered by 3.7V Lithium-Ion Battery & is connected to the RAW pin of Pro Mini.
The Rain Sensor, BH1750 Ambient Light Sensor, BME280 Barometric Sensor & LoRa Module is connected to the 3.3V of Arduino Pro Mini. You can use an additional TP4056 Battery charging Module to charge the Battery. Apart from this adding a Solar Panel and harvesting Solar energy to the Circuit would be the best option.
The circuit is assembled on a breadboard but you can design a custom PCB for this project. Alright, all the sensors can be placed in a small waterproof box except the rain sensor that needs to be placed outside to monitor the rainfall. The Sensor Node operates on very small power and putting the device to sleep mode will increase battery life. Also removing the unnecessary voltage regulator and using low power LDO or buck converter IC can lower down the power further.
The LoRa Module operates on frequency 433Mhz, but you can select the 868MHz or 915MHz frequency according to your region. You can use any other Lora module with a different antenna as per the availability in your region. Remember the LoRa Based Weather Station is not a waterproof device, so place it inside the waterproof casing.
Wifi Gateway Circuit
On the Gateway side, we only have LoRa Module SX1278 & ESP32 Wifi Module. The LoRa is connected via SPI Pins to ESP32 Board. And this unit is powered through USB Cable.
The Gateway unit can be placed inside the room or outside but near to the WiFi Network. The ESP32 Wifi module connects to the local wifi network. And the LoRa receives the data from the sensor node. Using the esp32 wifi module the data is uploaded to the server.
Library Installation on Arduino IDE
Before moving to the programming part, you need to install Libraries to the Arduino IDE. The following are the list of Libraries that is used in the code below.
1. LoRa Library
The LoRa library is used for sending and receiving data using LoRa radios. This library exposes the LoRa radio directly and allows you to send data to any radios in range with the same radio parameters. All data is broadcasted and there is no addressing.
2. BME280 Library
The Adafruit BME280 Library from the Adafruit makes an I2C Interface with Arduino or any other microcontroller and reads the temperature, humidity and Pressure Value from the Sensor.
3. BH1750 Library
This package contains an Arduino library for digital light sensor breakout boards containing the BH1750FVI IC. Configuring the I2C bus must be done in user code helps to communicate between Arduino & the sensor.
4. Blynk Library
Blynk is the most popular Internet of Things platform for connecting any hardware to the cloud, designing apps to control them, and managing your deployed products at scale. With Blynk Library you can connect over 400 hardware models including ESP8266, ESP32, NodeMCU & Arduino to the Blynk Cloud.
Source Code/Program for Sensor Node
The program or code for the LoRa Weather Station Sensor Node is given below. You can copy the code and upload it to the Arduino Pro Mini Board. In case if you are using the multiple sensor nodes make sure to change the device ID from the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#include <Wire.h> #include <SPI.h> #include <LoRa.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> #include <BH1750.h> // adds BH1750 library file //#define SS 10 //#define RST 9 //#define DI0 2 //#define TX_P 17 //#define ENCRYPT 0x78 #define BAND 433E6 #define rain_sensor A0 #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; BH1750 lightMeter; String LoRaMessage = ""; char device_id[12] = "MyDevice123"; void setup() { Serial.begin(115200); Wire.begin(); lightMeter.begin(); pinMode (rain_sensor, INPUT); while (!Serial); Serial.println(F("LoRa Sender")); //LoRa.setPins(SS, RST, DI0); //LoRa.setTxPower(TX_P); //LoRa.setSyncWord(ENCRYPT); if (!LoRa.begin(BAND)) { Serial.println(F("Starting LoRa failed!")); while (1); } if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } } void loop() { float temperature = bme.readTemperature(); float pressure = bme.readPressure() / 100.0F; float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA); float humidity = bme.readHumidity(); double dewPoint = dewPointFast(temperature, humidity); int rainfall = map(analogRead(rain_sensor), 780, 0, 0, 100); if (rainfall >= 100) { rainfall = 100; } if (rainfall <= 0) { rainfall = 0; } float lux = lightMeter.readLightLevel(); Serial.print(F("Device ID: ")); Serial.println(device_id); Serial.print(F("Temperature = ")); Serial.print(temperature); Serial.println(F("*C")); Serial.print(F("Pressure = ")); Serial.print(pressure); Serial.println(F("hPa")); Serial.print(F("Approx. Altitude = ")); Serial.print(altitude); Serial.println(F("m")); Serial.print(F("Humidity = ")); Serial.print(humidity); Serial.println(F("%")); Serial.print(F("Dew point = ")); Serial.print(dewPoint); Serial.println(F(" *C")); Serial.print(F("Rainfall = ")); Serial.print(rainfall); Serial.println(F("%")); Serial.print(F("Light = ")); Serial.print(lux); Serial.println(F(" lx")); Serial.println(); LoRaMessage = String(device_id) + "/" + String(temperature) + "&" + String(pressure) + "#" + String(altitude) + "@" + String(humidity) + "$" + String(dewPoint) + "^" + String(rainfall) + "!" + String(lux); // send packet LoRa.beginPacket(); LoRa.print(LoRaMessage); LoRa.endPacket(); delay(10000); } double dewPointFast(double celsius, double humidity) { double a = 17.271; double b = 237.7; double temp = (a * celsius) / (b + celsius) + log(humidity * 0.01); double Td = (b * temp) / (a - temp); return Td; } |
Source Code/Program for Gateway: WebServer
Here is a Gateway Code for ESP32 Board. Using this code you can view the weather station data on Web Browser. The ESP32 Webserver creates a webpage where all the data related to Weather Station is logged on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
#include <SPI.h> #include <LoRa.h> #include <WiFi.h> #include <WebServer.h> #define SS 5 #define RST 14 #define DI0 2 //#define TX_P 17 #define BAND 433E6 //#define ENCRYPT 0x78 String device_id; String temperature; String pressure; String altitude; String humidity; String dewPoint; String rainfall; String lux; const char* ssid = "Bynark_Airtel"; const char* password = "bynark@123"; WebServer server(80); void setup() { Serial.begin(115200); Serial.println("LoRa Receiver"); //LoRa.setTxPower(TX_P); //LoRa.setSyncWord(ENCRYPT); LoRa.setPins(SS, RST, DI0); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("Connecting to "); Serial.println(ssid); //Connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handle_OnConnect); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { // try to parse packet int pos1, pos2, pos3, pos4, pos5, pos6, pos7; int packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("Received packet: "); String LoRaData = LoRa.readString(); Serial.print(LoRaData); // read packet while (LoRa.available()) { Serial.print((char)LoRa.read()); } // print RSSI of packet Serial.print("' with RSSI "); Serial.println(LoRa.packetRssi()); pos1 = LoRaData.indexOf('/'); pos2 = LoRaData.indexOf('&'); pos3 = LoRaData.indexOf('#'); pos4 = LoRaData.indexOf('@'); pos5 = LoRaData.indexOf('$'); pos6 = LoRaData.indexOf('^'); pos7 = LoRaData.indexOf('!'); device_id = LoRaData.substring(0, pos1); temperature = LoRaData.substring(pos1 + 1, pos2); pressure = LoRaData.substring(pos2 + 1, pos3); altitude = LoRaData.substring(pos3 + 1, pos4); humidity = LoRaData.substring(pos4 + 1, pos5); dewPoint = LoRaData.substring(pos5 + 1, pos6); rainfall = LoRaData.substring(pos6 + 1, pos7); lux = LoRaData.substring(pos7 + 1, LoRaData.length()); Serial.print(F("Device ID = ")); Serial.println(device_id); Serial.print(F("Temperature = ")); Serial.print(temperature); Serial.println(F("*C")); Serial.print(F("Pressure = ")); Serial.print(pressure); Serial.println(F("hPa")); Serial.print(F("Approx. Altitude = ")); Serial.print(altitude); Serial.println(F("m")); Serial.print(F("Humidity = ")); Serial.print(humidity); Serial.println(F("%")); Serial.print("Dew point = "); Serial.print(dewPoint); Serial.println(" *C"); Serial.print(F("Rainfall = ")); Serial.print(rainfall); Serial.println(F("%")); Serial.print(F("Light = ")); Serial.print(lux); Serial.println(F(" lx")); Serial.println(); server.handleClient(); } } void handle_OnConnect() { server.send(200, "text/html", SendHTML(temperature.toFloat(), humidity.toFloat(), pressure.toFloat(), altitude.toFloat(), dewPoint.toFloat(), rainfall.toFloat(), lux.toFloat())); } void handle_NotFound() { server.send(404, "text/plain", "Not found"); } String SendHTML(float temperature, float humidity, float pressure, float altitude, float dewPoint, float rainfall, float lux) { String ptr = "<!DOCTYPE html> <html>\n"; ptr += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n"; ptr += "<title>Wireless Weather Station</title>\n"; ptr += "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n"; ptr += "body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n"; ptr += "p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n"; ptr += "</style>\n"; ptr += "</head>\n"; ptr += "<body>\n"; ptr += "<div id=\"webpage\">\n"; ptr += "<h1>Wireless Weather Station</h1>\n"; ptr += "<p>Temperature: "; ptr += temperature; ptr += "°C</p>"; ptr += "<p>Humidity: "; ptr += humidity; ptr += "%</p>"; ptr += "<p>Pressure: "; ptr += pressure; ptr += "hPa</p>"; ptr += "<p>Altitude: "; ptr += altitude; ptr += "m</p>"; ptr += "<p>Dew Point: "; ptr += dewPoint; ptr += "°C</p>"; ptr += "<p>Rainfall: "; ptr += rainfall; ptr += "%</p>"; ptr += "<p>Light: "; ptr += lux; ptr += "lx</p>"; ptr += "</div>\n"; ptr += "</body>\n"; ptr += "</html>\n"; return ptr; } |
Now you can upload the code to the Arduino Pro Mini & ESP32 Board. Once the code is uploaded, open the serial monitor for both the transmitter and then a receiver part. If every connection is correct the sender will initialize and starts sending the data. On the receiver side, the receiver will connect to the network and will print the IP Address.
Copy the IP address and paste it on the Web Browser. You can paste and hit enter in the Chrome Browser of your Computer or simply on the Smartphone.
The weather station data will be simply displayed in a web browser. You can reload the page to refresh the weather data. Or simply using the AJAX function in code you can refresh the data without reloading the page.
Source Code/Program for Gateway: Thingspeak Server
Now let’s monitor the LoRa Weather Station data on Thingspeak Server. For that create an account on Thingspeak Server or simply log in if you have created the account earlier. Then create a new channel with the following details like temperature, humidity, pressure, altitude, dew point, rainfall, and light intensity.
Then go to the API Key and copy the write API Key. In the below Code change the API Key, WiFi SSID & Password.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#include <SPI.h> #include <LoRa.h> #include <WiFi.h> String apiKey = "************"; // Enter your Write API key from ThingSpeak const char* ssid = "************"; const char* password = "************"; const char* server = "api.thingspeak.com"; #define SS 5 #define RST 14 #define DI0 2 //#define TX_P 17 #define BAND 433E6 //#define ENCRYPT 0x78 String device_id; String temperature; String pressure; String altitude; String humidity; String dewPoint; String rainfall; String lux; WiFiClient client; void setup() { Serial.begin(115200); Serial.println("LoRa Receiver"); //LoRa.setTxPower(TX_P); //LoRa.setSyncWord(ENCRYPT); LoRa.setPins(SS, RST, DI0); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); } void loop() { // try to parse packet int pos1, pos2, pos3, pos4, pos5, pos6, pos7; int packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("Received packet: "); String LoRaData = LoRa.readString(); Serial.print(LoRaData); // read packet while (LoRa.available()) { Serial.print((char)LoRa.read()); } // print RSSI of packet Serial.print("' with RSSI "); Serial.println(LoRa.packetRssi()); pos1 = LoRaData.indexOf('/'); pos2 = LoRaData.indexOf('&'); pos3 = LoRaData.indexOf('#'); pos4 = LoRaData.indexOf('@'); pos5 = LoRaData.indexOf('$'); pos6 = LoRaData.indexOf('^'); pos7 = LoRaData.indexOf('!'); device_id = LoRaData.substring(0, pos1); temperature = LoRaData.substring(pos1 + 1, pos2); pressure = LoRaData.substring(pos2 + 1, pos3); altitude = LoRaData.substring(pos3 + 1, pos4); humidity = LoRaData.substring(pos4 + 1, pos5); dewPoint = LoRaData.substring(pos5 + 1, pos6); rainfall = LoRaData.substring(pos6 + 1, pos7); lux = LoRaData.substring(pos7 + 1, LoRaData.length()); Serial.print(F("Device ID = ")); Serial.println(device_id); Serial.print(F("Temperature = ")); Serial.print(temperature); Serial.println(F("*C")); Serial.print(F("Pressure = ")); Serial.print(pressure); Serial.println(F("hPa")); Serial.print(F("Approx. Altitude = ")); Serial.print(altitude); Serial.println(F("m")); Serial.print(F("Humidity = ")); Serial.print(humidity); Serial.println(F("%")); Serial.print("Dew point = "); Serial.print(dewPoint); Serial.println(" *C"); Serial.print(F("Rainfall = ")); Serial.print(rainfall); Serial.println(F("%")); Serial.print(F("Light = ")); Serial.print(lux); Serial.println(F(" lx")); Serial.println(); if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com { String postStr = apiKey; postStr += "&field1="; postStr += String(temperature); postStr += "&field2="; postStr += String(pressure); postStr += "&field3="; postStr += String(altitude); postStr += "&field4="; postStr += String(humidity); postStr += "&field5="; postStr += String(dewPoint); postStr += "&field6="; postStr += String(rainfall); postStr += "&field7="; postStr += String(lux); postStr += "r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr); Serial.println("Data Send to Thingspeak"); delay(500); } client.stop(); Serial.println("Waiting..."); } } |
Now again open the Serial Monitor. So if you see the data is sent and received means your node and gateway both are working fine.
Now go to the Thingspeak Private view. Here you will see the data logged in the graphical format. The data is received after an interval of 15 seconds.
Source Code/Program for Gateway: Blynk Application
Here is a Blynk Code for monitoring Wireless Weather Station data is Blynk Application. The data from the ESP32 LoRa Gateway will be logged to Blynk Cloud Server.
In the following code change the Blynk Authentication Token that is generated by your Blynk Application. Also change the WiFi SSID & Password.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
#define BLYNK_PRINT Serial #include <SPI.h> #include <LoRa.h> #include <WiFi.h> #include <Blynk.h> #include <BlynkSimpleEsp32.h> char auth[] = "**********************"; // You should get Auth Token in the Blynk App. char ssid[] = "************"; // Your WiFi credentials. char pass[] = "************"; #define SS 5 #define RST 14 #define DI0 2 //#define TX_P 17 #define BAND 433E6 //#define ENCRYPT 0x78 String device_id; String temperature; String pressure; String altitude; String humidity; String dewPoint; String rainfall; String lux; void setup() { Serial.begin(115200); Blynk.begin(auth, ssid, pass); Serial.println("LoRa Receiver"); //LoRa.setTxPower(TX_P); //LoRa.setSyncWord(ENCRYPT); LoRa.setPins(SS, RST, DI0); if (!LoRa.begin(BAND)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("Connecting to "); Serial.println(ssid); //connect to your local wi-fi network WiFi.begin(ssid, pass); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); } void loop() { // try to parse packet int pos1, pos2, pos3, pos4, pos5, pos6, pos7; int packetSize = LoRa.parsePacket(); if (packetSize) { Blynk.run(); // received a packet Serial.print("Received packet: "); String LoRaData = LoRa.readString(); Serial.print(LoRaData); // read packet while (LoRa.available()) { Serial.print((char)LoRa.read()); } // print RSSI of packet Serial.print("' with RSSI "); Serial.println(LoRa.packetRssi()); pos1 = LoRaData.indexOf('/'); pos2 = LoRaData.indexOf('&'); pos3 = LoRaData.indexOf('#'); pos4 = LoRaData.indexOf('@'); pos5 = LoRaData.indexOf('$'); pos6 = LoRaData.indexOf('^'); pos7 = LoRaData.indexOf('!'); device_id = LoRaData.substring(0, pos1); temperature = LoRaData.substring(pos1 + 1, pos2); pressure = LoRaData.substring(pos2 + 1, pos3); altitude = LoRaData.substring(pos3 + 1, pos4); humidity = LoRaData.substring(pos4 + 1, pos5); dewPoint = LoRaData.substring(pos5 + 1, pos6); rainfall = LoRaData.substring(pos6 + 1, pos7); lux = LoRaData.substring(pos7 + 1, LoRaData.length()); Serial.print(F("Device ID = ")); Serial.println(device_id); Serial.print(F("Temperature = ")); Serial.print(temperature); Serial.println(F("*C")); Serial.print(F("Pressure = ")); Serial.print(pressure); Serial.println(F("hPa")); Serial.print(F("Approx. Altitude = ")); Serial.print(altitude); Serial.println(F("m")); Serial.print(F("Humidity = ")); Serial.print(humidity); Serial.println(F("%")); Serial.print("Dew point = "); Serial.print(dewPoint); Serial.println(" *C"); Serial.print(F("Rainfall = ")); Serial.print(rainfall); Serial.println(F("%")); Serial.print(F("Light = ")); Serial.print(lux); Serial.println(F(" lx")); Serial.println(); Blynk.virtualWrite(V1, temperature); Blynk.virtualWrite(V2, humidity); Blynk.virtualWrite(V3, pressure); Blynk.virtualWrite(V4, altitude); Blynk.virtualWrite(V5, dewPoint); Blynk.virtualWrite(V6, rainfall); Blynk.virtualWrite(V7, lux); } } |
So when the code is uploaded, the ESP32 will connect to the Blynk server. Now you can check the Blynk Application on your mobile phone. The mobile phone will receive the Wireless LoRa Weather Station data.
Video Tutorial & Guide: Wireless LoRa Weather Station
You can also send the data to the server using the MQTT protocol, which is a lightweight protocol. You can check one of the such examples here: BME680 MQTT Weather Station.
15 Comments
Hi, Is the “TP4050 Battery Charging Module” a typo error. Is it not the TP4056 ?
Thanks for the correction. Its TP4056.
can i ask for pcb / dps
i am having error with WebServer.h as i cannot find the library can you please provide me the link to library so i can integrate it
Excellent work! Thank you!
Thanks for interesting tutorial but is there not some code required to put the Arduino into a deep sleep to conserve the battery?
The code about Source Code/Program for Gateway: WebServer get followed error on line 59 and 60 : expected unqualified-id before ‘.’ token . And the in the line 136 Coud you help me ? .
The code about Source Code/Program for Gateway: WebServer get followed error on line 58-59 and 135 -141-147 : expected unqualified-id before ‘.’ token . And the in the line 136 Coud you help me ? .
Hello
Thank you for this example , very interesting but very very unstable. after a very long month of testing and many modifications, I think I have finally found the source of the problem. The ESP wifi modem is near the antenna LoRA and interferes with reception. I tried the espwifistop commands but had problems waking up. In the end I connect to the wifi after having received my data LORA and I close right after i send to Thingspeak. the result is not bad
Thanks for testing and clear explanation. I tried finding the problem and fixing the issues for many months and never realized why esp32 hangs and stops working. Now you have provided solution. Thanks a lot.
Is it possible to add wind speed/direction to this? If so what hardware would I need?
You need an anemometer to measure wind speed. We have some tutorial posted about Anemometer.
Hi, this this is a really cool project, i saw u say: “In case if you are using the multiple sensor nodes make sure to change the device ID from the code”, but how can i manage multiple nodes and get the data from it into thinkspeak server?
Lovely, this has helped my programming works
Can you please let me know where the PCB gerber of this project is?