Introduction: DIY Smart Agriculture Monitoring System With LoRaWAN

About: Elecrow is an open hardware facilitation company based in Shenzhen. To make your making and innovation easier, we offer various development platforms, modules, tools, electronics components, and other open-sou…

With population growth and urbanization accelerating, global agricultural production is facing enormous challenges. In this case, the application of smart agricultural technology is becoming more and more important. Smart agricultural technology can help farmers better manage agricultural production, improve agricultural production efficiency and quality, reduce waste and costs, while protecting the environment and sustainable development. Among them, IoT technology plays an important role in smart agriculture.

This project aims to use the LoRaWAN gateway to access the TTN platform to realize the application of smart agriculture, and improve the efficiency and quality of agricultural production by remotely monitoring the soil humidity, air temperature and light conditions of the farm.

Supplies

In order to complete this project, we mainly need some lora modules and node equipment, which can be purchased at www.elecrow.com.

hardware preparation

software:

  • The software of the LoRaWAN node device can be written using the Arduino IDE
  • TTN gateway node configuration

Lora Basic Gateway Module is a single-channel Lora gateway module combined with ESP32 WROOM 32UE and RA-01H module, powered by TYPE C USB interface, onboard LAN8720A-10/100Mbps RMII interface Ethernet chip, in addition to being able to network through ESP32 WIFI, Wired networking can also be carried out through the RJ45 network interface. The WIFI and LORA antenna interface adopts the onboard SMA interface antenna, which supports long-distance LORA communication. The onboard 1.8-inch touch screen can display gateway networking information, IP address, etc., Gateway Module It can be combined with LORA node modules and LORA development boards to form LORA WAN Internet of Things, which can be applied to smart home, industrial, agricultural control and other fields.

Step 1: Build the Development Environment of Lora Basic Gateway Module

1. Please go to the official website https://www.arduino.cc/ to download the Arduino IDE development tool and download the corresponding library file, install the tool, click: open the tool as shown in the figure(Picture 1)

2. Click the "File" menu and select "Preferences" from the drop-down menu, as shown in the figure(Picture 2)

3. Add the URLs link of the ESP32 Arduino IDE development board as follows:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json(Picture 3)

4. Select Tools->Board->Boards Manager(Picture 4)

5. After entering the Boards Manager interface, enter "ESP32", select "ESP32" and install the development environment (my computer has already installed it, so it shows that it needs to be updated)(Picture 5)

6. After the environment is successfully installed, "ESP32 Arduino" appears in the Arduino IDE development board management; it means that the environment is successfully built, and the Lora Basic Gateway Module can be programmed in the Arduino IDE! (Picture 6)

Step 2: Burn Gateway Configuration Program

1.Burn the gateway configuration program for Lora Basic Gateway Module through Arduino IDE

1.1. First copy the library files in "libraries" in the "Code" folder to the Arduino IDE library management folder, as shown in the following figure:(Picture 1)

1.2. Open the "ESP-sc-gway-0424.ino" file in the Code folder(Picture 2)

1.3 Burn the "ESP-sc-gway-0424.ino" sample program to the Lora Basic Gateway Module

Select the development board model and COM port(Picture 3)

Click to start the burning program, and wait for the program burning to complete!

After the burning is completed, press the RESET reset button to reset again!(Picture4)

After reset, the LCD screen on the back of the gateway module will display the gateway configuration information,(Picture 5)

Step 3: 2. Lora Basic Gateway Module Networking Configuration

1. Use the mobile phone or notebook wifi to connect to the WiFi "ELECROW-GW1C" of the gateway module, password: "12345678"(Picture 1)

2. Enter 192.168.4.1 on the browser to enter the webpage; configure the gateway networking mode WIFI (the correct wifi account password must be entered) or NET (that is, use the RJ45 network cable to directly connect to the router, and NET does not need to enter WIFI information); press Gateway Default Get the gateway default ID, or enter the 16-digit ID yourself; enter the server address port; REGION set the gateway working frequency band (EU868 and US915); set the gateway channel (CHANNEL) and spreading factor (SF); (Picture 2\Picture 3)

  1. NET MODE: WIFI/NET optional
  2. WIFI SSID: Fill in the name of the WiFi to be connected (in NET mode, you don’t need to fill in any information)
  3. WIFI PASS: Fill in the password of the WiFi to be connected (in NET mode, you don’t need to fill in any information)
  4. Gateway ID: Press Gateway Default to get the default gateway ID, or enter the 16-digit ID by yourself
  5. SERVER ADDR: eu1.cloud.thethings.network
  6. SERVER PORT: default 1700
  7. REGION: EU868/US915 can be selected for gateway working frequency setting
  8. CHANNEL: default 0
  9. SF: Default 7 (default 7 for EU868MHZ frequency band, 10 for US915 frequency band)

