Device provision
Device provisioning is a crucial process that connects your hardware to the Sensora Cloud.
- Purchase Compatible Hardware: We suggest using hardware that Sensora fully supports. Our platform works best when used with compatible hardware. However, you can use your preferred hardware by making it compatible with Sensora library. Learn more
- Connect Hardware: Once you have the compatible hardware, connect it to your PC or laptop using a suitable cable. This physical connection is necessary for transferring data between your computer and the IoT device. This is required only for the first time.
Setup environment
Choosing the right environment is key for easy and efficient work on your IoT project. You can use either PlatformIO or Arduino IDE. PlatformIO is great for bigger projects with more features, while Arduino IDE is simpler and perfect for beginners.
PlatformIO
We suggest using PlatformIO for IoT development. You can install it in your favourite editor. How to install.
- Create new project "PlatformIO Home > New Project"
- Update
platformio.ini
file and add Sensora library as a dependency.
[env:myenv]
lib_deps =
https://github.com/sensora-io/sensora-library#dev
- Build the project and PlatformIO will automatically install dependencies.
Arduino IDE
- Arduino IDE: To install Sensora library into your Arduino IDE you can use the Library Manager (available from IDE version 1.6.2). Open the IDE and click to the "Sketch" menu and then Include Library > Manage Libraries. Read more
Device Properties
Before uploading the firmware, you need to define properties for your device. This is how you tell Sensora what your device can do, and it’s the foundation for interacting with your device through the Sensora platform. Learn more.
To get started quickly, replace the contents of your main.ino
file with the following code. This code will simulate room temperature and humidity.
An example that simulates temperature and humidity sensor in ESP32/ESP8266 board
#include <Arduino.h>
#include <EspWifi.h>
Property temperatureProperty("temperature");
Property humidityProperty("humidity");
unsigned long lastRead = 0;
int roomTemperature = 20;
int roomHumidity = 40;
void setup() {
Serial.begin(115200);
temperatureProperty.setDataType(DataType::Integer).setAccessMode(AccessMode::Read);
humidityProperty.setDataType(DataType::Integer).setAccessMode(AccessMode::Read);
Sensora.setup();
}
void loop() {
Sensora.loop();
if (millis() - lastRead > 15000) {
// simulate a value between 0 and 15 degrees
roomTemperature = random(0, 15);
temperatureProperty.setValue(roomTemperature);
// simulate a value between 40 and 70 percent
roomHumidity = random(40, 70);
humidityProperty.setValue(roomHumidity);
lastRead = millis();
}
}
Configure device
We provide two different methods for device provisioning, and this guide will walk you through both processes. Choose the one that best fits your technical proficiency and project requirements.
Web Serial Chrome v89+
This method leverages the Sensora Web Platform, is designed to be user-friendly and straightforward, even for beginners.
Chrome v89+ Required
This feature works only in Chrome v89+. You can check if your browser supports the feature here.
- Go to Devices Page and select the device that you just created.
- Click Configure and a modal will appear.
- Select the correct serial port from the dialog.
- Provide Device ID and Device Token and click Send.
- Depending on your choice when selecting the device template, you'll need to upload specific network configuration details:
- WiFi -
SSID
andpassword
- Ethernet -
MAC
address - GSM -
APN
,username
andpassword
- WiFi -
HTTP API not stable
The second method of provisioning involves using HTTP API. This is a more hands-on approach, providing more control but requiring familiarity with sending HTTP requests.
- Connect to the Hotspot: Use your laptop or PC to connect to the device-created hotspot. The AP name format is
Sensora-IoT
. - Send HTTP Request: After establishing a connection, the next step is sending an HTTP request to the device. Here are your options for this step:
curl -X POST http://192.168.4.1/config \
-H "Content-Type: application/json" \
-d '{
"deviceId": "device id value",
"deviceToken": "device token value",
"wifi": {
"ssid": "ssid value",
"password": "password value"
}
}'
TIP 💡
The device will automatically restart if connection with Sensora Cloud is successful. This completes the process of provisioning a new device. Provision HTTP API