LakeNet Stateless LoRa Mesh Network

The goal of the project is.................................
=Problem Definition=
Project Goal: Develop a mesh network of nodes to be placed in buoys around lake Coeur d'Alene. These buoys will contain ESP-32 microcontrollers to monitor and record data such as O2 content, water temperature, and air temperature around the lake, and send that data back to a database in Coeur d'Alene to help with future lake reclamation projects.
==Background==
North Idaho has an extensive mining history that has created environmental problems that threaten Lake Coeur d'Alene. Currently, 75 million metric tons of contaminated sediment on the lake bed are the focus of ongoing cleanup by the EPA. The computer science department at the University of Idaho is involved in Our Gem Coeur d'Alene Lake Collaborative to "preserve lake health and protect water quality." Our team is tasked with creating a low-cost, low maintenance mesh network of nodes to collect data about the lakes of Coeur d'Alene to aid in the environmental monitoring of the lake.​
==Deliverables==
The network devices must:
*Integrate nodes into a stateless LoRa mesh network.
*Collect useful data such as Temp, Humidity, GPS location, and time.
*Send data from the network nodes about the lake to a database.
*Be robust and fixable. If a node in the network goes down for any reason, the rest of the nodes in the network should continue to send important information to the database.
==Specifications==
Node Specifications:
*Heltec LoRa Wifi ESP-32 v.2 boards (915 mhz)
*GPS Sensor 
*ASAIR DHT22 Temp/Humidity Sensor
*MySQL Database
==Value Proposition Statement==
The lakes and waters of North Idaho and the surrounding areas are in need of environmental monitoring and data gathering in order to maintain the health of the bodies of water. There is a need to create some sort of system that can be implemented into the lakes to collect data in an efficient and low-cost manner. The goal of this project is to implement ESP32s, low-powered microcontrollers, into these bodies of water to create a stateless mesh network of nodes using LoRa, or Long Range communication. This solution will be inexpensive and will also require little maintenance, while also providing frequent information gathering.
=Design Considerations=
*Each LoRa node should be robust and independent so that if a node goes down, the system will remain operational.
*The timing on the GPS sensors will sync nodes so they can communicate at the appropriate times to prevent data flooding.
*Sensors can be added to the system to collect other kinds of data for lake reclamation work.
*Packets sent by the LoRa nodes should maintain data integrity from the time of collection to storage in the database.
*Packets will be preserved (as long as possible) until the payload is integrated into the database.
=Project Learning=
* Create an RTOS (Real Time Operating System) using freeRTOS
* Doug Park's Masters Thesis and project on A Stateless LoRa Mesh Network
* How to gather data from microcontroller sensors
thumb|SBNPL Data Flow Diagram	thumb|SBNPL State Diagram
=Final Design=
thumb|Network Node Block Diagram
The final design of our project contained 2 tasks.
*Task Create (priority 1) creates a packet. Depending on the packet type, it might pull data from the DHT22 temp sensor.
*Task Scheduler (priority 24) decides what to do based on packet type. Sometimes it sends, listens, or blocks.
*Future Task Suggestions: 
**Task for sensors to gather data
**Task for sleep function
	
Gateway node:
*WiFi to connect to server. LoRa to connect to SBNPL network nodes
*Not an RTOS. Implemented with loops
*3 Queues: Transfer Queue, Backup Queue, Visitor List
Network nodes:
*Sync time, broadcast time, listen time
*Data packet, Node receipt, end receipt
Packet Type 	Packet Structure 	example
Data Packet 	[Packet Type] [Packet ID] [Src Mac] [Dest Mac] [Payload] [Mac addr of any node*]​	0 300 BC70 A27C Temp 24.80 BC70
Node Receipt	[1] [Packet ID] [Dest Mac] 	1 300 BC70
End Receipt 	[2] [Packet ID] [Packet ID to remove] 	2 401 201
Simple explanation:
When a data packet (call it packet A) is created by a node, a copy is made and put in the backup queue, and is sent to the next node. If the node is not the gateway node, it is added to the VL, and BQ, then transmitted by the next node. When the original packet (packet A) makes it to the gateway node, the payload is added to the database, then an ER (end receipt) is created and sent back to the network nodes. When the network nodes receive the ER, they check the ER against what is in the backup queue, and if the ER matches the packet in the backup queue, the data packet in the backup queue is dropped, and the ER is passed to the nodes that need the ER for packet A. If for some reason, packet A does not reach the gateway node, the node in the backup queue will be pulled into the TQ to be sent to the gateway node.
=Validation=
Requirement 	Test 	Test Subject 	Target Date	Result
Initial Transmit LoRa test 	Demonstrate Sending and Receiving Packet 	ESP32 	11/15/2021 	Success. Packets sent and received
Create Packet 	Create a packet in FreeRTOS on ESP32 	ESP32 freeRTOS 	12/10/2020 	Success. Created unique packets with identifiers (nodes)
Sensors 	Implement temp/humidity sensor into network nodes	ESP32, DHT22, 	2/27/2021 	Success. Other sensors can be added later.
GPS Setup and Sync 	Setup GPS modules and sync them. 	ESP32, Neo6m GPS 	3/15/2021 	Success. Timing works between nodes and gateway node.
RTOS LoRa Send/Receive Packets	Send and receive packets through RTOS. 	ESP32 	4/7/2021 	Success. Each node is given distinct name in code.
Send data to database 	Move data from network node packet to DB. 	ESP32, Apache Web Server, MySQL database	4/20/2021 	Success. DB can be accessed publically.
=Team Members=
	Luke Ryssel
Major: Computer Science 
Hometown: Coeur d'Alene 
Responsibility: Contact lead, Design Assistant 
Email: ryss4741@vandals.uidaho.edu		Nate Osterberg
Major: Computer Science 
Hometown: Coeur d'Alene
Responsibility: Wiki page lead, Design Assistant 
Email: oste1799@vandals.uidaho.edu
	Ronnie Keating
Major: Computer Science
Hometown: Post Falls
Responsibility: 
Email: keat2139@vandals.uidaho.edu		
=Additional Documentation=
Project Schedule
Gantt Chart
Presentations
Concept Design Review
Snapshot 1
Snapshot 2
Snapshot 3
Expo Presentation
Project Budget
Budget