Skip to content

Instantly share code, notes, and snippets.

@virgilvox
Last active November 5, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virgilvox/2bc07819d9b3e4f321b2 to your computer and use it in GitHub Desktop.
Save virgilvox/2bc07819d9b3e4f321b2 to your computer and use it in GitHub Desktop.

##Send Command to Photon from Octoblu

The Particle has an awesome API that lets you expose functions within the firmare to the API.

You can use the following Octoblu Photon API template and the example code to turn a relay on and off via Octoblu!

https://app.octoblu.com/bluprints/import/bc3b126e-fd7b-41cd-b74c-f187c092b892

int relay = D3; // use D7 to control the onboard LED


void setup() {
  pinMode(relay, OUTPUT);

  Spark.function("relay", relay); 
}

void loop() {
  
}

// The function exposed in the spark API

int relay(String command){
    
    if(command == "on"){
        digitalWrite(relay, HIGH);
    }else if(command == "off"){
        digitalWrite(relay, LOW);
    }
    
}


Send Messages TO Octoblu from the Photon

You can register webhooks as events with the Particle Spark API using the Particle CLI.

To get the Particle CLI set up go here.

If you create a JSON file called hook.json with this..

{
    "event": "some_event_name",
    "url": "https://triggers.octoblu.com/flows/yourTriggerWebHook",
    "requestType": "POST",
    "json": {
        "data": "{{SPARK_EVENT_VALUE}}"
    },
    "mydevices": true
}

Then in the terminal type this ..

particle webhook create hook.json

Add this in your Particle Photon firmware...

Spark.publish("some_event_name", String("hello world!"));

You can now send data to a trigger in Octoblu whenever you please!

This enables you to create complex electronics projects with the added benefit of simple two-way communication between Octoblu and your Photon. Add this to existing code and now your boring old IoT-less project has access to all the things!

For general codeless IO programming try The Tentacle which lets you configure pins remotely. Think of it like the tinker app but for Octoblu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment