Introduction: LTE Arduino GPS Tracker + IoT Dashboard (Part 2)

Picture of LTE Arduino GPS Tracker + IoT Dashboard (Part 2)

Intro & Part 1 Recap

Yup, it's time for yet another Instructable on the SIM7000 GPS tracker with Arduino and LTE! If you haven't already, please go over the getting started tutorial for the SIM7000 LTE/NB-IoT shield then read up on Part 1 of the GPS tracking tutorial. As such, I'm going to assume that you have all the hardware set up and ready to post data to the cloud all we really need to do in this tutorial is familiarize ourselves with ThingsBoard and do another road test to see the amazing data it shows!

In Part 1 we successfully got our nifty GPS tracker to send data to dweet.io and fetched the data on freeboard.io to visualize the data. However, I soon realized that the map functionality was quite lame on freeboard since it doesn't allow you to move the cursor around or even resize the widget window. This led me to a better solution: ThingsBoard.io which is a super-awesome IoT dashboard (and free!) that allows you to store, visualize, and customize the heck out of your data! You can drag to rearrange widgets (and it works in Chrome unlike freeboard), and the overall quality is the cream of the crop. Most importantly, the Google map widget allows you to free move around, zoom in and out, and select different styles (satellite, road view, etc.) and even allows you to drag and drop the little yellow guy onto the road for street views!

Step 1: ThingsBoard Setup

Picture of ThingsBoard Setup

ThingsBoard Account & Device Setup

The first thing you should do is go to the ThingsBoard home page then create an account by clicking the top right menu button and selecting "Live Demo". Create an account, verify your account in an email they send you, then log back in to the Live Demo homescreen. This should bring you to a screen where you can manage all your devices, edit dashboards, etc.

Next, select the "Devices" tab on the left hand side. This should bring up a bunch of demo devices like ESP8266, DHT22, Arduino and Pi demos, etc. Create a new device by clicking the red "+" button at the bottom right and enter a name and choose "default" for device type. After clicking "ADD" you should see your new device in the Devices tab. Click on "Manage Credentials" and you should see a small window pop up showing the device's access token. This is essentially the device ID and is analogous to the device ID used for posting data to dweet.io. You can change this device ID to the IMEI number of your shield if you want, but you can also just use the auto-generated token. Copy this token as you will need it in the Arduino sketch.

Arduino Example Setup

In this tutorial we'll be using the exact same example Arduino sketch as in the first tutorial but this time I've updated the sketch to include code to send data directly to ThingsBoard.io instead of dweet.io in Part 1. As always, you can find the example code here on Github.

The first thing you need to do is comment out the lines that make the shield post to dweet.io:

// GET request
/* // You can adjust the contents of the request if you don't need certain things like speed, altitude, etc. sprintf(URL, "http://dweet.io/dweet/for/%s?lat=%s&long=%s&speed=%s&head=%s&alt=%s&temp=%s&batt=%s", imei, latBuff, longBuff, speedBuff, headBuff, altBuff, tempBuff, battBuff);
  int counter = 0; // This counts the number of failed attempts tries
  // Try a total of three times if the post was unsuccessful (try additional 2 times)
  while (counter < 3 && !fona.postData("GET", URL, "")) { // Add the quotes "" as third input because for GET request there's no "body"
    Serial.println(F("Failed to post data, retrying..."));
    counter++; // Increment counter
    delay(1000);
  }
  */

Next, un-comment the lines that post to thingsboard.io:

// Let's try a POST request to thingsboard.io
const char* token = "YOUR_DEVICE_TOKEN"; // From thingsboard.io device sprintf(URL, "http://demo.thingsboard.io/api/v1/%s/telemetry", token); sprintf(body, "{\"latitude\":%s,\"longitude\":%s,\"speed\":%s,\"head\":%s,\"alt\":%s,\"temp\":%s,\"batt\":%s}", latBuff, longBuff, speedBuff, headBuff, altBuff, tempBuff, battBuff); // sprintf(body, "{\"lat\":%s,\"long\":%s}", latBuff, longBuff); // If all you want is lat/long
  int counter = 0;
  while (!fona.postData("POST", URL, body)) {
    Serial.println(F("Failed to complete HTTP POST..."));
    counter++;
    delay(1000);
  }

Upload the code to your Arduino, make sure you have the SIM card and antenna attached, and verify that the shield is sending code to the cloud before proceeding!

Step 2: Verify Data Reception

Picture of Verify Data Reception

In order to actually verify that data is being sent to ThingsBoard correctly, go to the same device details page (click on the GPS Tracker device tile in the "Devices" page) then click the "Latest Telemetry" tab. If your GPS tracker is sending values to ThingsBoard you should see the latest values here and they will update in real time as they come in.

Now that you've verified that ThingsBoard is actually getting the data it's time to set up the dashboard so we can visualize our data when as we collect it! (Or after the fact)