3. After confirming that it is correct, click Submit to submit the configuration information, and the gateway will load the corresponding configuration. After completion(Picture 4)

Step 4: TTN (thethings.network) Server Creates a Gateway

① Enter on the browser: eu1.cloud.thethings.network/oauth/login, enter the following network interface, click "Login with the things ID"(Picture 1)

② Click "Switch account" to create an account and log in by yourself (you only need an email account to register, follow the prompts to complete the registration, and I won't repeat it here)(Picture 2)

③ After logging in to the account, enter the interface as shown in the figure below: Click Go to the Console(Picture 3)

④ Create a gateway in the background of the TTN server, click Gateway->Register Gateway

Enter the following interface, enter the 16-digit ID in Gateway Eui: 0000000000009151 (you can set the ID by yourself, if you encounter creation failure, it may be that the entered ID has been registered, please modify the ID address)(Picture 4)

Special attention: Select the frequency band "Europe 863-870MHz (SF12 for RX2)" (select this for LoRa nodes using the 868MHZ frequency band) or "United States 902-928MHz FSB1" (select this for LoRa nodes testing the 915MHZ frequency band)

After setting the gateway information, click "Register Gateway" to register the gateway!

Just set up according to the picture above, and register the gateway! (Must make sure the gateway ID is consistent, otherwise the connection will fail)

Click Gateway to refresh and you can see that the gateway has connected to the TTN server background. After the gateway is built, power on and reset the gateway module, log in to the TTN server again, and you can see that the gateway has connected to the TTN server (may need to repeat the operation several times)(Picture 5)

⑤ Add the node application of Lora RA-08H Node Board (915MHZ) in the TTN server

Click Applications->Create Applications (Picture 5)

Enter the Applications ID and Applications name in the pop-up interface, and click "Create Applications" after the input is complete(Picture 6)

Click Register end device to register the node(Picture 7)

Enter the following interface, and set as shown below (Frequency plan is optional):(Picture 8/Picture 9)

If you are using an 868MHz gateway, please select "Europe 863-870MHz (SF12 for RX2)"

If you are using a 915MHz gateway, please select "United States 902-928MHz FSB1"

⑥ Configure the DevEui, AppEui, and AppKey information of the RA-08H node module, as shown in the figure below(Pocture 10)

Click Register end device to register the device. After successful registration, enter the following interface:(Picture 11)

Step 5: Receive Node Monitoring Information

1. First burn the serial port application program for the Lora RA-08H Node Board (915MHZ) node module.In the Code folder, use the Arduino IDE to open the "Lora_RA_08H_Node.ino" program.(Picture 1)

Node access single channel gateway configuration steps (send AT commands)

  • 1. Set the node network access mode to OTAA: AT+CJOINMODE=0
  • 2. Set the node group frequency mask: AT+CFREQBANDMASK=0001 (set 0-7 channels)
  • 3. Set the node type: AT+CLASS=0 (Type A node)
  • 4. Set the node DevEui: AT+CDEVEUI=70B3D57ED005B7FF (the red part corresponds to the TTN server)
  • 5. Set the node AppEui: AT+CAPPEUI=0000000000000003 (the red part corresponds to the TTN server)
  • 6. Set node AppKey: AT+CAPPKEY=A8D7E5959F7746D902BF52BA2F899E3E (the red part corresponds to the TTN server)
  • 7. Set the node to turn off the adaptive spreading factor: AT+CADR=0
  • 8. Set the port for the node to receive TTN uplink data: AT+CAPPPORT=2 (the red part corresponds to the TTN server)
  • 9. Set the node communication rate: AT+CDATARATE=0 (0 - 5 corresponds to SF12-SF7)
  • 10. Set the uplink and downlink frequency of the node: AT+CULDLMODE= 2 (1 same frequency and 2 different frequencies)
  • 11. Set the node receiving window parameters: AT+CRXP=1,1,868100000 (receiving channel frequency is 868.1Mhz, corresponding to the channel frequency of the gateway)
  • 12. Set the node to join the network: AT+CJOIN=1,0,8,16 (+CJOIN: OK appears successfully)
  • 13. Set the node to send data to the TTN server: AT+DTRX=0,10,2,0109 (it can be sent after successfully connecting to the network, and the data format is an even number)

2.Select the development board model, COM port, and burn!(Picture 2)

3.Receive uploaded information on the TTN gateway server.(Picture 3)

Step 6: Verify Lorawan Gateway Functionality

1,Prepare the front equipment, place the lora nodes and sensors outdoors, and place the gateway in a WiFi environment(Picture 1/Picture 2)

2,View the relevant data uploaded by the gateway received on the server.(Picture 3)

3,Convert hexadecimal data into decimal data to obtain intuitive environmental data.(Picture 4)


Thanks for reading!