Skip to content

Software Instructions

Angus Gratton edited this page Jan 17, 2017 · 9 revisions

Software Setup

The IoTuz uses the ESP32 at its core, and hence the dev environment for the IoTuz is the standard ESP-IDF dev environment/framework. The dev framework is a complete cross-compiling environment which includes the necessary pieces to not only develop software for the ESP32, but to push it to the device as well.

ESP32 Developer Docs & Resources

IoTuz Resources

Setup Steps

Step 1: Install Development Framework

Instructions for installing the '''ESP-IDF''' dev framework are at https://github.com/espressif/esp-idf#setting-up-esp-idf

Updating framework

Before the Open Hardware MiniConf, we recommended that you complete steps 1-3 of the specific setup guides for your OS. If you already did this, unfortunately the toolchain (C compiler & related programs) was updated this week so you'll need to redownload this from the steps you followed before (the download link has been updated.)

Step 2: USB Serial Drivers

The on-board USB Serial chip for the IoTuz is the Silabs CP2102. Note that the serial device may not show up in /dev until you apply power to the board by installing the power switch.

For OS X and Windows, you'll need drivers to communicate with the board. You can download drivers from http://www.silabs.com/products/mcu/pages/usbtouartbridgevcpdrivers.aspx if required.

For Linux, if you have a recent (3.x or later) kernel then these drivers are usually included. If you roll your own kernel or are using a really stripped down system, you may need to build them from source.

Step 3: Get iotuz-esp32-firmware software project

The iotuz-esp32-firmware repository is on github:

https://github.com/CCHS-Melbourne/iotuz-esp32-firmware

Recursively clone the repository

git clone --recursive https://github.com/CCHS-Melbourne/iotuz-esp32-firmware

The clone --recursive in the command is important because iotuz-esp32-firmware contains "git submodules" for various dependencies, including esp-idf itself (in the esp-idf directory) and some Arduino libraries for peripherals, etc. If you miss out on a recursive clone, you'll get a lot of build errors but you can fix this with:

git submodule update --init --recursive

You may also need to run the above command to update the submodules after running git pull, git checkout, etc.

Step 4: Configure The Project

make menuconfig

This command will run a text menu configuration interface. Configure the following items:

  • "WiFi Configuration" -> enter the SSID & Password for the 2.4GHz conference network (the main network is 5GHz and doesn't work with ESP32).
  • "Serial Flasher Configuration" -> "Serial Port" - set the serial port name (/dev/ttyXXX or COMx where the ESP32 serial port enumerates.
  • "Serial Flasher Configuration" -> "Serial Port" - set the default baud rate for faster flashing. 921600bps should work fine.
  • (Windows users only) "Serial Flasher Configuration" -> "Before Flashing" -> "Reset with ESP32R0 Workaround". (This is workaround for a serial driver bug when flashing from Windows PCs).

Use "esc" to exit menus and the configuration interface.

Step 5: Compile & Flash The Project

make -j3 flash

(You can replace -j3 with a different count, for the number of parallel compilation steps to run at once.)

make flash will build and then flash the project to the ESP32 serial port.

Step 6: Watch Serial Output

make monitor

This opens "miniterm.py" in order to watch the serial output from the IoTuz board.

To exit miniterm.py, type Ctrl-].

Use the "reset" button to restart the ESP32 and watch output from the beginning. (Linux resets automatically when you run monitor, other OSes do not.)

If you get an error about --raw, you need to update pyserial by doing something like pip install --upgrade pyserial

Step 7: Check Everything is working as expected

There's a big wall of information coming from the ESP32, look for some important bits of output hiding in there:

[MQTT INFO] Resolve dns for domain: test.mosquitto.org
[MQTT INFO] Connecting to server 253.210.16.128:1883,23303
[MQTT ERROR] Connect failed

These errors are fine early on, the MQTT "task" tries to connect to the MQTT server (test.mosquitto.org, this can be changed in the menuconfig) even before the WiFi is ready...

I (896) wifi: Setting WiFi configuration SSID meshthing...

This line should show the same SSID you set in the menuconfig step.

I (2606) wifi: connected with meshthing, channel 7

This line, a little later, indicates the ESP32 has successfully connected to the WiFi network.

I (12206) event: ip: 192.168.1.3, mask: 255.255.255.0, gw: 192.168.1.1

This line indicates the newly connected ESP32 has picked up an IP via DHCP, and can now connect to the network.

[MQTT INFO] Connected!
[MQTT INFO] Connected to server test.mosquitto.org:1883

Now the ESP32 is connected to WiFi, it can establish a TCP connection to the MQTT server!

I (23596) iotuz: sensor temperature(0) reading 28.84
I (23596) mqttservice: Publishing to esp32-031b2/sensor/temperature...

Lines like this indicate that a new sensor reading has been taken, and that values are published via MQTT. The ID of the particular ESP32 is part of the MQTT topic ID, in this example it is esp32-031b2.

Step 7: Watch for MQTT data

You can need the "mosquitto" command line tools to subscribe to MQTT data and watch IoTuZ publishing information. Most distros also have these tools in a package (usually called mosquitto).

mosquitto_sub -v -h test.mosquitto.org -t 'esp32-031b2/#'

This will start a mosquitto subscribe process to print all MQTT topics starting with the esp32 ID (esp32-031b2). Note the /# on the end, the # acts as a wildcard.

Step 8: You're done!

Things to try:

  • If you want to try Arduino on the IoTuZ board, some steps are below under Using Arduino IDE. This is a great option if you are new to embedded development.
  • Browse the iotuz-esp32-firmware code! This code uses a mixture of esp32-idf and Arduino (Mark's talk will explain this).
  • If you're feeling particularly confident, take a look at the open issues on github.

Using Arduino IDE

There are install instructions for getting the ESP32 running in the Arduino IDE at https://github.com/espressif/arduino-esp32#installation-instructions

The Open Hardware Miniconf 2017 won't be using the ESP32 Arduino environment, however it's still quite usable, especially for basic stuff and testing. Most functions in the ESP-IDF are exposed and available in ESP Arduino shortly after they appear in ESP-IDF.

IoTuz Test Code (Arduino)

As part of the main IoTuz repo, there is some Test code for confirming that hardware on the IoTuz is working as expected.

This hardware is in the form of Arduino "sketches" so you will need the Arduino IDE installed, rather than the ESP-IDF.