Skip to content

Instantly share code, notes, and snippets.

@rsmudge
Created September 18, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsmudge/49fb0a6a76a312cdd95666256265a64f to your computer and use it in GitHub Desktop.
Save rsmudge/49fb0a6a76a312cdd95666256265a64f to your computer and use it in GitHub Desktop.
Fire a beacon_revisited event when we get a checkin event that occurs some window of time (e.g., 60s here) after the last checkin event. Keep in mind checkin is only fired on task acknowledgement. If you set the window to 8 hours and don't interact with the Beacon for 8 hours--you'll fire revisited.
global('%checkins');
on beacon_checkin {
local('$last');
if ($1 in %checkins) {
$last = %checkins[$1];
# has it been 1m since the last task acknowledgement?
if (($3 - $last) > 60000) {
fire_event("beacon_revisited", $1);
}
}
# store last checkin
%checkins[$1] = $3;
}
on beacon_revisited {
println("Beacon $1 is here!");
}
@Und3rf10w
Copy link

Could this be extended in some way to create working hours for a beacon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment