How to use the Geotab data feed
Pull live or historical data quickly with the Geotab SDK data feed. Video transcription of the DEV Channel video with step-by-step instructions.
Pull live or historical data on all your vehicles with the Geotab SDK data feed. The Geotab data feed API is a scalable, efficient, and secure method to access device data.
What is the Geotab Data Feed?
The Geotab Data Feed is an example application that allows a third party to easily receive all the telematics data from your GO devices. The application can be run interactively or in the background as a Windows Service. The application produces easy-to-consume CSV files containing the key telematics data sets with updates every few seconds.
The application can easily be customized when further integration is required, such as pushing the data into a Web service, writing to a database, etc.
Read this transcript to learn how to get large amounts of data from MyGeotab in a fast and efficient manner. The video is presented by Geotab Software Developer Nathan Mascitelli.
New to the Geotab SDK? Read our post "Intro to the Geotab Software Development Kit" for a complete overview of the SDK.
Using Geotab’s Data Feed (Video Transcription)
Hi. My name is Nathan Mascitelli and I'm a developer at Geotab. Today, I'm going to be showing you how to get data from MyGeotab using the data feed.
The data feed is essentially a method that when called allows you to pull large amounts of data quickly and efficiently from MyGeotab. You can also pull data as it comes in to give you a live feed of your devices. Not everything can be accessed with the data feed. Currently, only log records, status data, fault data, trips, and exception events can be retrieved with the feed.
For the most up-to-date information about what data can be retrieved using a data feed, please consult the data feed documentation at my.Geotab.com/SDK.
To show you how to use the feed, I'm going to build a C# console app that gets GPS data in real time and outputs the coordinates to the console. To start, I've created a default console app using Visual Studio. In order to use the MyGeotab SDK, I have to get the required DLL [Dynamic Link Library] which can be found, again, at My.Geotab.com/SDK. [New location on page: Go to CODE SAMPLES > .NET examples > Overview section to download the dotnet.zip file.]
Okay, so here are all the files that come with our SDK. There are a number of good examples which I encourage you to look at, but for now, all we need is the ObjectModel.dll. I'll import that into our project so we can use the MyGeotab objects.
First, I'm gonna make an API object. I need to provide my MyGeotab username, password, and the database I want to connect to.
Now that we have that, I'm going to create a simple while loop and call GetFeed using the API object. I'm also going to create a variable called Token that I will explain later.
In order to use the API object, you need to call the Call Method. It has several parameters. The first is the name of the method you want to call. In this case, GetFeed. Now GetFeed is a generic method so the next parameter will be the type parameter, in this case, LogRecord.
Finally, to pass in any additional parameters, we will create an anonymous object where the field names are the same as the parameter names. GetFeed has an additional parameter called From Version. We will pass the local variable token to the method as that parameter.
The Call method is generic, so we need to tell it what kind of object we want from it. For GetFeed, we want a feed result object.
You might be wondering what the fromVersion parameter is. FromVersion is basically a token telling the server what data you've already received and indicated what data you should get next. If you think of all your data as being ordered sequentially, fromVersion indicates a point on your data timeline.
When we first called GetFeed, our token is null. Because of this, the first call to GetFeed does not return any data. I'll show you that now. As you can see, we have no data. However, it does give us back an updated token stored in the feed result ToVersion property. If we give this result back to the server, we will get another updated token, as well as any data that has arrived since the last token.
So, first time we run the feed, we don't get any data, but we get an updated token. Then the next time we pull for data you can see that we got some data and again, the token was updated.
In this way, we can pull for new data. It is very simple then to loop and get new data. You simply need to get the token when you make a call to GetFeed and pass that back to the server the next time you call GetFeed. This allows you to continue to have a live stream of events, even if your application shuts down. Simply just store your token value and you can pick up right where you left off.
So, as you can see, we have live data coming in. And this is a good setup if all you want to get is a live feed up and running.
But what if you want to get more than just live data? If you wanted to get all the GPS data starting from yesterday, you can pass in a search object to the GetFeed call. This search object is the exact same as the one used in the standard GetMethod.
As you can see, the data starts from yesterday. The data will be given to you in chunks and your token needs to be updated the same as before. The search object allows for a lot of flexibility with the data feed. For example, you can pull GPS data only for a specific device. You could also get only specific status data, for example, fuel level in order to know which of your vehicles are low on gas in real time.
You can pull only live data or you can pull all the data Geotab has ever received from your vehicles. The data feed allows you to leverage the Geotab platform and its data in any way you see fit.
Hopefully, you now see the power and flexibility of the data feed. If you would like to know more, I encourage you to go look at Geotab's SDK documentation at My.Geotab.com/SDK. Thanks for watching.
Find more SDK training videos on the Geotab DEV Channel.
Suggested Reading: The Beginner’s Guide to APIs
5 Tips From a Geotab Software Developer on Building Fleet Management Solutions
More From This Author: Don’t Delay: How Late Notifications Work
If you liked this post, let us know!
Geotab's blog posts are intended to provide information and encourage discussion on topics of interest to the telematics community at large. Geotab is not providing technical, professional or legal advice through these blog posts. While every effort has been made to ensure the information in this blog post is timely and accurate, errors and omissions may occur, and the information presented here may become out-of-date with the passage of time.
Subscribe to the Geotab Blog
Sign up for monthly news and tips from our award-winning fleet management blog. You can unsubscribe at any time.
Other posts you might like
Mindfulness at work: 10 tips for productivity
Quick tips for staying refreshed and productive.
April 9, 2021
Creating effective health and wellness programs
Supporting employee health and wellness is critical to creating a positive working environment where individuals and organizations can thrive.
March 26, 2021