This section refers to the following sample application(s):
04-voting
The 04-voting Sample Application
The voting sample demonstrates using the precise timing information available from a SmartMesh network to solve a problem - here recording and timing votes. Each note monitors 4 GPIO inputs (the "buttons") and sends a message when one is pressed. Pressing a button locks out the other buttons for a brief period.
All messages in a SmartMesh network are timestamped when they are handed to the network layer on a mote - this allows the manager to compute packet latency. A corresponding Voting python application available in the SmartMesh SDK displays a histogram of how all the motes in the network voted, who were the fastest respondents (by MAC address) per category and overall.
Implementation Details
The voting application consists of the following tasks:
- The
buttonTask
waits for the mote to have joined, then enables notifications from the 4 GPIOs. When a notification is received, it populates a global variablebuttonMask
and notifiessendTask
by posting thesendNow
semaphore. A mutual exclusion semaphore is used to arbitrate concurrent access to global variables. A global variablebusyVoting
indicates whether thesendTask
is busy sending; while it is, thebuttonTask
keeps running, but a button press will not notifysendTask
. - The
sendTask
waits for thesendNow
semaphore to be posted by thebuttonTask
. When it is, it sends the contents of the globalbuttonMask
variable to the SmartMesh IP Manager, and delays for 10 seconds. Before delaying it posts theblinkNow
semaphore to release thevotingLEDTask
task. After delaying, it clears thebusyVoting
global variables. - The
votingLEDTask
waits forblinkNow
to be posted. When it is, it blinks the blue LED at a 50% duty cycle until thebusyVoting
global variable is reset. The blinking is too fast to be seen by the human eye, but lowers the overall power consumption when the LED is on. - The
statusLEDsTask
periodically gets the status of the mote. It blinks a single green LED during the join process, and both green LEDs when it is operational. This task is not synchronized to the other tasks.