Blog

Send an Event to Wia from a Particle Photon

Hi All, You can now connect your Particle device to Wia. Here's a quick tutorial showing you how to interact with our REST API.

What's needed?

  • A Particle device. For this tutorial we're using a Photon, you can find one on Amazon here
  • Particle IDE. Download it here
  • A Wia account. Click here to signup

To get started, load up the IDE and create a new project. We've called ours wia-particle-client. Copy the files from our GitHub to your new project. There should be at least 4 files in your folder

  • application.cpp
  • application.h
  • HttpClient.cpp
  • HttpClient.h

The application.cpp file is where will be working (see the whole file below). In it, change DEVICE_SECRET_KEY in the headers array to the secret key of your Wia device.

Now, in the Particle IDE, select your device then click Flash your-device via the cloud. This will send the code straight to your device. To monitor it, load up a terminal and run the command particle serial monitor.

That's it! You've now send an Event to Wia. You can view the whole GitHub project at https://github.com/wiaio/wia-particle-client

Happy building! CL

#include "application.h"
#include "HttpClient.h"

/**
* Declaring the variables.
*/
HttpClient http;

http_header_t headers[] = {
    { "Content-Type", "application/json" },
    { "Accept" , "application/json" },
    { "Authorization" , "Bearer DEVICE_SECRET_KEY"},
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};

http_request_t request;
http_response_t response;

void setup() {
    Serial.begin(9600);
}

void loop() {
    // Request parameters
    request.hostname = "api.wia.io";
    request.port = 80;
    request.path = "/v1/events";

    // Body parameters in JSON format
    request.body = "{\"name\":\"temperature\", \"data\":\"21.5\"}";

    // POST request
    http.post(request, response, headers);

    // Response
    Serial.print("Application>\tResponse status: ");
    Serial.println(response.status);

    Serial.print("Application>\tHTTP Response Body: ");
    Serial.println(response.body);

    delay(2000);
}

Credit goes to Nils Mattisson for the HTTPClient code. That project can be viewed here.

Ready to get started?
Talk to our sales team or setup an account.