Note: If your board has a micro USB port, you can probably skip this step.
Connect your board to laptop/desktop via a USB to TTL cable/adapter. Here's a pinout showing the different connections.
- ESP8266 <-> ESP-01 USB TTL
- GND <-> GND
- TX <-> RX
- VCC <-> 3.3V(+)
- CH_PD <-> 3.3V(+)
- GPIO0 <-> GND (Only while flashing the board)
Note: You may need to install FTDI drivers to make your device appear. To do so, go here, then download and install the drivers for your operating system.
- Install the Arduino IDE. You can download it for Mac OS X, Windows and Linux here
- Start the Arduino application and open
http://arduino.esp8266.com/stable/package_esp8266com_index.jsoninto the Additional Board Manager URLs. If you need more than one, they can be separated with commas
- Go to
Tools > Board > Boards Manager
- Search for
esp8266. When found, click
Select your ESP8266 board type by going to
Tools > Board, then choosing your type. For this example I am using
NodeMCU 1.0 (ESP-12E Module).
You can get the name of your device's port using one of the following steps:
- Open a terminal window and run the command
- Look for a device with the name that begins with
/dev/tty.usbmodemPy343431on MAC or
- Download and install the FTDI 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)Note: Check that
Upload Speedis set to
115200and the correct Port is selected.
In the Arduino IDE, Go to
Sketch > Include Libraries > Manage 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.
- Click on
File > Newto create a new Sketch
- Copy and paste the example code below labeled
PublishEventViaMQTT.ino. You can also view it on GitHub here. This code publishes an event to your Device every 10 seconds
Replace the following values of the following variables:
your-ssid- with your WiFi network name
your-password- with your WiFi network password
your-device-idwith your Device id from the Wia Dashboard (the one that begins with
your-device_secret_keywith your Device secret key from the Wia Dashboard (the one that begins with
Verify/Compilethe code. If it runs correctly then go to
Sketch > Uploadto send it to your ESP8266
Go to the Wia dashboard to view the data coming through to your device.
Now that you've learned how to publish an event via MQTT, learn how to control your board via MQTT too!