Who doesn't love Halloween? The candy. The costumes. The decorations. Traumatizing small children with scary props. 🎃💀
In this project, I'll show you how to remotely trigger a jump-scare skeleton with cellular IoT, giving you the opportunity to be the most hated grown-up on your block!
The Very Scary Skeleton
This jump-scare skeleton lets you to trigger its "jump" action via detected motion or a footpad. Unfortunately the motion-triggering is a little too sensitive, often ruining the opportunity for a real surprise when kids are inspecting what's in the bag.
Take a peek...if you dare!
Ideally we want to activate the skeleton by replacing the footpad action with a relay switch that can be remotely triggered. Therefore, we need a way to send a signal to toggle said relay from any distance.
Since this IoT deployment will be outdoors, a reasonable connectivity option is cellular, specifically the prepaid cellular Notecard from Blues. To minimize cost, we will use a new Notecard feature to set the state of a Notecard AUX pin to toggle the relay switch, removing the need for a host MCU at the skeleton.
In summary we will remotely trigger an AWS Lambda function, the Lambda function will call an API to send an event to the Cellular Notecard attached to the skeleton, and then, SURPRISE!
From cloud to skeleton via low-power cellular.
Later on in the project, I'll show you how to (optionally) add a button, host MCU, and another Notecard to let you trigger the skeleton by literally pressing a button (technically from anywhere in the world).
From host to cloud to skeleton via low-power cellular.
The Cloud
Let's start with what needs doing in the cloud to make this project a reality.
Blues Notehub
Blues Notehub is a thin cloud service that is effectively a secure router between the Notecard and your cloud app (which today will be AWS, but can be any cloud service).
The benefit of this pairing is the Notecard literally knows to how communicate with Notehub as soon as it's powered on. The Notecard is extremely secure as it doesn't have a public IP address and communicates with Notehub through private VPN tunnels.
After setting up a free account and a new project in Notehub, we are going to use a feature of Notehub's API to remotely configure a setting on the Notecard to toggle the relay switch.
But for right now, all we need are the ProjectUID (the unique identifier of the Notehub project) and the DeviceUID (the unique identifier of the Notecard, discoverable by connecting the Notecard to the in-browser terminal at dev.blues.io or after the Notecard connects to your Notehub project).
Find your Notehub project's ProjectUID:
Find your Notecard's DeviceUID in Notehub (available after connecting with a hub.set request - see instructions later on in this tutorial):
AWS Lambda Function
Switching gears into AWS, let's write the Lambda function in Python (because why not):
import requests import timedef lambda_handler(event, context): url = 'https://api.notefile.net/v1/projects/<project-uid>/devices/<device-uid>/environment_variables' timestamp = int(time.time()) payload = '{"environment_variables":{"_aux_gpio_set":",,low,,1000,' + str(timestamp) + ',60"}}' headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'X-SESSION-TOKEN': '<your-auth-token>'} r = requests.put(url, data=payload, headers=headers)
The url
variable is a call to the Notehub API. It includes placeholders for the aforementioned ProjectUID and DeviceUID you should have from Notehub.
The payload
variable sets a specific environment variable on the Notecard. Environment variables are key-value pairs that are shared between Notehub and Notecards.
They can be edited via the Notehub UI or the Notehub API (like we are doing today) and are...
Read more »
Very cool project, thanks for building and documenting it!