Global Twitter Mood Light

Hi - im pretty new to programming but have completed a few projects that turn data into physical actions. My latest project i really want to build is a RGB lamp that connects to this API in particular this and displays a colour based on the returned emotion eg:


I would like the photon to take the highest value and return a colour so IF “love” is the highest number return ‘RED’ or if its “anger” = “FLASH ORANGE”

I created a similar project using @jvanier advice on i ried using this tutorial but cant really get my head around using it on this API

Any pointers greatly appreciated

Thanks Al

Take a look at webhooks, since that might simplify things a bit :slight_smile: which part are you struggling with and what have you tried so far?

Ive managed to parse the API in using @jvanier tutorial from here but i dont know how to map the values to colors

module['exports'] = function WeFeel (hook) {
  var got = require('got');
  .then(function (response) {
  })**_**This is the section im struggling with!_**
  .catch(function (error) {
hook.res.end("Error fetching data: " + error);

These are the values from the API im trying to send to the photon - the photon would only display rank number ‘1’

This is the photon code

int setWeFeel(String value) {
    if(value == "pulse_green") {
        return 0;
    } else if(value == "pulse_blue") {
        return 0;
    } else if(value == "pulse_red") {
        return 0;
    } else if(value == "flash_green") {
        return 0;
    } else if(value == "flash_orange") {
        return 0;
    } else if(value == "flash_red") {
        return 0;
    return 1;

void setup() {
    Particle.function("we-feel", setWeFeel);

void loop() {

Any help i would be stoked! :slight_smile:

I’d agree with @Moors7, why not use Particle webhooks and do the whole lot on the device.
The webhook would only relay the data to your device and then you’ve got all the logic in one place.

1 Like

Thanks @ScruffR and @Moors7 cool ive spent a good few hours trying to get this working with webhooks

I created the webhook to read the data

My photon is running the below but im really stuck with how to pull the highest value out and display a colour on the onboard LED

void loop() {
  // Get the emotion
  String data = String(10);
  // Trigger the integration
  Particle.publish("get_emotion", data, PRIVATE);
  // Wait 60 seconds

    void setup() {
  // Subscribe to the integration response event
  Particle.subscribe("hook-response/get_emotion", myHandler, MY_DEVICES);

void myHandler(const char *event, const char *data) {
  // Handle the integration response
void myHandler(const char *event, const char *data) {
  // Handle the integration response

you get data from the event, so you need to process that into usable data.

One way would be to add a Response Template (mustache template) to your Integration/WebHook and get just deal with the numbers(if that is all you are really interested in).

Another approach would to be to use the JSON parser library (a couple available if you search this site) to extract the values from the JSON object you received in data.


I tried using mustache but soon realised i need the ‘emotion’ as well as the value. This is what the webhook is returning

Requesting Emotion
47hook-response/get_emotion/0, data: {"love":2078091,"other":4099889,"sadness":4038821,"anger":1114953,"joy":15067171,"*":23838244,"surprise":1468112,"fear":840305}

Unfortunately my knowledge of programming is very limited so im unsure how to start ‘sorting’ the numbers and emotions so i can display the highest value as a LED colour. Ive spent hours searching and trying to learn more and came across this brilliant tutorial i have tried my best to configure it to the API im working with and its given me a great understanding of how to extract specific data using webhooks & mustache.

This is my modified version of the tutorial above

You could get the full response and either parse that JSON string yourself or use this lib

To extract the moods. Then convert the values using atoi() and then just find the max.