Setup Your Environment
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.
To communicate with the Wemos board from your Arduino IDE, you must manually install ESP32 board definitions on your Arduino IDE, you can find the official tutorial for the different operating systems here
Terminal tip
For Mac: To run python get.py in Mac, you need to open the Terminal app.
Type in cd then drag and drop the entire file containing the get.py file in it and drop it into your terminal - hit enter then type python get.py and hit enter.
For Linux, right click on the folder and select in Open in Terminal.
Folder Structure for Windows
Folder Structure for Mac
Selecting the board and port
The board has an On/Off Switch so make sure it's on before continuing any further
Once you've got it connected to your computer, get the name of your device's port using one of the following steps:
FTDI Drivers
FTDI Drivers allow for communication between your operating system and your deviceover USB. Installing them may require Administrative privilages.
Linux and Mac OS X
Windows
Install the required libraries
Install each of the following libraries by searching for their name in the search bar within the modal. A button will appear in the bottom right of the box that will allow you to install the library.
Library Manager
Create the Sketch
Arduino IDE new Sketch
#include <ArduinoJson.h>
#include <WiFi.h>
#include <ArduinoHttpClient.h>
#include <Arduino.h>
const char* ssid = "your-ssid"; // Your WiFi ssid
const char* password = "your-password"; //Your Wifi password
// Get this sccret key from the wia dashboard. It should start with `d_sk`
const char* device_secret_key = "your-device-secret-key";
// Wia API parameters
char server[] = "api.wia.io";
char path[] = "/v1/events";
int port = 80;
WiFiClient client;
int status = WL_IDLE_STATUS;
StaticJsonBuffer<200> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject& root = jsonBuffer.createObject();
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.
// wait 5 seconds for connection:
delay(5000);
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("connecting...");
}
// Loop function runs continuously
void loop() {
root["name"] = "temperature";
root["data"] = 21.5;
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
sendToWia(root);
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(3000); // Wait for 3 seconds to post again
}
// Adds the correct headers for HTTP and sends Data to Wia
void sendToWia(JsonObject& data) {
size_t len = data.measureLength();
size_t size = len + 1;
char json[size];
httpClient.beginRequest();
httpClient.post(path);
httpClient.sendHeader("Content-Type", "application/json");
httpClient.sendHeader("Content-Length", data.measureLength());
httpClient.sendHeader("Authorization", "Bearer " + String(device_secret_key));
httpClient.beginBody();
data.printTo(httpClient);
Serial.print("Posting ");
data.printTo(Serial);
Serial.println(" to Wia");
httpClient.endRequest();
}
Replace the following values of the following variables names (Place the correct value between the quotation marks right of the variable names in the code):
Selecting Board and Port in the Arduino IDE
Check that Upload Speed is set to 115200
Upload the code
Viewing your output
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
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