This is an old revision of the document!
Download and install VS Code from here
Open terminal and check if you have Python 3 installed.
$ python3 --version
If you don't have Python 3 installed then run the following command.
$ sudo apt install python3
Wether you already had Python installed or not, you need to run the following command.
$ sudo apt install python3-distutils
After installing make sure the extension is enabled.
After that, the PlatformIO icon should show up on the left sidebar as well as an Home icon that redirects you to PlatformIO home.
On VS Code, click on the PlartfomIO Home icon. Click on + New Project to start a new project.
Give your project a name, select the board WeMos D1 MINI ESP32 (WEMOS) and the framework as Arduino
After finishing the setup the project should be accessible from the explorer tab.
The platformio.ini file is the PlatformIO Configuration File for your project. It shows the platform, board, and framework for your project. You can also add other configurations like libraries to be included, upload options, changing the Serial Monitor baud rate and other configurations.
Add the following line to include the ITTIoT Library and another parameters:
upload_speed = 921600 upload_port = COM3 monitor_speed = 115200 lib_deps = ITTIoT
The src folder is your working folder. Under the src folder, there’s a main.cpp file. That’s where you write your code. Click on that file. The structure of an Arduino program should open with the setup() and loop() functions.
Paste the following example code to main.cpp
#include <Arduino.h> #include <ittiot.h> void iot_received(String topic, String msg){ Serial.print("MSG FROM USER callback, topic: "); Serial.print(topic); Serial.print(" payload: "); Serial.println(msg); } void iot_connected(){ Serial.println("MQTT connected callback"); iot.subscribe("mytopic"); iot.log("Hello from ESP!"); } void setup() { Serial.begin(9600); iot.setConfig("wname", ""); iot.setConfig("wpass", ""); iot.setConfig("msrv", ""); iot.setConfig("mport", ""); iot.setConfig("muser", ""); iot.setConfig("mpass", ""); iot.printConfig(); // print json config to serial iot.setBootPin(5); iot.setup(); } void loop() { iot.handle(); }
Make sure to replace the connection information with yours like so:
... iot.setConfig("wname", "myWiFi"); iot.setConfig("wpass", "myPassword"); ...
To test and upload your code first save your code and then click on the Build icon on the bottom of the editor to verify that your code can be ran. After a successful build press the Upload icon. Alternatively, you can got to the PIO Project Tasks menu and select build or upload from there..
Continue to the next page to verify that everything is working as expected
If the code compiled and uploaded successfully there a serial monitor should have automatically opened and you should see live data from the controller like so:
If the serial monitor does not open automatically click the button below:
This means that the code was successfully uploaded and the board has connected to the MQTT server.
Install the MQTTBox chrome app to publish and subscribe messages to the MQTT server.
Configure the connection with your details and publish a message to the topic that your board is listening to (mytopic in the example)
The board should receive the message and print it out in the serial monitor: