The Wia Developer Hub

Welcome to the Wia developer hub. You'll find comprehensive guides and documentation to help you start working with Wia as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

ESP32

How to setup an Espressif ESP32 and publish an event to Wia

Components

  • ESP-WROOM-32
  • Micro USB to USB cable

Setup Your Environment

Arduino IDE

  • Install the Arduino IDE (Integrated development environment). You can download it for Mac OS X, Windows and Linux here.

Detailed instructions can be found below:

Installing the board definitions

  • Start the Arduino application and open Preferences
  • Enter https://dl.espressif.com/dl/package_esp32_index.json into the Additional Board Manager URLs field. If you need more than one, they can be separated with commas
  • Go to Tools > Board > Boards Manager
  • Search for esp32. When found, select it and click Install
Install the ESP32 Arduino package

Install the ESP32 Arduino package

Selecting the board and port

Once you've got it connected to your computer, get the name of your device's port using one of the following steps:

Linux and Mac OS X

  • Open a terminal window and run the command ls /dev/tty*
  • Look for a device with the name that begins with /dev/tty e.g. /dev/tty.usbmodemPy343431 on MAC or /dev/ttyUSB0/dev/ttyACM0 on Linux

USB to UART Drivers Required

On Mac OS X you may require USB to UART bridge drivers. View our tutorial here which shows you how to install them.

Windows

  • Download and install the USB to UART bridge drivers from here.
  • Open the Windows start menu and search for 'Device Manager'
  • The COM port for the ESP32 device will be listed as 'USB Serial Device' or something similar
    • Keep note of the COM port (e.g. COM4)
  • Select the ESP32 Dev Module board type by going to Tools > Board
  • Select the port that matches from above

Check that Upload Speed is set to 115200

Create the Sketch

  • Click on File > New to create a new Sketch.
  • Copy and paste the publish event example code below in place of the empty setup() and loop() functions
#include <ArduinoJson.h>
#include <WiFi.h>
#include <ArduinoHttpClient.h>
#include <Arduino.h>


const char* ssid     = ""; // Your WiFi ssid
const char* password = ""; //Your Wifi password

WiFiClient client;
int status = WL_IDLE_STATUS;

// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "";

// Wia API parameters
char server[] = "api.wia.io";
char path[] = "/v1/events";
int port = 80;

StaticJsonDocument<200> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject root = jsonBuffer.to<JsonObject>(); 


void setup() {

  // initialize serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, password);
    // wait 10 seconds for connection:
    delay(10000);
  }
  
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  JsonObject& root = jsonBuffer.createObject();
  root["name"] = "hello-wia";
  root["data"] = "";
Serial.println("connecting...");
  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {
    Serial.println("connected");

    postToWia(root);

  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    client.stop();

    delay(10000);
    //Do nothing forever
    for (;;)
      ;
  }
}

void postToWia(JsonObject& data) {
  String dataStr = ""; 
  serializeJson(data, dataStr);
  httpClient.beginRequest();
  httpClient.post(path);
  httpClient.sendHeader("Content-Type", "application/json");
  httpClient.sendHeader("Content-Length", dataStr.length());
  httpClient.sendHeader("Authorization", "Bearer " + String(device_secret_key));
  httpClient.beginBody();
  httpClient.print(dataStr);  
  httpClient.endRequest();

}

Replace the following values of the following variables:

  • ssid - with your WiFi network name.
  • password - with your WiFi network password.
  • device_secret_key with your device secret key from the Wia Dashboard (the one that begins with d_sk).
  • Go toSketch > Upload` to send it to your ESP-WROOM-32.

You may need to push the En (Reset) button to run the code on the board

Viewing you output

  • Click on button on the right hand of the screen to view your Serial monitor (Denoted in image below)
  • Make sure the baud rate is set to 1152000 (Shown in red rectangle in image below)
Publish an Event to Wia

Publish an Event to Wia

If the Serial monitor doesn't show you connecting to a WiFi, You may need to push the RST(Reset) button to run the code on the board.

Now go to your device in the Wia dashboard and you should see the data appearing in the debugger.

Wia Device Debugger

Wia Device Debugger