ESPRESSIF ESP32
Introduction
ESP32 is a series of low-cost, low-power system-on-chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. There are multiple modules based on this microcontroller that include different kinds of antennas, pinouts and memory extensions. It is the successor to the ESP8266 microcontroller and is designed to be one of the most relevant IoT impulsors during the next years and there is a great diversity of variants that exploit its capacities together with other peripherals, integrating LoRa communication, audio amplifiers, LCD screens, etc.

Install On Arduino IDE
This device can be programmed directly from the Arduino IDE by including the ESP32 core libraries with the Arduino Boards Manager. For this step, include this first: https://dl.espressif.com/dl/package_esp32_index.json into Additional Board Manager URLs
field in the Arduino preferences.
Next, go to the Boards manager to install the ESP32 package. Search for the esp32
and install the package esp32 by Espressif Systems
After this process, this board should be selectable on the Arduino IDE, allowing for the creation of IoT projects with Thinger.io.
ESP32 WiFi
This example will allow connecting a device to the cloud platform in a few lines via the WiFi interface. The arduino_secrets.h
file just needs to be modified with the relevant information.
#define THINGER_SERIAL_DEBUG
#include <ThingerESP32.h>
#include "arduino_secrets.h"
ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
// open serial for debugging
Serial.begin(115200);
pinMode(16, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["GPIO_16"] << digitalPin(16);
// resource output example (i.e. reading a sensor value)
thing["millis"] >> outputValue(millis());
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}
ESP32 Ethernet
// It may be required to define this according to a specific board
// Example RMII LAN8720 (Olimex, etc.)
#ifndef ETH_PHY_TYPE
#define ETH_PHY_TYPE ETH_PHY_LAN8720
#define ETH_PHY_ADDR 0
#define ETH_PHY_MDC 23
#define ETH_PHY_MDIO 18
#define ETH_PHY_POWER -1
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#endif
// enable debug output over serial
#define THINGER_SERIAL_DEBUG
// disable certificate validation
// #define THINGER_INSECURE_SSL
// define private server instance
// #define THINGER_SERVER "acme.aws.thinger.io"
#include <ThingerESP32Eth.h>
#include <ThingerESP32OTA.h>
#include "arduino_secrets.h"
// initialize thinger instance
ThingerESP32Eth thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
// Initialize ESP32OTA OTA
// use Thinger.io VSCode Studio extension + Platformio to upgrade the device remotely
ThingerESP32OTA ota(thing);
void setup() {
// enable serial for debugging
Serial.begin(115200);
// example of fixed IP address (DHCP is used by default)
//thing.set_address("192.168.1.55", "192.168.1.1", "255.255.255.0", "8.8.8.8", "8.8.4.4");
// set desired hostname
thing.set_hostname("ESP32Eth");
// resource output example (i.e. reading a sensor value)
thing["eth"] >> [](pson& out){
out["hostname"] = ETH.getHostname();
out["mac"] = ETH.macAddress();
out["ip"] = ETH.localIP().toString();
out["link"] = ETH.linkSpeed();
};
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}
ESP32 WiFi WebConfig
It is possible to configure all parameters required for connection via a web Interface (captive portal). The device will create an access point where the user can connect to establish required information, like username, device identifier, credentials, and access point to connect.
#define THINGER_SERIAL_DEBUG
// Requires WifiManager from Library Manager or https://github.com/tzapu/WiFiManager
#include <ThingerESP32WebConfig.h>
ThingerESP32WebConfig thing;
void setup() {
// open serial for debugging
Serial.begin(115200);
pinMode(27, OUTPUT);
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["relay"] << digitalPin(27);
// resource output example (i.e. reading a sensor value)
thing["millis"] >> outputValue(millis());
}
void loop() {
thing.handle();
}
Once this sketch is loaded on the device, it is possible to follow the next steps to connect it to the platform:
Connect to the "Thinger-Device" WiFi with a computer or phone, using "thinger.io" as the WiFi password.
Wait for the configuration window, or navigate to http://192.168.4.1 if it does not appear.
Configure the WiFi network to which the ESP32 will connect, and input the Thinger.io device credentials.
The device should now be connected to the platform.
The WebConfig interface includes different methods to control the captive portal:
clean_credentials: It cleans all credentials from the device (WiFi/user parameters). This way, the next time the device is booted will create the captive portal again to request the WiFi configuration. It can be executed after a long press on a button.
set_user: Initializes the default user for connecting the device to the platform (if set, this parameter is not requested from the user in the captive portal).
set_device: Initializes the default device for connecting the device to the platform (if set, this parameter is not requested from the user in the captive portal).
set_password: Initializes the default device password for connecting the device to the platform (if set, this parameter is not requested from the user in the captive portal).
add_setup_parameter: Add additional parameters to be requested in the captive portal, for example, any other configuration required for the execution: sampling intervals, meta-data, thresholds, etc.
set_on_config_callback: Set a callback to receive configuration provided by the user in the captive portal, i.e., user, device, password, or any additional parameter configured.
set_on_wifi_config: Set a callback to receive the result of the WiFi configuration. If the connection did not succeed, it can be used to clean credentials, so, the captive portal runs again.
set_on_captive_portal_run: Set a callback to receive the WiFiManager instance before the captive portal is shown. It can be used to add any other customization over the WebConfig interface.
ESP32 WiFi SmartConfig
Coming soon
Last updated
Was this helpful?