World cup Led blinker

Hi there,

I was asked to post some code that makes a Led (or whaterver you want) blink when a goal is scored during the World Cup in Brazil. You should have a look at my first prototype here: As in the video, I first tried to give a random effect on the red LED strip but this is not the best effect… The code below rises the Output during 5 seconds then releases it.

I tried a few websites as data source, but seems to be the most responsive. With the TV latency in Switzerland, the red LED strip start blinking 5-6 seconds after the goal, which is acceptable for me.

Agent Code:
function AgentGetScore(val)
local request = http.get(“”,{});
local response = request.sendsync();
local responsebody=response.body;
local ex = regexp("<td class=“fs”> ([0-9]) - ([0-9]) ");

local res = ex.capture(responsebody);
    local TeamA = responsebody.slice(res[1].begin,res[1].end);
    local TeamB = responsebody.slice(res[2].begin,res[2].end);
    local Score = [TeamA,TeamB];
    //server.log("TeamA "+TeamA+" - "+TeamB+" TeamB");
    server.log("No datas");


device.on(“GetScore”, AgentGetScore); `

Device code:

/* Jean-Philippe Rey - 2014
World Cup Led blinker (or whatever you want to blink :smiley: )

Output <- hardware.pin9;

local Output_old;
local time=0;
local t_refresh=0;
local refresh_rate=3; // [seconds]
local goal_turnoff_time;

local TeamA_old=“0”;
local TeamB_old=“0”;

function setOutput(State) {

function main(){



imp.wakeup(0.5, main);


function get_score(score){
if( (score[0]!=TeamA_old) || (score[1]!=TeamB_old) )
//new score!
server.log(score[0]+" - "+score[1]);


I hope that could be useful for someone.

Have fun!

Jean-Philippe Rey

FUN! I live in England no chance… :frowning:

But great Idea thanks for sharing

Why live in England is no chance for that project?!?

Nice - thanks for sharing!

@jeanphilippe It will work I was commenting on the England team who won’t score a goal as they are Pants!!

@controlCloud Don’t say that, I am supporting England too!! :slight_smile:

I considered writing some code that would take crowd sourced twitter data and determine if a goal had been scored. Wonder if it would be any faster?

Joel for England you need a #groan filter :slight_smile:
@jeanphilippe here’s hopping we can do better than I hope for :slight_smile:

Improved version of this hack. Now with an emulated rotating light !!! :

By the way, did someone already did such a hack? My data source ( seems to be the fastest refreshed web page but… still too slow… about 20 seconds…
What was the secret with the Budweiser Red Light?!?

I think that the secret is paying a lot of $$$ for a live sports scores service.

Yes I think this is the only way to get minimal delay. And even with a low latency data source, it is quite difficult to synchronize the LED blinker with the live TV stream. I compared some Swiss providers, the delay can be up to 25 seconds depending of the provider… Not easy to deal with such differences…

Anyway, Paying is cheating :slight_smile: . I’ll keep as my prefered datasource.

I bet you could use the Twitter Streaming API and look for “{country} scores!” or “{country} goal” or “x-y #{country}{country}” or something like that?

I’m not sure how people tweet about the world cup, but I bet it’s possible :wink:

I suppose that is a very good idea, but I never used that API and I am not very confident with that stuff… I’ll try that solution as soon as I have a little time to learn how to use the Twitter API.

Thank for your advice!

Here’s the Twitter class - note, it requires you to setup some stuff up on the Twitter side…

Thank you, it seems to be easy to use!