Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Hans ScharlerRobert Mawrey
Published © MIT

ThingSpeak + Particle Photon using Webhooks

Learn how to connect the Particle Photon to ThingSpeak using webhooks and the ThingSpeak REST API.

BeginnerFull instructions provided1 hour11,139
ThingSpeak + Particle Photon using Webhooks

Things used in this project

Story

Read more

Schematics

Particle devices connected to the Internet

Code

thingSpeakWrite Webhook

JavaScript
This is a JSON formatted file for sending data to ThingSpeak from Particle using webhooks
{
    "event": "thingSpeakWrite_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}

MATLAB Visualization Code

R
Use this MATLAB code you visualize data from a ThingSpeak channel.
readChannelID = 93156;
fieldID1 = 1;
readAPIKey = 'MCI6XM81ZFOY8UCE';

%% Read Data %%
[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 10, 'ReadKey', readAPIKey);

%% Visualize Data %%
thingSpeakPlot(time, data);

Particle Code for Sending Data to the ThingSpeak Webhook

Arduino
This code sends data to ThingSpeak from Particle devices
#define publish_delay 16000
unsigned int lastPublish = 0;

void setup() {

}

void loop() {
    unsigned long now = millis();

    if ((now - lastPublish) < publish_delay) {
        return;
    }

    int value = analogRead(A0);
    Particle.publish("thingSpeakWrite_A0", "{ \"1\": \"" + String(value) + "\", \"k\": \"XXXXXXXXXXXXXXXX\" }", 60, PRIVATE);

    lastPublish = now;
}

Credits

Hans Scharler
15 projects • 87 followers
IoT Engineer, Maker - I have a toaster that has been tweeting since 2008.
Robert Mawrey
2 projects • 31 followers
Founder and CEO of Sentient Things, Inc. Former CEO of IoT startup ioBridge.com, the creators of ThingSpeak.com.

Comments