Kosmos Documentation

Connect Your ESP32 to Kosmos

What will I learn?

In this tutorial you’ll learn how to connect your Espressif ESP32 programmable microcontroller to the Kosmos Industrial IoT platform.
Kosmos is an IoT platform that sends sensor data to the cloud through a gateway device (typically a Raspberry Pi). Data from a range of sensor devices like the ESP32 can be sent to the Kosmos cloud via the Kosmos gateway.
testing alt text
What’s more, since Kosmos is a no-code IoT solution, no computer programming skills are necessary to quickly and easily connect your ESP32 to Kosmos. We automatically generate all the code you need to program both your ESP32 and your Kosmos gateway (the Raspberry Pi).

What You'll Need

Before you get started, make sure you have the following to hand:
An ESP32 development board (like the ESP32-WROVER-B)
A micro USB cable to power your ESP32
A power supply for your Raspberry Pi
An SD card (8GB or more)
An SD card reader/writer
A USB thumb drive

Get Started With Kosmos & ESP32

1
If you haven’t already, sign up for a free Kosmos trial account.
2
Log into your Kosmos account and navigate to the Kosmos application builder.
3
Select Espressif ESP32 as your Kosmos edge device.
4
On the next screen, select ESP32.
5
Give your ESP32 a name and then move on to setting up a GPIO to read data from.
6
While Kosmos supports a range of sensors, we’ll keep things simple for this tutorial and just read voltage from GPIO 35. Here’s what you need to do:
a
Select GPIO 35
b
Select Analog Sensor
c
Select the Other category
d
Select Generic Voltage
e
Give your GPIO a name e.g., volts
f
Click Done to close out of GPIO 35 and then click Confirm to move on
7
Now that you’ve added your ESP32 to Kosmos, click “Confirm” to move on to the next step.
8
Set your ESP32 to send data to the Kosmos gateway (Raspberry Pi) every 30 seconds by using the “Custom” field as shown below. Make sure to also set the gateway to send data to Kosmos every 30 seconds by using the custom field.
9
Next, give your ESP32 Kosmos application a name and then move on to downloading your Kosmos files - you'll be given an ESP32 embedded application and the Kosmos gateway for your Raspberry Pi.
10
Download the two files that have been automatically generated for you.
11
When you move on from here you’ll be asked to enter your credit card information if you haven’t already done so. Go ahead and do that - you won’t be automatically charged for anything.

Flash Kosmos Onto Your ESP32

1
We’re going to use the official ESP32 development framework (ESP-IDF) to flash the auto-generated Kosmos application onto your ESP32. Make sure you have the ESP-IDF installed and that you can run their "Hello World" application before continuing.
2
Next, locate the two Kosmos files that you downloaded earlier:
There’s the Kosmos gateway image (the .xz file on the right in the image below) that you load onto the Raspberry Pi via SD card
And the Kosmos application files (a .zip file) that contains a gateway configuration file and your ESP32 firmware application
3
Unzip the temboo_kosmos_files.zip and navigate into the folder named after the Kosmos application you created earlier. In the screenshot below that’s the “Kosmos_ESP32” folder.
4
Now, navigate into the main directory and open the “app_main.c” file. Find the WIFI_SSID and WIFI_PWD constants, and then enter the details of a Wifi network that your ESP32 can use to connect to the Kosmos gateway (the Raspberry Pi) that we’ll set up later. Save your “app_main.c” file and exit.
5
Next, use your terminal to locate to the Kosmos application files you've just been updating. Navigate to the top level of the directory that contains the Kosmos application code that you want to flash onto your ESP32 (in this tutorial that’s the “Kosmos_ESP32” folder) and then run this command:
idf.py build
6
Once your ESP32 has built, you can flash the application onto your ESP32 by running the command below (make sure your ESP32 is connected to your computer first!). Also, make sure to substitute PORT in the command below with the USB port your ESP32 is connected to. Here’s Espressif’s official guide to discovering the USB port your ESP32 is connected to. You can find this on Mac OS X by plugging in your ESP32, running the “ls /dev/cu.*” command, and looking for the “/dev/cu.SLAB_USBtoUART” port.
idf.py -p PORT flash

Set Up Your Kosmos Gateway

Now that your ESP32 is up and running, you’re ready to set up your Raspberry Pi as a Kosmos gateway so that it can start collecting data from your ESP32 and send it to your Kosmos dashboard.
1
Locate the Kosmos files that you downloaded earlier - we’re now going to turn our attention to the .xz file.
2
If you don’t have it already, download Etcher so that you can flash your SD card with the Kosmos gateway image (.xz file).
3
Insert your SD card into your SD card reader/writer (and connect the reader/writer to your computer if you’re using an external reader/writer), then use Etcher to flash the Kosmos gateway disk image onto your SD card.
4
Next, inside the other file you downloaded (the temboo_kosmos_files.zip file), open the kosmos_gateway_config.ini file in your favorite text editor and enter the details of the wifi network you configured in your ESP32 application earlier.
a
Find the SSID field and enter the name of your wifi network
b
Beneath that, enter your wifi password in the password field
5
Save the kosmos_gateway_config.ini file you just edited, and then transfer it to your USB thumb drive - now you’re ready to get your Kosmos gateway online.
6
Take these steps to finish setting up your Raspberry Pi as a Kosmos gateway:
a
Insert the SD card into your Raspberry Pi
b
Plug your Raspberry Pi power adapter into an outlet and then into the Pi
c
Insert the USB thumb drive into your Pi
7
Now that your Raspberry Pi is set up to act as a Kosmos gateway, you can visit your Kosmos dashboard, check that the Pi gateway has come online, and that your ESP32 is sending data to Kosmos.
8
Now that your ESP32 is sending GPIO data to Kosmos, let’s set up an email alert based on the voltage data in the graph.
a
From the voltage graph page, click on the settings icon in the top right of the screen
b
Click on Let’s create a rule
c
Set the voltage level at which you want your alert to trigger
d
In the Delivery Frequency section, select Also send email as it happens
e
Enter your email address, give your rule a name, and save the rule
9
Alter the voltage on the selected GPIO to trigger the alert and then check your inbox. Kosmos rules can be used to generate email and SMS alerts for sensor data values, battery status, device connectivity status, and more.

What's Next?

Now that you’ve learned how to send data from your ESP32 to Kosmos, the natural next step is to integrate some sensors and build a real IoT application. You can learn more about the sensors and actuators that Kosmos supports for the ESP32 by hovering on the various GPIOs when setting up an ESP32 during Kosmos application creation.
You can also learn more about the sensor and actuator hardware that Kosmos supports in the documentation section.

Questions?

We're always happy to help with questions about building IoT applications with Kosmos.
Check out our documentation for more tutorials, email support for help, or connect with our product outreach team with any questions you might have.