Few weeks ago, I published my first LoRa WAN project titled Helium Network GPS Tracking Directly In Google Sheets. It was a quick and simple device to send GPS coordinates to Google Sheets without cellular data or any online services other than Helium Console. Helium extended the deadline to submit a project to #IoTforGood contest so I bought few LoRa modules online. The first one came in fast but it was the wrong frequency (my bad). The second one came a week later and it is the one I ended up using here. The main two LoRa modules are yet to be delivered which presented one of the challenges of this project.
Today, we will be building Basic Locator Over Ubiquitous Network (BLOUN). The new device will have few extra features such as local storage and Google maps in Google sheets.
One of the features we will be adding is locating lost pets off Helium Network ground coverage. I was planning to accomplish that by placing one of the LoRa modules on a dog and the other connected to BLOUN. Since the two LoRa modules I was counting on didn't arrive in time and I'm too cheap to pay 11 times the cost of the module for expedited shipping, I had to get creative. The only LoRa Module I have will be placed on the dog and I will have B-L072Z-LRWAN1 toggle between LoRaWAN to send data on Helium Network and LoRaRadio to communicate with LoRa Module on the dog.
I'll try my best not to repeat any thing I covered in the previous project or in the documentations here. I will also try to show not only what I had achieved, but also how I got there.
Game PlanWe will build a solution to work as follow:
1 - Helium Network sends a Be On The Lookout to an aircraft in a specific geographical location
2 - Dog identifier and expected reply relayed to Sony Spresense
3 - GPS coordinates and command to search sent to B-L072Z-LRWAN1
4 - Search call is made
5 - Dog replies to its name
6 - Reply compared to expected reply received from Helium Network
7 - GPS coordinates and search results sent to B-L072Z-LRWAN1
8 - Data sent to Helium Network
Finding A Dog In A Dog Stack"You can't miss what you never had". In order to show how to find a missing dog, I gotta have one first. I asked Laura D. to borrow her dog but she refused (maybe still upset about that project?). Who would have thought that getting a dog could be that difficult? I even walked up to a stray on the street and asked him "Hey dog, wanna make some money?" then he took off running.
Meet Sparky; he's a good boy. Found him at the dollar store and thought that could be a good twist in the plot. Sparky barks when you press his button, but he will be modified to bark when he hears his name over LoRaRadio.
Paired with RFM95W, this would be the setup for the device to put on the dog. Arduino Pro Mini may not have a USB port, but it is cheap, lightweight, small, low power(ish), and good enough for the job.
It's a board that looks like an Arduino Uno, but it is far superior. We don't need the multi core feature on this project, but we will utilize the Micro SD card slot and GPS. Sony Spresense will be powered via USB cable and it will provide power to B-L072Z-LRWAN1. It will also send reset signals to B-L072Z-LRWAN1 for a reason that will be explained later.
We will use SX1276 which is part of B-L072Z-LRWAN1 to communicate with RFM95W on the dog.
Just like the previous project, we need only one Device defined in Helium Console. We also need only one Integration to send data to Google Sheets. We added Cayenne Integration and HTTP Integration just for troubleshooting.
Lastly, we need a Label to pull everything together and a Function to decode payload of JSON.
Software - Google Apps ScriptThe first main function of the script is doPost() which will be invoked by GoogleSheetsIntegration. The function starts by calling our Spreadsheet by its id, create a tab for today's date if it doesn't already exist, then fill a row in the Spreadsheet with JSON contents. The function will also highlights the data with Magenta if the dog has been found in that location.
The other main function of the script is onOpen(). Opening the Spreadsheet will trigger using GPS coordinates of the most recent tab to add markers to Google Maps. The first marker will always be Green and the last Marker will always be Red. All markers in between will be Blue except if the dog is found then it will be Magenta. If a point is more than 10 minutes from the previous one, the function will automatically start a new map.
Software - Arduino IDEWe have all the code in one Arduino Sketch using Compiler Directives. This was very useful in aligning inputs and outputs.
Here is an overall view of the code:
#if defined(ARDUINO_ESP32_DEV) || defined(ARDUINO_AVR_MINI)
.
.
.
#elif defined(ARDUINO_spresense_ast)
.
.
.
#elif defined(ARDUINO_STM32L0_B_L072Z_LRWAN1)
.
.
.
#else
#error Unsupported board selection.
#endif
That allowed us to use one file and just change Board and Port in the Tools menu. Arduino IDE loads the selected Microcontroller with the right code. Note that each section of the three shown above must have both setup() and loop() functions.
If you want to know what is defined for your boards find boards.txt and platform.txt. For example, here is where to find those files in windows
C:\Users\<login>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4
In both files search for "build.board". In platform.txt we have "-DARDUINO_{build.board}" and in boards.txt we have ".build.board=ESP32_DEV". put them both together and you get ARDUINO_ESP32_DEV. There could be an easier way to do this, but this is what worked for me.
Software - Arduino IDE - ESP32 or Arduino Pro MiniWe try to use the smallest Arduino possible to build a project. However, during development, it was easier to work with ESP32 than Arduino Pro Mini. The code started from LoRaReceiver example then has been modified to wait for the dog's name to be called then reply. Similar to Marco Polo except the dog's name and the reply would be unique.
Software - Arduino IDE - Sony SpresenseWe will be utilizing an ancient technique known as Marco-Polo. Sony Spresense will send a reset signal using a GPIO pin to B-L072Z-LRWAN1 followed by a comma separated string of GPS data and the dog name over UART.
Software - Arduino IDE - B-L072Z-LRWAN1The GPS part of the UART string will be sent to Helium Network then the dog name will be sent to all radios within reach. B-L072Z-LRWAN1 will then receive a reply, and send it to Sony Spresense for comparison with the expected reply. The results of the comparison will be sent to Helium Network in the subsequent transmission.
We ended up putting all the code in setup() and kept loop() empty. The reason for that is we can include LoRaWAN.h and LoRaRadio.h but we can't use them concurrently. As soon as we begin LoRaRadio, LoRaWAN stops working. That's why we used Sony Spresense to reset B-L072Z-LRWAN1.
Keeping it realIf you can't just scramble some hardware together then type some lines of code and everything auto-magically works, then this section is for you. In addition to serial monitor and builtin LEDs we have few troubleshooting tools at our disposal. Starting with the very powerful Helium Console we can see our devices and debug live data. If we want to keep JSON text a little longer then we need to create HTTP Integration. We'll have to provide an Endpoint which we can get for free from https://requestbin.com/r. Creating this HTTP Integration in Helium Console helped write the script to insert data in Google Sheets by clarifying data structure.
More help with Google Sheets came from https://apitester.com. At that site we can POST HTTP requests to the Apps Script for Google Sheets. This is very useful if we want to test committing data to Spreadsheet without spending data credits or waiting for the right set to become available. All we have to do is grab JSON that we intercepted from the first website, modify it if needed, then POST.
If you think that's too much work, you can still get some valuable information from https://cayenne.mydevices.com. Just create a free account then create the Prebuilt Integration in Helium Console. You don't even have to create a dashboard because it will be created for you automatically and can be modified to fit your needs.
We collected information about hotspots from JSON. Three columns have been added to the Spreadsheet to capture hotspot name, RSSI, and SNR. We didn't capture hotspot GPS coordinates in the Spreadsheet. We looked up the coordinates of one of the hotspots that we captured during a test flight.
We departed from Houston and went all the way out to Eagle Lake mainly climbing.
Distance from the ground was a little over 2.5 miles, but we climbed to clear obstacles not to gain distance from the hotspot.
Finally, we calculated the distance between our GPS coordinates and the hotspot's and found it to be 51 miles (elevation is negligible).
Just to be clear, this device to be placed on the dog not in it.
I have been on Helium Network every day of the past few weeks. I gathered a lot of data in Google Sheets and uploaded some of it to Github at the link below. Many thanks to Helium and Hackster for providing the discovery board and then extending the deadline which allowed me to order more parts and improve my original simple project. I hope you enjoyed this project as much as I did and learned few things a long the way.
DemoThis product has not been tested on animals. No real dogs were harmed in the making of this project.
I did a couple of flights in the morning of the submission date. In the first flight Sparky was off, but in the second flight he was on. Since the flights were more than 10 minutes apart, Apps Script created two maps on today's tab.
Just for S's & G's, I looked up the data in requestbin.com and cayenne.mydevices.com to make sure all three integrations worked properly.
In addition to all the data presented, here is a video of Sparky reacting to LoRa communication sent from the plane taking off which we can barely see in the background.
Comments