Step 3: Setting Up Dashboard

Picture of Setting Up Dashboard

Now it's time for the fun part! Now click the "Dashboards" tab on the left and select your GPS tracker device. This should bring up a new page that asks you to add widgets. Click the bottom right "+" button and "create new widget" to bring up a dropdown menu of widgets to choose from. For now let's add a "digital gauge". Selecting this should load a bunch of previews for all the different types of digital gauges you can choose from. When you click on one it will bring up another screen for you to set up the widget parameters. The first thing you need to add is the datasource (your GPS tracker device which sends the data to ThingsBoard). Press the "+ ADD" button and select your "GPS Tracker" device and select the appropriate variable that you want the widget to display. In this case, let's choose the variable "temp" (temperature).

Now if you want to add things like a title for the widget, go under the "Settings" tab, check "Display title", and enter a title. There are lots of other things you can do under the "Advanced" tab but I will let you investigate those yourself! Have fun changing the value ranges, label text, colors, and more! After adding the widget it will appear at the bottom left of your dashboard (you may have to scroll down if you have multiple widgets filling the screen). You can edit the widget at any time by pressing the button on the widget if you're already in the dashboard edit mode, or enter the edit mode by pressing the pencil button at the bottom right of the entire screen first to allow you to edit the widgets. Pretty straightforward!

Step 4: Adding a Map!

Picture of Adding a Map!

Now for a GPS tracker a map is a must-have! Let's add one by creating a new widget (bottom right "+" button again) and this time scroll down and select "Maps". Go ahead and click on one and it will bring up the options for it. Add the datasource as usual but this time, select both "lat" and "long" variables since it will need both of these to get the location. Next, go to the "Settings" tab and here you can set the timewindow of the data to display on the map. For example, you may only want the last 2 minutes of data to appear, or you may want all data since yesterday, or maybe you just want a fixed window in time (like 2PM yesterday through 10AM today).

If you want you can then go to the "Advanced" tab and select the map type (roadmap, satellite, hybrid, or terrain). Perhaps the most important part of all this is to check the latitude and longitude key names. Make sure these names correspond exactly to the variable names you're actually sending to ThingsBoard. For example, if your Arduino sketch says it's sending "lat" and "long" variables (which it is by default) then you need to change the key names to "lat" and "long" and using "latitude" and "longitude" won't fetch your data!

Again, after adding the map it will appear at the bottom of the dashboard. Simply drag it to re-position it on the dashboard and click and drag the edges to resize it. If your timewindow was set correctly you should see your current location appear on the map. Super neat huh? Now we're ready for a real test!

Step 5: Road Test

Picture of Road Test

Testing the GPS tracker is super simple! Just plug the Arduino into a car USB adapter to power it, make sure the green LED turns on, and it should start sending data! To change the sampling rate of the GPS tracker make sure you find this line of code in the example sketch:

#define samplingRate 10 // The time in between posts, in seconds

and set it to whatever you want. I found that 10s works quite well for a leisurely road test, but if you're fast and furious maybe you might want an even higher sampling rate!

Step 6: Results

Picture of Results

In the pictures above you can see my dashboard setup. I added charts to graph historical data for things like speed, altitude, and temperature, and also included real-time gauges in case I want to see them in real time on another road trip (image this in an RV!).

The map was killer awesome and I managed to collect some really accurate data of a route I took. Also, the speed data was extremely accurate because we never exceeded about 40mph (the graph is in kph) on the city roads. The many fluctuations in speed can be explained by the traffic lights. Overall, great results and just imagine what else we could use this for! You could install this on an RV, motorcycle, car, etc. and have it track all the time and pull up the results on ThingsBoard!

To summarize, in this tutorial we programmed our GPS tracker to send data directly to ThingsBoard via HTTP POST requests and managed the data on a dashboard. You can add multiple devices and dashboards, each containing multiple widgets that look super cool and have lots of customization options! ThingsBoard has proven to be a very powerful (and free!) tool to view IoT data and there are even other features that I haven't even scratched. Feel free to play around with it and see what you find.

  • If you liked this tutorial, made your own, or have any questions, please make a comment below!
  • Be sure to give this Instructable a heart and subscribe here and on my YouTube channel for more awesome Arduino-related tutorials!
  • Please vote for this Instructable for the contests it's in!
  • I'll be launching a crowdfunding campaign for the SIM7000 LTE shield for Arduino on Feb 1st. Sign up to be notified on the pre-launch page!

I'll see you next time!

Comments

About This Instructable

1,089views

38favorites

License:

Bio: I'm a young engineer with a passion for DIY and electronics! Learn to share, share to learn!
More by arduinofanboy:LTE Arduino GPS Tracker + IoT Dashboard (Part 2)LTE Arduino GPS Tracker + IoT Dashboard (Part 1)ESP32 BLE + Android + Arduino IDE = AWESOME
Add instructable to: