Skip to main content

Syncing data from your SPOT Satellite Messenger to CartoDB

In my last blog post, we looked at how you can track your trips using the open API of the SPOT Satellite Messenger. A limitation is that you can only get your locations from the last 7 days, and the web service has request limits (500 request within 15 minutes). To avoid these limitations we can sync the data to a CartoDB account using a PHP cron job. CartoDB is a great choice as it allows us to both visualize and to query our tracking data.

A cron job is a script on the server running periodically at fixed times, dates, or intervals. I've created my cron job in PHP, but you can choose the language you want. What you need is a server which allows to run scripts repeatedly. I'm using the cron job support from my hosting provider, Bluehost. As I'm tracking my position every 10 minutes, the cron job is running at 10 minutes interval to sync the data.

CartoDB is providing a simple PHP library to make use of the CartoDB API as easy as possible. The library allows us to authenticate (using OAuth) and run SQL queries on our CartoDB account. You don't have to authenticate to read data from the SPOT API, but you need to create a shared page to obtain your feed id.

In my PHP script, I'm first reading the JSON feed from SPOT, and the last timestamp from my CartoDB table. Then I'm looping through the tracking points from SPOT, and if the timestamp is newer, I'm adding the point to CartoDB.


You need to add your feed id from SPOT and your CartoDB credentials. Remember to create the table in CartoDB before you run the script! The PHP script is available on Github. Feel free to improve it!

In the next blog post, we'll display the tracking data on a map. 

Comments

danieltakayama said…
Hi! I found Your blog while searching for solutions to show spot messenger positions. I really like it and think You do some good stuff! :-) I'm a beginner so this might be a bad question. I doesn't understand if Your Github should have included a config.php? And should this config.php specify the spot feedid and maybe more? I would appreciate if You have time to give me a headsup! Kepp up the good work! Best regards, Daniel
Peter Ribe said…
Hi Bjørn!

I have recently made a site for a friend of mine, http://roferd.no, that monitors a 3300km one-man rowing expedition around the Norwegian coastline. I am a novice at this but, inspired by your blog, I have managed to prepare a Leaflet map and store the mapping data in CartoDB. I will probably give the syncing part a go very soon too. Maybe you could tell me how I can make Leaflet focus on the active marker only, instead of all the markers (fitBounds)? Best regards, Peter

Popular posts from this blog

Creating a WebGL Earth with three.js

This blog post will show you how to create a WebGL Earth with three.js , a great JavaScript library which helps you to go 3D in the browser. I was surprised how easy it seemed when reading a blog post  by Jerome Etienne . So I decided to give it a try using earth textures  from one of my favourite cartographers, Tom Patterson . WebGL is a JavaScript API for rendering interactive 3D graphics in modern web browsers without the use of plug-ins. Three.js is built on top of WebGL, and allows you to create complex 3D scenes with a few lines of JavaScript. If your browser supports WebGL you should see a rotating Earth below: [ Fullscreen ] To be able to display something with three.js, you need three things: a scene, a camera and a renderer. var width  = window.innerWidth,     height = window.innerHeight; var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(45, width / height, 0.01, 1000); camera.position.z = 1.5; var rende...

Thematic Mapping Engine

It's time to introduce the Thematic Mapping Engine (TME). In my previous blog posts, I've shown various techniques of how geobrowsers can be used for thematic mapping. The goal has been to explore the possibilites and to make these techniques available to a wider audience. The Tematic Mapping Engine provides an easy-to-use web interface where you can create visually appealing maps on-the-fly. So far only prism maps are supported, but other thematic mapping techniques will be added in the upcoming weeks. The engine returns a KMZ file that you can open in Google Earth or download to your computer. My primary data source is UNdata . The above visualisation is generated by TME ( download KMZ ) and shows child mortaility in the world ( UNdata ). The Thematic Mapping Engine is also an example of what you can achieve with open source tools and datasets in the public domain: A world border dataset is loaded into a MySQL database . The same database contains tables with statistics ...

Creating 3D terrains with Cesium

Previously, I’ve used three.js to create 3D terrain maps in the browser ( 1 , 2 , 3 , 4 , 5 , 6 ). It worked great for smaller areas, but three.js doesn’t have built-in support for tiling and advanced LOD algorithms needed to render large terrains. So I decided to take Cesium for a spin. Cesium is a JavaScript library for creating 3D globes and 2D maps in the browser without a plugin. Like three.js, it uses WebGL for hardware-accelerated graphics. Cesium allows you to add your own terrain data, and this blog post will show you how. Impressed by the terrain rendering in @CesiumJS - with a 10m elevation model for Norway! Farewell Google Earth. pic.twitter.com/RQKvfu2hBb — Bjørn Sandvik (@thematicmapping) October 4, 2014 Compared to  the dying Google Earth plugin , it's quite complicated to get started with Cesium. The source code is well documented and the live coding Sandcastle is great, but there is a lack of tutorials  and my development slows down when ...