AskSensors IoT Platform Documentation


Connect Hardware to AskSensors over HTTP/HTTPS


As there are many IoT hardware available nowadays, AskSensors is not tied to some specific hardware or platform.
If your device is connected to the internet, you can connect it easily to AskSensors and start building your Internet of Things project in few minutes.
This section will cover how to connect your hardware to the AskSensors IoT platform over HTTP/HTTPS.

Here is a list of how to use instructions provided for some popular platforms. To start using the platform select the development board you want to use:

1-HTTP/HTTPS Write/Read API

2-ESP8266

3-ESP32

4-Arduino Ethernet

5-Arduino WiFi

6-Raspberry Pi

7-Regular PC using Node.js


Note:

It is recommended to install a new version of Arduino IDE from the official Arduino download page for programming Arduino compatible hardware, which is any board you can program with the Arduino IDE (Arduino + Ethernet, Arduino + Wifi, ESP8266, ESP32 , etc).
Please install a version starting form v1.8.7. Ignore this if you already have a modern version.


1-HTTP/HTTPS Write/Read API

HTTP (Hypertext Transfer Protocol) is a request-response based protocol between a client and server. The HTTP can be used to enable communications between IoT devices (clients) and the AskSensors server.
The GET Request is one of the most common HTTP methods used to request data from a specified resource and can be used to write data to or read data from the AskSensors IoT platform.

    a) API to write data to AskSensors:

      The AskSensors users can write data to their sensors in the AskSensors IoT platform using the following structure:

      https://api.asksensors.com/write/apiKeyIn?module1=value1
      or
      https://api.asksensors.com/write/apiKeyIn?module1=value1&module2=value2&module3=value3&module4=value4&module5=value5&module6=value6

      Where,
    • apiKeyIn: is the sensor API KEY IN
    • value1...value6: are the modules values
    • If the HTTP Get Request is performed well, you should Get the number of modules updated successfully.
      Here are the response codes that you should get when writing data to the AskSensors IoT platform over HTTP/HTTPS:
    • 200: Corresponds to an OK HTTP code.
    • 1..6: Number of modules successfully updated.
    • The URL below shows an example to write a value of "100" to the "module1" of the Sensor with "apiKeyIn = BmYlV171NKvTmCOJioDRCnclbZUNvpwY:
      https://api.asksensors.com/write/BmYlV171NKvTmCOJioDRCnclbZUNvpwY?module1=100

      The response is: "1" .

    b) API to read data from AskSensors:

      This API allows user to read data stored in AskSensors cloud server in JSON format using the HTTPS GET Request. Here is the structure:

      https://api.asksensors.com/read/apiKeyOut?module=Module_Number&maxResults=number_of_entiries
      Where,
    • apiKeyOut: is the Sensor API KEY OUT.
    • Module_Number: is the module name (module1, module2...module6).
    • maxResults: is the number of latest entries to read (from 1 to 50).

    If the HTTP Get Request is performed well, you should Get a buffer with the specified number of enrties in JSON format:
    Here are the response codes that you should get when reading data from the AskSensors IoT platform over HTTP/HTTPS:
  • 200: Corresponds to an OK HTTP code.
  • [{"value":"...","date":"..."},{"value":"...","date":"..."}]: The data read buffer in JSON format.
  • The URL below shows an example to read the "latest three entries" stored in the "module1" of the Sensor with "apiKeyOut = eNWxlUQLAmAleOXRULIAL90GVrytXBqr”:
    https://api.asksensors.com/read/eNWxlUQLAmAleOXRULIAL90GVrytXBqr?module=module1&maxResults=3

    The response is: [{"value":"100","date":"2019-04-18 17:27:45.259Z"},{"value":"100","date":"2019-04-18 17:27:43.992Z"},{"value":"100","date":"2019-04-18 17:27:42.593Z"}].

2-ESP8266

The ESP8266 chip from Espressif was the new generation of low-cost WiFi chips after the TI CC3000/CC3200.
This small chip not only integrates the whole WiFi features, but also a powerful programmable MCU.
Depending on the board layout (ESP-01, ESP-03, ESP-07, ESP12, etc) it is attached to a programmable flash, ranging from 512K to 4M. This increases the available user code space, and make possible other cool features like a small file system, or OTA updates.
This devices can be directly programmed from the Arduino IDE. The only requirement is to install the board via the Arduino Boards Manager.

AskSensors : ESP8266

    • Prerequisites
    • Hardware requirements
    • To follow along with this tutorial you will simply need:
      • Computer running Arduino software.
      • ESP8266 Node MCU.
      • USB micro cable to connect the node MCU to the computer.

    • Install ESP8266 in Arduino IDE
    • To install the ESP8266 board in your Arduino IDE, follow the instructions below:
      • Install the latest version of Arduino IDE software (1.8.7 or higher).
      • First of all, open the preferences window from the Arduino IDE : File> Preferences.
      • Go to the "Additional Board Manager URLs" field, Enter the following URL:
        http://arduino.esp8266.com/stable/package_esp8266com_index.json
        If you already have the ESP32 boards URL, separate the URLs with a comma as show below:
        https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
        Now, open boards manager (Tools > Board > Boards Manager), search for ESP8266 and click the install button for the "ESP8266 by Espressif Systems". It takes some few seconds.

    • Software
    • Example sketch and ESP8266 WIFI libraries are available in Github. The provided code is ready to use as is. It connects the ESP8266 to wireless network as HTTP client, and then push data to AskSensors.
      Download the code from github, decompress the zip folder and open the .ino file in Arduino IDE. You need to fill the following:
      • Your WIFI SSID and password.
      • The Api Key In generated before by AskSensors.
      • If needed, the time period between two successive data updates (set to 25 second in this example).
      •   const char* wifi_ssid = ".........."; // SSID
          const char* wifi_password = ".........."; // WIFI
          const char* apiKeyIn = ".........."; // API KEY IN
          const unsigned int writeInterval = 25000; // write interval (in ms)

    • Run the code
      • Connect your ESP8266 to the computer via USB or serial and upload the code from Arduino IDE.
      • Return back to your AskSensors dashboard and head to the sensor that you are sending data to, click on 'Show Graph' and select your chart type to view your sensor data in graph such as Line, Gauge, scatter and Bar.
      • Open a serial terminal. You can cross-check the AskSensors graph readings with the values being printed on your Arduino Terminal.

    • Source Code :

    • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.
      /*
      * AskSensors HTTP Request
      * Description: Connect ESP8266 to AskSensors over HTTP
      * Author: https://asksensors.com, 2018
      * github: https://github.com/asksensors/AskSensors-ESP8266-API
      */ #include <Arduino.h>
      #include <ESP8266WiFi.h>
      #include <ESP8266WiFiMulti.h>
      #include <ESP8266HTTPClient.h>
      // TODO: ESP8266 user config.
      const char* wifi_ssid = "..................."; // SSID
      const char* wifi_password = "..................."; // WIFI
      const char* apiKeyIn = "..................."; // API KEY IN
      const unsigned int writeInterval = 25000; // write interval (in ms)
      // ASKSENSORS API host name
      String host = "http://api.asksensors.com";
      ESP8266WiFiMulti WiFiMulti;
      void setup() {
      Serial.begin(115200);
      Serial.println("*****************************************************");
      Serial.println("********** Program Start : Connect ESP8266 to AskSensors over HTTP");
      Serial.println("Wait for WiFi... ");
      Serial.print("********** connecting to WIFI : ");
      Serial.println(wifi_ssid);
      WiFi.begin(wifi_ssid, wifi_password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("-> WiFi connected");
      Serial.println("-> IP address: ");
      Serial.println(WiFi.localIP());
      }
      void loop() {
      // wait for WiFi connection
      if (WiFi.status() == WL_CONNECTED){
        HTTPClient http;
        Serial.print("[HTTP] begin...\n");
        // Create a URL for updating module 1 and module 2
        String url = "";
        url += host;
        url += "/write/";
        url += apiKeyIn;
        url += "?module1=";
        url += random(10,100);
        url += "&module2=";
        url += random(10,100);
        Serial.print("********** requesting URL: ");
        Serial.println(url);
        http.begin(url); //HTTP
        Serial.println("> Request sent to ASKSENSORS");
        Serial.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();
        // httpCode will be negative on error
        if(httpCode > 0) {
          // HTTP header has been send and Server response header has been handled
          Serial.printf("[HTTP] GET... code: %d\n", httpCode);
          // file found at server
          if(httpCode == HTTP_CODE_OK) {
            String payload = http.getString();
            Serial.println(payload);
          }
        } else {
          Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
        Serial.println("********** End ");
        Serial.println("*****************************************************");
      }
      delay(writeInterval); // wait for writeInterval
      }

    3-ESP32

    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 connect your ESP32 to the AskSensors cloud

    AskSensors : ESP32

      • Prerequisites
      • Hardware requirements
      • To follow along with this tutorial you will simply need:
        • Computer running Arduino software.
        • ESP32 development board.
        • USB micro cable to connect ESP32 development board to the computer.

      • Install ESP32 in Arduino IDE
      • To install the ESP32 board in your Arduino IDE, follow the instructions below:
        • Install the latest version of Arduino IDE software (1.8.7 or higher).
        • First of all, open the preferences window from the Arduino IDE : File> Preferences.
        • Go to the "Additional Board Manager URLs" field, Enter the following URL:
          https://dl.espressif.com/dl/package_esp32_index.json
          If you already have the ESP8266 boards URL, separate the URLs with a comma as show below:
          https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
          Now, open boards manager (Tools > Board > Boards Manager), search for ESP32 and click the install button for the "ESP32 by Espressif Systems". It takes some few seconds.

      • Software
      • Download this demo from the AskSensors Github page.
        The code includes the libraries for both connecting to a WiFi network and to perform the HTTP requests. You need to fill the following:
        • Your WIFI SSID and password.
        • The Api Key In given by AskSensors.
        • The time interval between two successive updates.
        •   const char* wifi_ssid = ".........."; // SSID
            const char* wifi_password = ".........."; // WIFI
            const char* apiKeyIn = ".........."; // API KEY IN
            const unsigned int writeInterval = 25000; // write interval (in ms)

      • Run the code
        • Connect your ESP32 to the computer and upload the code from Arduino IDE.
        • Return back to your sensor page on askSensors, click on 'visualize' and 'Show Graph' to view your sensor data in graph.
        • Open a serial terminal on Arduino IDE. You can cross-check the AskSensors graph readings with the values being printed on your Arduino IDE Terminal.

      • Source Code:

      • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.
        /*
        Connect ESP32 to AskSensors
        * Description: This sketch connects to a website (https://asksensors.com) using an ESP32 Wifi module.
        * Author: https://asksensors.com, 2018
        * github: https://github.com/asksensors
        */
        #include <WiFi.h>
        #include <WiFiMulti.h>
        #include <HTTPClient.h>
        WiFiMulti WiFiMulti;
        HTTPClient ask;
        // TODO: ESP32 user config
        const char* ssid = "............."; //Wifi SSID
        const char* password = "............."; //Wifi Password
        String apiKeyIn = "............."; // API Key
        const unsigned int writeInterval = 25000; // write interval (in ms)
        // ASKSENSORS host config
        const char* host = "http://api.asksensors.com";
        const int httpPort = 80; // port
        void setup(){
          // open serial
          Serial.begin(115200);
          Serial.println("*****************************************************");
          Serial.println("********** Program Start : Connect ESP32 to AskSensors.");
          Serial.println("Wait for WiFi... ");
          // connecting to the WiFi network
          WiFiMulti.addAP(ssid, password);
          while (WiFiMulti.run() != WL_CONNECTED) {
            Serial.print(".");
            delay(500);
          }
          // connected
          Serial.println("WiFi connected");
          Serial.println("IP address: ");
          Serial.println(WiFi.localIP());
        }
        void loop(){
          // Use WiFiClient class to create TCP connections
          WiFiClient client;
          if (!client.connect(host, httpPort)) {
            Serial.println("connection failed");
            return;
          }else {
          // Create a URL for updating module 1 and module2 request
          String url = "https://api.asksensors.com/write/";
          url += apiKeyIn;
          url += "?module1=";
          url += random(10, 100);
          url += "&module2=";
          url += random(10, 100);
          Serial.print("********** requesting URL: ");
          Serial.println(url);

          ask.begin(url); //Specify the URL
          //Check for the returning code
          int httpCode = ask.GET();
          if (httpCode > 0) {
             String payload = ask.getString();
             Serial.println(httpCode);
             Serial.println(payload);
          } else {
           Serial.println("Error on HTTP request");
          }
          ask.end(); //End
          Serial.println("********** End ");
          Serial.println("*****************************************************");
          }
          client.stop(); // stop client
          delay(writeInterval); // delay
        }

      4-Arduino Ethernet

      The Arduino Ethernet Shield connects your Arduino to the internet in mere minutes. Just plug this module onto your Arduino board, connect it to your network with an RJ45 cable, and you are almost done to start controlling your world through the internet.

      AskSensors : Arduino + Ethernet

      • Arduino Ethernet Shield
      • - Features:

        • Requires an Arduino board.
        • Operating voltage 5V, supplied from the Arduino Board.
        • Ethernet Controller: Wiznet Ethernet controller W5100 with internal 16K buffer.
        • The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP.
        • Connection speed: up to 10/100Mb.
        • Connection with Arduino on SPI port: It uses the ICSP header pins and pin 10 as chip select for the SPI connection to the Ethernet controller chip.
        • The latest revision of the Ethernet Shield includes a micro-SD card slot on board, which can be used to store files for serving over the network.
        • The Ethernet Module has a standard RJ45 connection, with an integrated line transformer.
        • The connection to a network is made with a RJ45 Ethernet cable.

        - Software Library:

        • The Ethernet shield relies on the Arduino Ethernet library.
        • The library comes bundled with the Arduino IDE.
        • We will need to change some network settings in the program to correspond to our network.

        - Informational LEDs:

        • PWR: indicates that the board and shield are powered.
        • LINK: indicates the presence of a network link and flashes when the shield transmits or receives data.
        • FULLD: indicates that the network connection is full duplex.
        • 100M: indicates the presence of a 100 Mb/s network connection (as opposed to 10 Mb/s).
        • RX: flashes when the shield receives data.
        • TX: flashes when the shield sends data.
        • COLL: flashes when network collisions are detected.

        • Prerequisites
        • Hardware requirements
        • To follow along with this tutorial you will simply need:
          • Computer running Arduino software.
          • An Arduino board such as the Arduino Uno.
          • An Arduino Ethernet Shield.
          • USB micro cable to connect ESP32 development board to the computer.
          • An Ethernet cable, for connecting to your network router.

        • Software

        • There are hundreds of tutorials about connecting the Arduino to the web through the Ethernet Shields, so I'm not going to explain this part.
          Download this demo from the AskSensors Github page.
          The code uses DHCP and DNS for the server and is supposed to work right away with few changes:
          • If you are using more than one Ethernet shield on a network, make sure that each Ethernet shield on the network must have a unique mac address.
          • Change the IP address in the sketch to match the IP address range of your network.
          • Set the Api Key In of your sensor.
          • Set your dummy data.
          • // MAC
            byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
            // Set the static IP address to use if the DHCP fails to assign
            IPAddress ip(192, 168, 1, 177);
            // ASKSENSORS config.
            const char* apiKeyIn = "......................"; // Change it with your API KEY IN
            // dummy data
            int dumData = 100; // set your data

        • Run the code
          • Plug the Ethernet shield into the Arduino Uno board.
          • Connect the Ethernet shield to your router/network through the Ethernet cable.
          • Connect the Arduino to the computer through the USB cable. Power will be supplied to the two boards via the USB cable.
          • Open your code in Arduino IDE, Select the correct Arduino board and COM port. Then, upload the code to your Arduino board. make sure that the code was uploaded successfully.
          • You can use the reset button on the shield to reset both the the Ethernet Controller and the Arduino board.
          • After reset/power up, open a serial terminal, you should see the Arduino printing the program status: the arduino connects to the network (takes few seconds), then sends the dummy data to the AskSensors over HTTP get requests.
          • After receiving the request of wrting data to the specific Sensor from the client, the server first sends a HTTP response telling the number of modules updated successfully ('1' in our case).

        • Source Code

        • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.
          /*
          Connect Arduino Ethernet to AskSensors
          * Description: This sketch connects to a website (https://asksensors.com) using an Arduino Wiznet Ethernet shield.
          * Author: https://asksensors.com, 2018
          * github: https://github.com/asksensors
          */
          #include <SPI.h>
          #include <Ethernet.h>
          // ETHERNET config.
          // Enter a MAC address for your controller below.
          // Newer Ethernet shields have a MAC address printed on a sticker on the shield
          byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
          // Set the static IP address to use if the DHCP fails to assign
          IPAddress ip(192, 168, 1, 177);
          // ASKSENSORS config.
          char server[] = "api.asksensors.com"; // ASKSENSORS host name
          const int port = 80; // Port: HTTP=80
          const char* apiKeyIn = "5V8APAV9Q0OWEBDOSCYRSKGGEIWC3M8Q"; // API KEY IN (change it with your API KEY IN)
          // dummy data
          int dumData = 100; // set your data
          // Initialize the Ethernet client library
          // with the IP address and port of the server
          // that you want to connect to (port 80 is default for HTTP):
          EthernetClient client;
          void setup() {
          // Open serial communications and wait for port to open:
          Serial.begin(9600);
          while (!Serial) {
            ; // wait for serial port to connect. Needed for native USB port only
          }
          // start the Ethernet connection:
          if (Ethernet.begin(mac) == 0) {
            Serial.println("Failed to configure Ethernet using DHCP");
            // try to congifure using IP address instead of DHCP:
            Ethernet.begin(mac, ip);
          }
          // give the Ethernet shield a second to initialize:
          delay(1000);
          Serial.println("connecting...");
          // if you get a connection, report back via serial:
          if (client.connect(server, port)) {
            Serial.print("connected asksensors.com");
             //Create a URL for the request
            String url = "http://api.asksensors.com/write/";
            url += apiKeyIn;
            url += "?module1=";
            url += dumData;
            Serial.print("********** requesting URL: ");
            Serial.println(url);
            //Make a HTTP request:
             client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + server + "\r\n" +
               "Connection: close\r\n\r\n");
            client.println();
            Serial.println("> Request sent to ASKSENSORS");
          } else {
            // if you didn't get a connection to the server:
            Serial.println("connection failed");
          }
          }
          void loop() {
          // if there are incoming bytes available
          // from the server, read them and print them:
          if (client.available()) {
            char c = client.read();
            Serial.print(c);
          }
          // if the server's disconnected, stop the client:
          if (!client.connected()) {
            Serial.println();
            Serial.println("disconnecting.");
            client.stop();
            // do nothing forevermore:
             while (true);
          }
          }

        5-Arduino WiFi

        In this section we will configure a setup composed from an Arduino and an ESP8266 WiFi module as an IoT Thing.

        AskSensors : Arduino + WiFi

          • Prerequisites
          • Hardware requirements
          • To follow along with this tutorial you will simply need:
            • Computer running Arduino software
            • An Arduino board such as the Arduino Uno.
            • ESP8266 WiFi module. I'm using the ESP-01S
            • USB micro cable to connect ESP32 development board to the computer.
            • Wires and breadboard.

            The connection between Arduino and ESP8266 is as follows:
            • ESP TX to Arduino pin 10
            • ESP RX to Arduino pin 11
            • ESP VCC to Arduino 3V3
            • ESP CH_PD to Arduino 3V3
            • ESP GND to Arduino GND

          • Software

          • Now let’s write the code to send a simple data from the Arduino to the AskSensors cloud through WiFi. The Arduino code communicates with the ESP8266 WiFi module using AT commands. Data will be sent to AskSensors over HTTP connection. A ready to use code is provided in the AskSensors Github page.
            Download the code and set the following variables to your setup (WiFi SSID, password and the 'Api Key In'):
              String ssid = "............."; //Wifi SSID
              String password = "............."; //Wifi Password
              String apiKeyIn = "............."; // API Key

          • Run the code
            • Connect the Arduino to your computer through USB cable.
            • Open Arduino IDE and flash the code.
            • Return back to your sensor page on askSensors, click on 'visualize' and 'Show Graph' to view your sensor data in graph.
            • Open a serial terminal. You should see you Arduino handles AT commands with the ESP8266 which performs the connection to WiFi networks and sending data to the AskSensors cloud over HTTP requests.

          • Source Code

          • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.
            /*
            Connect Arduino WiFi to AskSensors
            * Description: This sketch connects the Arduino to AskSensors IoT Platform (https://asksensors.com) using an ESP8266 WiFi.
            * Author: https://asksensors.com, 2018-2019
            * github: https://github.com/asksensors/AskSensors-Arduino-WiFi
            */
            #include <SoftwareSerial.h>
            // serial config
            #define RX 10
            #define TX 11
            SoftwareSerial AT(RX,TX);
            // TODO: change user config
            String ssid = "............."; //Wifi SSID
            String password = "............."; //Wifi Password
            String apiKeyIn = "............."; // API Key
            String host = "api.asksensors.com"; // API host name
            String port = "80"; // port
            int AT_cmd_time;
            boolean AT_cmd_result = false;
            void setup() {
            Serial.begin(9600);
            // open serial
            Serial.println("*****************************************************");
            Serial.println("********** Program Start : Connect Arduino WiFi to AskSensors");
            AT.begin(115200);
            Serial.println("Initiate AT commands with ESP8266 ");
            sendATcmd("AT",5,"OK");
            sendATcmd("AT+CWMODE=1",5,"OK");
            Serial.print("Connecting to WiFi:");
            Serial.println(ssid);
            sendATcmd("AT+CWJAP=\""+ ssid +"\",\""+ password +"\"",20,"OK");
            }
            void loop() {
            // Create the URL for the request
            String url = "GET /write/";
            url += apiKeyIn;
            url += "?module1=";
            url += random(10, 100);
            Serial.println("*****************************************************");
            Serial.println("********** Open TCP connection ");
            sendATcmd("AT+CIPMUX=1", 10, "OK");
            sendATcmd("AT+CIPSTART=0, \"TCP\",\"" + host +"\"," + port, 20, "OK");
            sendATcmd("AT+CIPSEND=0," + String(url.length() + 4), 10, ">");
            Serial.print("********** requesting URL: ");
            Serial.println(url);
            AT.println(url);
            delay(2000);
            sendATcmd("AT+CIPCLOSE=0", 10, "OK");
            Serial.println("********** Close TCP Connection ");
            Serial.println("*****************************************************");
            delay(20000); // delay
            }
            // sendATcmd
            void sendATcmd(String AT_cmd, int AT_cmd_maxTime, char readReplay[]) {
            Serial.print("AT command:");
            Serial.println(AT_cmd);
            while(AT_cmd_time < (AT_cmd_maxTime)) {
              AT.println(AT_cmd);
              if(AT.find(readReplay)) {
                AT_cmd_result = true;
                break;
              }
              AT_cmd_time++;
            }
            Serial.print("...Result:");
            if(AT_cmd_result == true) {
              Serial.println("DONE");
              AT_cmd_time = 0;
            }
            if(AT_cmd_result == false) {
              Serial.println("FAILED");
              AT_cmd_time = 0;
            }
            AT_cmd_result = false;
            }

          6-Raspberry Pi

          This section explains how to connect your Raspberry Pi to the AskSensors IoT platform using node.js.
          AskSensors : Raspberry Pi

          • Prerequisites
          • Hardware requirements
          • Here is the required materials:
            • Raspberry Pi Model B+ or Model B (you can also use a Raspberry Pi 2 Model B)
            • USB micro cable to power up your Pi.
            • MicroSD card, I recommend a class 10 card that is 16 GB or higher.
            • MicroSD to SD memory card adapter, you will need to use the SD card reader on your laptop/desktop to write to the microSD card.

          • Set Up Your Raspberry Pi

          • Running a basic setup of Raspbian on Raspberry Pi become easy and clearly explained in this Getting Started Guide.
            Here are the main steps:
            • Download NOOBS
            • Extract it on your SD
            • Plug it in and turn on the Raspberry Pi.
            • When prompted, choose to install Raspbian and let it run.
            That's it, Now we have an amazing Raspberry Pi system that can be used for a variety of tasks!

          • Install Node Js

          • Here we go in the Node.js installation, Installing an ARM-version of Node become very easy!

          • Test Node.js

          • To make sure that node.js runs correctly, Type the commands below. It should return the current version of node and npm installed.   node -v
              npm -v
            Make sure it doesn't give any error. If everything is ok, we can move to the next step!

          • Software
          • Download the .js file from github. It requires the installation of the https npm package.
            You will need to set your Api Key In.   var ApiKeyIn = '................'; // Api Key In

          • Run the code
          • Now you are ready to run the final script :
              node https_GET.js

          • Source Code

          • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.
            /*
            * Connect Raspberry Pi to AskSensors
            * Description: This code sends dummy data to askSensors IoT platform over HTTPS GET Request.
            * Author: https://asksensors.com, 2018
            * github: https://github.com/asksensors/AskSensors-Raspberry-Pi
            * Instructables: https://www.instructables.com/id/Connect-Raspberry-Pi-to-Asksensors-IoT-Platform-Us/
            */
            // includes
            var https = require('https');
            const request = require('request');

            // Raspberry Pi User Configuration
            var ApiKeyIn = '...................'; // TODO: fill your sensor Api Key In given by https://asksensors.com
            var writeInterval = 25000; // TODO; adjust your timer interval (in ms)
            // API host name
            var host = 'https://api.asksensors.com';
            // Function declaration: send data
            function send_data(){
              var url = host + '/write/';
               url+= ApiKeyIn;
               url+= '?module1='
               url+= 100*Math.random();// random data in module 1;
               url+= '&module2='
               url+= 100*Math.random();// random data in module 2;
            console.log('Data sent to:' + url);
            request(url, { json: true }, (err, res, body) => {
              if (err) { return console.log(err); }
            });
            }

            send_data();// send first data
            // Send data every writeInterval
            setInterval(send_data, writeInterval); // setInterval

          7-Regular PC using Node.js

          This section explains how to connect send data to the AskSensors IoT platform from regular PC using node.js.

          AskSensors : Node.js

          • Prerequisites

          • Install Node.js and NPM
            • download Node.js . It’s free and available for Windows, MacOs and Linux (in my case I'm using Windows).
            • Run the installer, follow the prompts in the installer. Accept the license agreement, click the NEXT button a bunch of times and accept the default installation settings.
            • NPM is distributed with Node.js, which means that when you download Node.js, you automatically get npm installed on your computer.
            • Restart your computer. You will not be able to run Node.js until you restart your computer!

          • Test the Node.js


          • To Make sure you have Node.js and NPM installed, we will run simple commands to see what version of each is installed and to run a simple test program:
            • Test Node.js: To confirm that you have Node.js installed, type this command in your terminal:
            •   node -v
              This should print a version number.

            • Test NPM: To check if you have NPM installed, you can run this command in your terminal:
            •   npm -v

          • Software


          • Download the .js file from github. It requires the installation of the https npm package.
            You will need to set your Api Key In.   var ApiKeyIn = '................'; // Api Key In

            • Run the code
            • Type this command to run the .js file:
                node https_GET.js

          • Source Code


          • A basic source code is shown below. Please refer to the AskSensors Github page to get the latest version and updates.

            /*
            * AskSensors node.js API
            * Description: This demo shows how to send data to AskSensors IoT platfom over HTTPS GET Requests.
            * Author: https://asksensors.com, 2018
            * github: https://github.com/asksensors/AskSensors-node.js-API
            */
            // includes
            var https = require('https');
            const request = require('request');

            // node.js User Configuration
            var ApiKeyIn = '...................'; // TODO: fill your sensor Api Key In given by https://asksensors.com
            var writeInterval = 25000; // TODO; adjust your timer interval (in ms)
            // API host name
            var host = 'https://api.asksensors.com';
            // Function declaration: send data
            function send_data(){
              var url = host + '/write/';
               url+= ApiKeyIn;
               url+= '?module1='
               url+= 100*Math.random();// random data in module 1;
               url+= '&module2='
               url+= 100*Math.random();// random data in module 2;
            console.log('Data sent to:' + url);
            request(url, { json: true }, (err, res, body) => {
              if (err) { return console.log(err); }
            });
            }

            send_data();// send first data
            // Send data every writeInterval
            setInterval(send_data, writeInterval); // setInterval



          Previous : Create Sensor