Reply
<a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> Alf
Posts: 280
Registered: ‎09-06-2012

Threading Christmas - Thunderboard Sense on Steroids

[ Edited ]

This project is an upgrade of my previous project so not too much code will be included here. What I wanted to do was to take the Thunderboard Sense and create wireless Christmas tree lights. Luckily enough we have some silicone balls around here that fits a Thunderboard Sense and a double-A battery holder which is perfect for the purpose of creating electronic Christmas baubles. You can see the boards, the battery holders and the silicone balls in this workshop picture, taken on Christmas Eve:

Thread - Workshop

 

And here's a couple more workshop pictures:

Thread - Christmas lights

My dad installing the wires for holding the baubles on the tree (obligatory white shirt on Christmas Eve).

 

Thread - W

Several units getting finished soldering.

 

Thread - Workshop

Installing the electronics in the silicon cases.

 

Thread - Christmas tree lights

All the baubles ready for the tree.

 

Thread - Christmas tree lights

Getting help with putting them up.

 

Thread - Christmas tree lights

And the last two baubles. Of course they need to go on the exact same branch.

 

The program have been updated slightly, the clients now poll at a one second interval instead of 10 which is done with this line of code:

#define REPORT_PERIOD_MS (1 * MILLISECOND_TICKS_PER_SECOND)

 

The server was also ported to a Thunderboard Sense so I can have a more sexy remote. It is now also possible to turn the lights off by pressing both buttons simultaneously, so the new halButtonIsr looks like this:

void halButtonIsr(uint8_t button, uint8_t state)
{
  // button: BUTTON0 BUTTON1
  // state:  BUTTTON_RELEASED BUTTON_PRESSED
  if(button == BUTTON0)
    buttonsPressed = (buttonsPressed & ~0x1) | (state << 0x0);
  else if(button == BUTTON1)
    buttonsPressed = (buttonsPressed & ~0x2) | (state << 0x1);

  if(buttonsPressed == 0x3)
  {
	colorOff   = 0x1;
	colorStep  = 0;
	colorFixed = 0x1;
	colorStepped = 0;
  }
  else if((button == BUTTON0) && (state == BUTTON_PRESSED))
  {
	  colorOff   = 0;
	  colorStep  = 0;
	  colorFixed = 0x1;
  	  incrementColorIndex();
  }
  else if((button == BUTTON1) && (state == BUTTON_PRESSED))
  {
	colorOff   = 0;
	colorStep++;
	colorFixed = 0;
	colorStepped = 0;
  }

  //Setting server led
  if(!colorOff)
  {
    BOARD_rgbledEnable( true, 0xf );
    BOARD_rgbledSetColor(colorTableSine[colorIndex][0],
    					 colorTableSine[colorIndex][1],
    					 colorTableSine[colorIndex][2]);
    ledOn = 0x1;
  }
  else
  {
	BOARD_rgbledEnable( true, 0xf );
	BOARD_rgbledSetColor(0x80,
	   					 0x80,
	   					 0x80);
	ledOn = 0x1;
  }
  colorHold = 0;
}

 

You can also see that the LED's of the server is lit up according to the new color. They are turned off again in the handler for GET-requests:

void clientGetHandler(const EmberCoapMessage *request)
{
  // Requests from clients are sent as CoAP GET requests to the "client/get"
  // URI.

  EmberCoapCode responseCode;

  if (state != ADVERTISE) {
    responseCode = EMBER_COAP_CODE_503_SERVICE_UNAVAILABLE;
  } else {
	if (!colorFixed)
	  incrementColorIndex();
	else if (colorHold <= 5)
	  colorHold++;

	// Disabling server LED after a while
    if (ledOn && colorHold > 5)
	{
	  BOARD_rgbledEnable( false, 0xf );
	  ledOn = 0x0;
	}

	coapmessage[0] = colorOff ? 0x0 : colorTableSine[colorIndex][0];
	coapmessage[1] = colorOff ? 0x0 : colorTableSine[colorIndex][1];
	coapmessage[2] = colorOff ? 0x0 : colorTableSine[colorIndex][2];

	emberAfCorePrint("Sending %ld %ld %ld to client at ", coapmessage[0], coapmessage[1], coapmessage[2]);
    emberAfCoreDebugExec(emberAfPrintIpv6Address(&request->remoteAddress));
    emberAfCorePrintln("");
    responseCode = EMBER_COAP_CODE_205_CONTENT;
  }

  if (emberCoapIsSuccessResponse(responseCode)
      || request->localAddress.bytes[0] != 0xFF) { // not multicast
    emberCoapRespond(responseCode, coapmessage, 3); // Payload
  }
}

And that's it! Here's a video demonstrating the new features on our Christmas tree:

My views are my own and do not necessarily represent the views of Silicon Labs