TNS
VOXPOP
Will JavaScript type annotations kill TypeScript?
The creators of Svelte and Turbo 8 both dropped TS recently saying that "it's not worth it".
Yes: If JavaScript gets type annotations then there's no reason for TypeScript to exist.
0%
No: TypeScript remains the best language for structuring large enterprise applications.
0%
TBD: The existing user base and its corpensource owner means that TypeScript isn’t likely to reach EOL without a putting up a fight.
0%
I hope they both die. I mean, if you really need strong types in the browser then you could leverage WASM and use a real programming language.
0%
I don’t know and I don’t care.
0%
Edge Computing / Tech Life

Tracking Live Cricket Scores with Arduino and the Parse IoT SDK

Apr 18th, 2015 10:30am by
Featued image for: Tracking Live Cricket Scores with Arduino and the Parse IoT SDK

In India, cricket is more of a religion than a sport. Even before the World Cup fever came to an end, the Indian Premier League season started, much to the joy of cricket frenzied Indians. Though I am not a big fan of cricket, I wanted to build an IoT app that tracks the live score. Above is a picture of the prototype.

I want to start this article with two disclaimers:

1) This is not a detailed step-by-step guide to walk you through the entire setup, configuration and code. The objective is to show you what’s possible with available technologies and tools. If this inspires some of you to build something cool, I met my goal.

2) This example uses screen scrapping to get content from a website. We don’t encourage you to follow this technique for commercial usage. Please refer to the terms and conditions of the website or get in touch with their webmaster to understand their policy.

With that in place, let me take you on a tour.

The Prerequisites

You need the following before you start connecting the dots:

Let me explain the role of each component:

Arduino Yún is a powerful microcontroller development board from the hugely popular Arduino family. While most of the makers are familiar with Arduino Uno, Arduino Yún is preferred for scenarios where we need in-built networking and WiFi capabilities. It can be connected to the Internet without a special shield. According to the official website, the Yún distinguishes itself from other Arduino boards in that it can communicate with the Linux distribution onboard, offering a powerful networked computer, with the ease of Arduino. In addition to Linux commands like cURL, you can write your own shell and python scripts for robust interactions. Our code will run on Arduino Yún to receive the live score from the cloud.

Grove Base Shield is originally meant for Arduino Uno but works well with Arduino Yún. The shield makes it extremely easy to connect a wide range of sensors, switches and actuators to Arduino. Think of it as an interface between the development board and the Grove family of sensors.

Grove LCD RGB Backlight is a cool display to show not just ASCII characters, but even user-defined characters. We will use this to display the live score.

CloudScrape.com is an online tool that converts any webpage into a REST endpoint. Its visual designer is extremely simple and intuitive to extract content from a webpage. This will be the REST API gateway for us to get the live score.

Parse is a powerful mobile backend from Facebook. Recently, at the F8 Developer Conference, Parse announced native SDK for Arduino, which we’ll be using in our project. The code to invoke the REST endpoint and send the push notification to Arduino Yún will be hosted in Parse.

The following illustration depicts the flow:

Live_Score_IoT

Configuring CloudScrape

CloudScrape has the concept of a Robot, which is capable of scrapping the content from a webpage. Spend a few minutes playing with the designer to get familiar with the interface. Clicking on an element let’s you extract the value within the surrounding HTML. The below screenshot shows that we are extracting the first team’s name, the second team’s name, the score of first team, and the score of second team.

CloudScrape_IPL

When you hit the play button it should show the output. Since our LCD cannot show the full name of the teams, we will transform the value to show only the first characters. So, the Delhi Daredevils become DD and the Rajasthan Royals become RR.

CloudScrape_IPL2

Once you are done with the basic configuration, test the REST endpoint with cURL. CloudScape authentication scheme expects you to include an MD5 hash of the accountid and API key in the header. You can grab both from here. You can also generate MD5 hash from here. Just paste the accountid followed by the API key with no spaces and hit enter. Copy the MD5 checksum and save it. You also need to create a run task which will execute the robot. The run task id is required to invoke the REST endpoint.

Your cURL command should look like this:


If everything goes well, cURL should show you the JSON output of the score:

Configuring Parse

This step is pretty straightforward. Parse has excellent documentation for you to get started. Just create a new app from the dashboard and head straight to the installation object. Modify the channels array to add a new entry. Remember the name of this as it may be used in Arduino code to selectively subscribe to the push notifications. Go to settings and enable the client push option. Parse documentation for push notifications has all the details. Refer to that to learn how to send a push notification from the code.

Next, configure the background job to invoke the CloudScrape REST endpoint periodically and send a push notification to Arduino Yún. Refer to the Background Jobs documentation for details on configuring and scheduling the job. Below is the code that I used for the background job. Be cautious when scheduling the job. Hitting the destination website too often might lead to blacklisting the IP address.

Wiring up LCD With Arduino Yún

Since we are using Grove Base Shield, this is very simple. Carefully push the Grove Base Shield into the Arduino Yún pins. The Grove shield is not designed for Yún, so make sure the shield pins don’t touch the ethernet and USB sockets. Connect the Grove LCD to one of the I2C ports of the shield. The circuit should resemble the picture we saw at the beginning of the article.

Coding Arduino Sketch

You need two libraries before proceeding with the code:

  1. Parse SDK for Arduino.
  2. Grove LCD library from SeeedStudio.

Download and import them into your Arduino library. Use the following code to subscribe to Parse push notifications and displaying the output on the LCD:


That’s it! Connect the Arduino Yún to a power bank and enjoy tracking the live score from your lawn.

Next Steps

I am planning to add a buzzer that will beep every time the wicket falls. We can also change the background color of the LCD as it receives updates. If you have ideas to enhance this further, do let me know.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.