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    

Wemos D1 mini

How to setup a Wemos D1 mini ESP8266 and publish an event to Wia

Wemos D1 mini ESP8266

Wemos D1 mini ESP8266

Setup Your Environment

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

Detailed instructions can be found below:

New to the Arduino IDE?

If you are completely unfamiliar with the Arduino IDE, watch this video here to give you a better understanding of how it works.

  • Start the Arduino application and open Preferences
  • Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into the Additional Board Manager URLs. If you need more than one, they can be separated with commas
Install the ESP8266 Arduino package

Install the ESP8266 Arduino package

  • Go to Tools > Board > Boards Manager
  • Search for esp8266. When found, click Install
  • Select your ESP8266 board type by going to Tools > Board, then choosing your type. For this example, you can use Wemos D1 mini Pro
  • Check that Upload Speed is set to 115200
  • Select the correct port for the board

When selecting a port

For the ESP 8266, the port names tend to have unusual names, e.g:
    On Mac OS: /dev/tty.usb.modem8232 or /dev/cu.SLAB_USB_toUART
    On Windows: Com4 or Com3
    On Linux /dev/ttyUSB0 or /dev/ttyACM0

USB to UART Drivers Required

If your port is not showing up, you need to install USB to UART Bridge VCP drivers. To do so, go here, then download and install the drivers for your operating system.
After installing the drivers, restart the Arduino IDE.

Note for Mac users

You may need to install the driver twice for it to work, as the first install will just remove the existing driver.

Charge-only USB cables

Another cause of the port not showing up could be the USB cable - make sure that the cable you're using is not a charge-only cable, and that it isn't faulty.

Create the Sketch

  • Click on File > New to create a new Sketch
  • Copy and paste the publish event example code below. You can also view it on GitHub here. In that directly you will see how to publish both Events and Locations
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ArduinoHttpClient.h>

const char* ssid     = "your-ssid";
const char* password = "your-password";

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

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

WiFiClient client;
int status = WL_IDLE_STATUS;
HttpClient httpClient = HttpClient(client, server, port);

StaticJsonDocument<200> jsonBuffer;
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
  }
  WiFi.begin(ssid, password);
  Serial.print("Attempting to connect to SSID: ");
  Serial.print(ssid);
  // attempt to connect to WiFi network:
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    // Connect to WPA/WPA2 network. Change this line if using open or WEP  network:
    // wait 5 seconds for connection:
    delay(5000);
  }
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("Connected");
}

void loop() {
  root["name"] = "hello-wia";
  postToWia(root);
  delay(10000);
}

// Adds the correct headers for HTTP and sends Data to Wia
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 values of the following variables:

  • your-ssid - with your WiFi network name.
  • your-password - with your WiFi network password.
  • your-device-secret-key with your device secret key from the Wia Dashboard (the one that begins with d_sk).
  • Go to Sketch > Upload to send it to your ESP8266.

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

Common errors

If you encounter an error like the one denoted in the image below, check if your board and port are correctly set in the Tools menu

Board or Port Failure

Board or Port Failure