/******************************************************************* Sets a custom status on your slack account. It will toggle between two every 30 seconds You will need a bearer token, see readme for more details Parts: ESP32 D1 Mini style Dev board* - http://s.click.aliexpress.com/e/C6ds4my * * = Affiliate If you find what I do useful and would like to support me, please consider becoming a sponsor on Github https://github.com/sponsors/witnessmenow/ Written by Brian Lough YouTube: https://www.youtube.com/brianlough Tindie: https://www.tindie.com/stores/brianlough/ Twitter: https://twitter.com/witnessmenow *******************************************************************/ // ---------------------------- // Standard Libraries // ---------------------------- #include #include // ---------------------------- // Additional Libraries - each one of these will need to be installed. // ---------------------------- #include "ArduinoSlack.h" // Library for connecting to the Slack API // Install from Github // https://github.com/witnessmenow/arduino-slack-api #include // Library used for parsing Json from the API responses // Search for "Arduino Json" in the Arduino Library manager // https://github.com/bblanchon/ArduinoJson #include "credentials.h" // copy credentials.h.sample to credentials.h and edit // so it contains your passwords and tokens. //------- Replace the following! ------ //char ssid[] = "SSID"; // your network SSID (name) //char password[] = "password"; // your network password char ssid[] = WIFI_SSID; // your network SSID (name) char password[] = WIFI_PASSWORD; // your network password //#define SLACK_ACCESS_TOKEN "AAAAAAAAAABBBBBBBBBBBCCCCCCCCCCCDDDDDDDDDDD" //------- ---------------------- ------ // including a "slack_server_cert" variable // header is included as part of the ArduinoSlack libary #include "ArduinoSlackCert.h" WiFiClientSecure client; ArduinoSlack slack(client, SLACK_ACCESS_TOKEN); unsigned long delayBetweenRequests = 120000; // Time between requests unsigned long requestDueTime; //time when request due bool firstStatus = true; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); Serial.println("Wifi credentials:"); Serial.println(ssid); Serial.println(password); Serial.print("Connecting to wifi."); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); client.setCACert(slack_server_cert); // If you want to enable some extra debugging // uncomment the "#define SLACK_ENABLE_DEBUG" in ArduinoSlack.h } void displayProfile(SlackProfile profile) { if (!profile.error) { Serial.println("--------- Profile ---------"); Serial.print("Display Name: "); Serial.println(profile.displayName); Serial.print("Status Text: "); Serial.println(profile.statusText); Serial.print("Status Emoji: "); Serial.println(profile.statusEmoji); Serial.print("Status Expiration: "); Serial.println(profile.statusExpiration); Serial.println("------------------------"); } else { Serial.println("error getting profile"); } } void loop() { if (millis() > requestDueTime) { SlackProfile profile; SlackMessage message; if (firstStatus) { profile = slack.setCustomStatus("First status", ":apple:"); message = slack.postMessage("equant-test", "This is a test message... :apple2:"); } else { profile = slack.setCustomStatus("And now the second status", ":apple2:"); message = slack.postMessage("equant-test", "This is a different message... :cactus:"); // There is an optional third parameter which takes a Unix timestamp for // when this custom status expires: // slack.setCustomStatus("I am the second status", ":v:", 1532627506); } firstStatus = !firstStatus; displayProfile(profile); requestDueTime = millis() + delayBetweenRequests; } }