Andrew BerryAdam O' CeallaighJack DuffSpivey
Published

Slack Away Button with Wia Dot One and Button Module

In this tutorial, we will be going over how to make a button module toggle your presence on Slack from auto to away.

IntermediateFull instructions provided19 minutes2,211
Slack Away Button with Wia Dot One and Button Module

Things used in this project

Hardware components

Wia Dot One
Wia Dot One
×1
Micro USB 16340 Lithium Battery Shield Mobile Power Holder Adapter For Arduino
×1
Wia Button Module
Wia Button Module
×1
Wia Micro USB Cable
Wia Micro USB Cable
×1

Software apps and online services

Wia
Wia

Story

Read more

Custom parts and enclosures

Button Module with Dot One Case Main

This is the top portion of the case for the Button Module on top of the Dot One. This will protect the two from drops. Be sure to clean up the edges of the case to make sure that when you put the Dot One in it you are not going to hurt the Dot One.

Button Module with Dot One Case Lid

This is the lid to the main portion of the case. It can be tough to get this lid on because the plastic of the printer can expand at the edges and make the fitment tough. It can be helpful to sand down the edges of the main case to fit the lid on the bottom.

Code

Slack Button Toggle Preference Code Project

C/C++
This is the portion of code which initiates creates events for the flows.
/* The following instructions and comments are based on the assumption that you are framiliar with the 
syntax of C++ anda few funtioins and tools that are commonly used in C++ and classes used with Wia.*/

//These are libraries stored by Wia which are necessary for Wia products
#include <WiFi.h>
#include <Wia.h>

const int button = 17; // This is the pinout for the button module
int status = 0; // This is the status that is toggled through

Wia wiaClient = Wia(); /// This is specific to Wia and necessary for Wia to function

void setup() {
  WiFi.begin(); // this starts the connection 
  delay(2500); // delay is necessary for the WIFI to work properly
  pinMode(button, INPUT_PULLDOWN); // this sets up the pin for the button
}

void loop() {
  while (digitalRead(button) == HIGH) //this keeps looping through while the button is pressed
  {
    if (status == 0) { /* when the status was on awa and the button is pressedy toggle to auto and switch status to 1*/
      wiaClient.createEvent("toggle-auto"); /* this is the event which initiates the flow to toggle the slack presence with an HTTP request (refer to flows code)*/
      status = 1; // status 1 represents auto
      while (digitalRead(button) == HIGH) // this loop ensures that one click toggles once
      {
        delay(10); // keep delaying for 10ms until the button is released
      }
    }
    else if (status == 1) /* when the status was on auto and the button is pressed toggle to away and switch status to 0*/
    {
      wiaClient.createEvent("toggle-away"); /* this is the event which initiates the flow to toggle the slack presence with an HTTP request (refer to flows code)*/
      status = 0; // status 0 represents away
      while (digitalRead(button) == HIGH)
      {
        delay(10); // keep delaying for 10ms until the button is released
      }
    }
  }
}

Flow Run Function Code

JavaScript
This is the code that the Run Function in the flow uses to select which the HTTP request to make based on what event has come in from the other code block
var event = input.body.name;
if (event == "toggle-away" ) {
	output.body = "slack.com/api/users.setPresence?token=xoxp-000000000000-000000000000-000000000000-000000000000000000000000&presence=away&pretty=1";
	/* The link above is the link you copited from the Slack API (without the https://) test although you need to make sure that at the end of the HTTP request it says "presence= away" because this will make the presence set to away*/
} else {
	output.body = "slack.com/api/users.setPresence?token=xoxp-000000000000-000000000000-000000000000-000000000000000000000000&presence=away&pretty=1";";
	/* The link above is the link you copited from the Slack API test (without the https://) although you need to make sure that at the end of the HTTP request it says "presence= auto" because this will make the presence set to auto*/
}

Credits

Andrew Berry

Andrew Berry

25 projects • 11 followers
Adam O' Ceallaigh

Adam O' Ceallaigh

20 projects • 8 followers
Jack Duff

Jack Duff

32 projects • 8 followers
Man of the people. Champion of the downtrodden. Marketing magic @ Wia. Becoming a maker by learning, building, and exploring
Spivey

Spivey

82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup

Comments