voting

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 mote 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 variable buttonMask and notifies sendTask by posting the sendNow semaphore. A mutual exclusion semaphore is used to arbitrate concurrent access to global variables. A global variable busyVoting indicates whether the sendTask is busy sending; while it is, the buttonTask keeps running, but a button press will not notify sendTask.
  • The sendTask waits for the sendNow semaphore to be posted by the buttonTask. When it is, it sends the contents of the global buttonMask variable to the SmartMesh IP Manager, and delays for 10 seconds. Before delaying it posts the blinkNow semaphore to release the votingLEDTask task. After delaying, it clears the busyVoting global variables.
  • The votingLEDTask waits for blinkNow to be posted. When it is, it blinks the blue LED at a 50% duty cycle until the busyVoting 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.