Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Blynk-Particle-Example

A minimal example showing how to get sensor data from a Particle device into Blynk, without any Blynk library on the device.

How it works

Particle device --Particle.publish(JSON)--> Particle Cloud --Webhook--> Blynk HTTP Data Converter

Every 30 seconds the device publishes a small JSON payload (dummy temperature/humidity readings) as a Particle Cloud event. A Particle webhook integration forwards that event to a Blynk HTTP Data Converter, which maps the JSON fields onto datastreams on your Blynk device.

Example payload:

{ "temperature": 24.3, "humidity": 55.1, "uptime": 120 }

Setup

  1. Blynk: create a Datastream and an HTTP Data Converter on your Blynk template/device, and copy the converter's URL.

  2. Update BLYNK_TEMPLATE_NAME in src/Blynk-Particle-Example.cpp to match your Blynk template - slugified (lowercase, hyphenated, e.g. hvac-monitor for a template named "HVAC Monitor"). This is used to build the Particle event name, so it's easy to trace an event in the Particle console back to the Blynk template it feeds.

    Avoid names starting with particle or spark - those prefixes are reserved for Particle's own system events (spark/status, particle/device/...), and events using them get silently dropped: Particle.publish() still returns true on the device, but the event never reaches your event stream in the Particle console.

  3. Particle: in the Particle console, go to Integrations > New Integration > Webhook and configure:

    • Name: your Blynk Template name (e.g. blynk-particle-example)
    • Event Name: <BLYNK_TEMPLATE_NAME>/data (e.g. blynk-particle-example/data)
    • URL: the Blynk HTTP Data Converter URL from step 1
    • Leave everything else at its default. The key thing is the event name must match what the firmware is using in the Particle.publish().
  4. Flash src/Blynk-Particle-Example.cpp to your device (any Wi-Fi or cellular Particle device works - update particle.targetPlatform in .vscode/settings.json if you're not using an Argon).

  5. Watch the values arrive in Blynk.

Blynk Data Convertor

This is the complete code for the Blynk HTTP Data Convertor

function initialize(context) {
  const { handler } = context;
  handler.useAuthMetaField("ParticleDeviceId")
}

function handleRequest(context) {
  const { request, server } = context;
  const { uri, headers, body, isSecure } = request;

  // Parse incoming JSON payload
  const bodyJson = JSON.parse(new TextDecoder().decode(body));

  // Authenticate the device
  const device = server.authenticateDevice(bodyJson.coreid);

  // Set all the datastreams from the data
  const data = JSON.parse(bodyJson.data);
  for (const [key, value] of Object.entries(data)) {
    device.setDataStreamValue(key, value);
  }  

  return { status: 200, body: 'Datastreams updated' };
}

Using real sensors

Replace the random() calls in publishSensorData() with real sensor readings, and add any extra fields to the JSON payload and to the webhook mapping in Blynk.

About

Minimal example: publish sensor data from a Particle device to Blynk via a webhook and HTTP Data Converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages