AskSensors IoT Platform Documentation

Control Hardware with AskSensors over HTTP/HTTPS

Control AskSensors Actuators Summary:

1-Actuator HTTP/HTTPS Read API

2-Control ESP32 Actuators over HTTP/HTTPS

2-Control ESP32 Actuators over HTTP/HTTPS

After the big success of the ESP8266, the ESP32 is a new chip from Espressif that combines WiFi and Bluetooth wireless capabilities with two CPU cores and a decent hardware peripheral set.

This section shows how to send commands to your ESP32 device with AskSensors.

AskSensors : Control ESP32

a) Prerequisites :

b) Required Material :
The hardwares needed in this section are:
  • Computer running Arduino software.
  • ESP32 development board.
  • USB micro cable to connect ESP32 development board to the computer.

c) Install ESP32 in Arduino IDE:
If not done yet, follow the instructions below to install the ESP32 board in your Arduino IDE:
  • Install the latest version of Arduino IDE software (1.8.7 or higher).
  • Open the preferences window from the Arduino IDE : File> Preferences.
  • Go to the "Additional Board Manager URLs" field, Enter the following URL:
    If you already have the ESP8266 boards URL, separate the URLs with a comma as show below:,
    Now, open boards manager (Tools > Board > Boards Manager), search for ESP32 and click the install button for the "ESP32 by Espressif Systems".

d) Required Software :
  • Install the Official JSON Library for Arduino: Navigate to the Sketch > Include Library > Manage Libraries.
    Wait for Library Manager to download libraries index and updated list of installed libraries.
    Filter your search by typing Arduino_JSON. There should be a couple entries. Look for Arduino_JSON by Arduino. Click on that entry, and then select Install.
  • Download this demo from the AskSensors Github page.
The code includes the libraries for both connecting to a WiFi network, perform HTTP GET requests to read commands from AskSensors and parse it from Json format. You need to fill the following:
  • Your WIFI SSID and password.
  • The Actuator device Api Key Out given by AskSensors.
  • The time interval between two successive reads.
  •   const char* wifi_ssid = ".........."; // SSID
      const char* wifi_password = ".........."; // WIFI
      const char* apiKeyOut = ".........."; // Actuator API KEY OUT
      const unsigned int readInterval = 10000; // read interval (in ms)

e) Run the code :
  • Connect your ESP32 board to the computer via serial/USB and upload the code using the Arduino IDE. The code will be running automatically after Reset.
  • Return to the AskSensors web appplication, open your actuator devices workspace and send commands to the actuator module that your ESP32 reads data from.
  • Open a serial terminal in Arduino IDE. You can cross-check the ESP32 terminal reading with the values being sent from the AskSensors Application.

f) Source Code :
A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.

Control ESP32 actuators with AskSensors
* Description: This sketch reads commands from AskSensors cloud ( using an ESP32 Wifi module.
* Author:, 2020
* github:
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>

WiFiMulti WiFiMulti;
HTTPClient ask;
// TODO: user config
const char* ssid = ".................."; //Wifi SSID
const char* password = ".................."; //Wifi Password
const char* apiKeyOut = ".................."; // Actuator API KEY OUT
const unsigned int readInterval = 10000; // read interval (in ms)

// ASKSENSORS API host config
const char* host = ""; // API host name
const int httpPort = 80; // port
void setup(){

  // open serial
  Serial.println("********** Program Start : ESP32 reads commands from AskSensors.");
  Serial.println("Wait for WiFi... ");

  // connecting to the WiFi network
  WiFiMulti.addAP(ssid, password);
  while ( != WL_CONNECTED) {
   // connected
  Serial.println("WiFi connected");
  Serial.println("IP address: ");

void loop(){

   // Use WiFiClient class to create TCP connections
   WiFiClient client;

  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
  }else {

  // Create a URL to read data from module 1
  String url = "";
  url += apiKeyOut;
  url += "?module=module1";
  url += "&maxResults=1";

  Serial.print("********** requesting URL: ");
  // send data
  ask.begin(url); //Specify the URL

   //Check for the returning code
  int httpCode = ask.GET();

  if (httpCode > 0) {

     String payload = ask.getString();
    String command_value;

    Serial.print("********** Json parsing ");
    JSONVar askObject = JSON.parse(payload);

    // JSON.typeof(jsonVar) can be used to get the type of the var
    if (JSON.typeof(askObject[0]) == "undefined") {
    Serial.println("Parsing input failed!");

   Serial.println("********** Read Actuator Command from AskSensors ");

  // read command value
   if (askObject[0].hasOwnProperty("value")) {
     command_value = (const char*)askObject[0]["value"];
    Serial.print("Command value: ");
  // read date
   if (askObject[0].hasOwnProperty("date")) {
     Serial.print("Updated date: ");

     Serial.println((const char*)askObject[0]["date"]);

   } else {
    Serial.println("Error on HTTP request");

  ask.end(); //End
  Serial.println("********** End ");


   client.stop(); // stop client
  delay(readInterval); // delay