Introduction
What's up guys! This Instructable is a follow-up of my first Instructable on using the Botletics LTE/NB-IoT shield for Arduino so if you haven't already, please read it to get a good overview of how to use the shield and what it's all about. In this tutorial I'll focus on IoT data logging, and specifically, GPS and temperature tracking and provide you will all the code and guidance you'll need to hit the road and test it out!
This Instructable is mainly focused on the LTE shield that I personally designed and built, but everything here (including the Github Arduino library) should work on SIMCom's 2G and 3G modules like the SIM800/808/900/5320 as well since it's just an updated version of the Adafruit FONA library. Regardless of hardware the concept is exactly the same and you can do lots of cool stuff with this, including sensor data logging, remote weather monitoring, auto theft karma GPS tracking, etc... so read on!
The list is the same as in my first tutorial and is really simple!
For the GPS tracking test!
Now that you have all your parts, here's a quick recap of what you need to do to set up your hardware:
Arduino IDE Setup
If you haven't already, please see the "Arduino IDE Setup" and "Arduino Example" steps in the main product Instructable to make sure your board is functioning properly. In those instructions you'll need to download the library on the Github page and open the example code "LTE_Demo". After following those instructions you should have tested the network connection, GPS, and posting data to dweet.io.
IoT Example Sketch
Now that you've tested the core features of your shield, load the "IoT_Example" sketch in Arduino IDE. You can also find it here on Github. Upload this code to your Arduino and open the serial monitor and you should see the Arduino find the SIM7000 module, connect to the cell network, enable GPS and keep trying until it obtains a fix on location, and post the data to dweet.io. This should all run without changing any line of the code, assuming you're using the LTE shield and Hologram SIM card.
By default you will see the following line define the sampling rate (well, actually the delay in between posts).
#define samplingRate 30 // The time in between posts, in seconds
If this line is left uncommented, the Arduino will post data, delay 30s, post data again, repeat, etc. During the 30s delay you can do things like put the Arduino in low-power mode and fancy things like that, but to keep things simple I'll just use the delay() function to pause the operation. If you comment this line the Arduino will post data then go directly to low-power sleep mode indefinitely until you press the reset button on your Arduino. This is useful if you are testing something and don't want to burn your precious free data (although honestly each post uses practically nothing) or maybe you have external circuitry to reset the Arduino (555 timer? RTC interrupt? Accelerometer interrupt? Temperature sensor interrupt? Think outside the box!). Actually in the Burgalert 7000 tutorial I show how you can use a PIR motion detector to wake up the microcontroller.
The next line sets whether the shield will turn off after posting data or remain on. You might opt for the former choice by uncommenting the line if you're only sampling once in a while, but if you have a relatively high sampling rate you will want to leave the line commented so that the shield stays on and doesn't have to re-initialize, re-enable GPRS and GPS, etc. When the shield is left on it's able to post extremely quickly!
//#define turnOffShield // Turn off shield after posting data
Also keep in mind that this example automatically fetches the module-specific and globally-unique IMEI number of the SIM7000 and uses it as the device ID (or "name" if you prefer) to identify the device when it posts data to dweet.io. You can change this if you want, so I'd thought I'd just let you know :)
To check if your data is actually being sent to dweet.io, simply fill in the appropriate info and copy/paste the URL into any browser:
dweet.io/get/latest/dweet/for/{deviceID}where {deviceID} should be substituted with the IMEI number which is printed out in the serial monitor at the beginning, right after the Arduino finds it. After entering that URL in your browser you should see a JSON response like the following:
{"this":"succeeded","by":"getting","the":"dweets","with":[{"thing":"112233445566778","created":"2017-12-28T23:32:39.803Z","content":{"lat":11.223344,"long":-55.667788,"speed":10,"head":75,"alt":330.7,"temp":21.2,"batt":3630}}]}Looking at the "content" you should see the latitude, longitude of your location, your speed (in kilometers per hr), direction heading (degrees, with 0 deg being North), altitude (meters), temperature (*C, but feel free to convert in the code), and the supply voltage in milli-Volts (which is VBAT, the voltage of the battery). For more info on the NMEA data string you can take a look at page 149 of the SIM7000 AT command manual.
Once you verify that your setup is successfully sending data to dweet, let's set up the dashboard to view all our data on a nice interface!
For this tutorial we'll be using freeboard.io, a really cool IoT dashboard that can connect with numerous cloud platforms like PubNub and dweet, as well as other features like JSON and MQTT. As you probably have guessed we'll be also using dweet.io which is used in the example code from the previous section. As an important note, dragging panes in freeboard.io doesn't seem to work in Chrome so use Firebox or Microsoft Edge instead. If you don't, it can be a real "pane" to re-arrange the items on your screen!
Account & Device Setup
Dashboard Setup
Now let's take a look at how to set up the actual bells and whistles that you want to see on your screen!
dweet.io/dweet/for/112233445566778?lat=11.223344&long=-55.667788&speed=0&head=10&alt=324.8&temp=22.88&batt=3629
Extras
Since our little GPS tracker sends not only lat/long data but also altitude, speed, heading, and temperature, let's throw in a few more widgets to make our dashboard more colorful!
Have fun and set it all up how you like it because we're ready to go out on a field trip!
To test your setup I would recommend setting the sampling time to a lower value, like 10-20s so that you can capture your journey with higher resolution. I would also leave the "turnOffShield" variable commented out so that the shield doesn't go to sleep. This allows it to post data in quick succession.
After uploading the code to your Arduino, either get a battery pack (7-12V) to power the Arduino or simply plug the Arduino in using a car USB adapter. You will also need a 3.7V LiPo battery plugged into the shield as mentioned earlier; the shield shown in the picture above is an old version and didn't have LiPo battery support but it's now needed on all newer versions.
Next, open up freeboard somewhere so when you return you can see the results! Once you plug in the Arduino you're good to go! Start driving around, get some coffee, return home, and you should see the data plotted on freeboard. If you really want (I don't recommend this while driving...) you can view the freeboard data on your phone in real time as your friend drives the vehicle. Fun stuff!
For this test my dad and I went to get some chicken drums at Trader Joe's (omnomnomnom...) and we collected some pretty accurate data. I had the device send data every 10s and the max speed from the trip was about 92khm (around 57mph) which is quite accurate because we kept an eye on the speedometer the whole time. The LTE shield definitely does its job quite well and sends data to the cloud very quickly. So far so good!
However, perhaps the not-so-good news is that the map widget on freeboard isn't as great as I had originally thought. It doesn't allow you to move the location of your mouse and it stays centered on the last location so it's great for things like a car GPS tracker but not if you want to analyze a completed trip with all the data points, especially if it was a long journey.
In this tutorial we learned how to use the LTE shield as a GPS tracker and data logger and how to quickly view the data on freeboard.io. Now use your imagination and apply it in your own project. You can even add on more shields and turn this thing into a low-power solar data logger! (I might actually be planning on doing a tutorial on that in the future!). Because of the limitations of the freeboard map I'm also planning on making a brand new tutorial on how to make your own Android app that fetches the data from dweet and will allow you to graph the location of the tracker on Google Maps with start, pause, and stop features for your trip! Stay tuned!