Real-Time Foot Traffic Processing with Dor and Losant

When measuring foot traffic, you are recording how many people enter or exit a space, and how often that area is used. This technology allows us to answer questions such as:

  • How can I track the number of people moving in and out of a space? 
  • How can I monitor the usage and utility of a space? 
  • How can I evaluate the return-on-investment of a physical space?

Monitoring the usage of space is a common request we get all the time at Losant. From a technical perspective, there are many ways to attack problems of this nature. However, not too long ago, I was introduced to a new solution that aims to solve this problem. Dor is a foot traffic solution that’s accurate, affordable, and easy to install in any location.

 

hp-family-shadow.93cd1b8e

Dor provides data almost instantaneously after installation. Best of all, it can integrate directly with Losant. With Losant, you have the opportunity to integrate Dor with any other service, build complex business logic on top of the sensor data, and build custom websites and applications.

In this blog post, I am going to describe how to send foot traffic data from Dor into Losant and make use of it. 

Obtain a Dor API Token

Dor provides a simple REST, JSON based API that allows you to receive your foot traffic data programmatically. 

The Dor Foot Traffic as a Service API gives you direct access to each Dor sensor in your fleet. The simple yet powerful API allows you to retrieve the latest foot traffic events as well as useful status information about your sensors such as orientation and battery level allowing you to easily manage large deployments.

First, you’ll need to contact Dor for an API token.  Once you have a token, you’ll have access to their Foot Traffic API. Here is the URI to obtain this information:

/teams/:team_id/devices/:device_type_name/:serial_number/foot_traffic_events

Using Losant we can authenticate and call this API to obtain our foot traffic data on a specific interval.

Create a Workflow

The sensor will report foot traffic to Dor on a (configurable) interval. My device is reporting once an hour, which is the default. Using a Losant Workflow, we can build a workflow to facilitate the communication between Dor and Losant.

To accomplish this, we can use the Timer Node to poll the Dor API once an hour to receive all the foot traffic data since Losant last checked. Here is that exact workflow:

Image 2017-12-18 at 6.17.55 PM
This workflow contains two Trigger Nodes. The four-node flow on the right is to authenticate, and reauthenticate, to Dor ever hour. Every hour this flow will make an HTTP request to obtain a new authentication token and save it in the workflow’s local storage. 

In the left flow, every hour we follow the following steps:

  1. Get Value Node: Get the last reported foot traffic data point. (This is saved later)
  2. Function Node: Calculate the start and end time of the data we’re looking for. Here is the code:
    let last_dor_point = new Date(payload.data.last_dor_point);
    payload.dor = {};
    payload.dor.end = payload.time.toISOString();
    payload.dor.start = last_dor_point.toISOString();
  3. Get Value Node: Get the Dor authentication token that’s refreshed once an hour. (Saved in the four-node flow on the right)
  4. HTTP Node: Make an API request to Dor’s Foot Traffic API. Here is what the request (using string templating and globals) looks like:
    https://api.getdor.com/v1/teams//devices///foot_traffic_events?start=&end=&order=desc
  5. Conditional Node: Did we get any new foot traffic data?
    1. If we didn’t, end with a Debug Node.
    2. Loop Node: If we did, Loop through all the data points, and save each traffic event as a state update on a device using the Device State Node. Here is what’s contained in the Loop Node:Image 2017-12-18 at 6.27.15 PM.png
  6. Set Value Node: Save the last reported foot traffic data point. 

With this workflow, every hour we can save all the foot traffic events to Losant, and make sure Losant is always authenticated to Dor’s API. 

Now that we have data flowing into Losant, we can start to build on top of it. 

Setting up Alerts

Losant makes it easy for you to answer new questions about the data you are collecting.  For example: Can we be alerted when someone walks in after hours? Yes, you can. This task is done by adding two nodes to our existing workflow: A Time Range Node and an Email Node.

 

Image 2017-12-18 at 6.29.27 PM

The Time Range Node allows a workflow to perform actions based on the time the workflow was triggered. The Email Node can send an email with a custom body that can even pull from your sensor data if desired. All in all, when there is traffic during the off times, you’ll get an email.

Next Steps

Now that your foot traffic data is integrated to Losant, there are endless possibilities. With Losant, you can tie your Dor data to any other critical system you may have to provide you with the more comprehensive view. 

Screenshot-2017-12-18 Dor - Losant

Along with custom dashboards, you can:

Here at Losant, we are interested to see what problems you are trying to solve with foot traffic. If you have any questions or feedback, please leave a comment or contact us

There are 3 Comments

What is Losant?

Losant is an enterprise IoT platform that makes it easy to build secure, complex connected experiences.

Losant’s platform enables you to intelligently manage your devices, collect and visualize data, and ultimately take action on data through highly customizable workflows - all in real-time.

Get Started For Free