Arduino + SIM800 HTTP -> GPRS thermometer

Consider an example that sends temperature and humidity to a warehouse every 5 minutes.

Required materials:

Device adding and setting:

  1. Add a new device under the name of «GPRS thermometer testing» in VizIoT
  2. Configure device settings. Add parameters:
    1. tem key of «Temperature, °C» type;
    2. hum key of «Humidity, %» type.
  3. Copy pass key and access password in «Basic settings» of the device.

Firmware Arduino:

  1. Create a new project in Arduino IDE.
  2. Copy the example below to the created project.
                  #define TINY_GSM_MODEM_SIM800
    
    #include <TinyGsmClient.h>
    #include <ArduinoHttpClient.h>
    #include <Wire.h>
    #include "Adafruit_SHT31.h" //https://github.com/adafruit/Adafruit_SHT31
    #define SerialMon Serial
    
    // Use physical Serial port for Mega, Leonardo, Micro
    #define SerialAT Serial1
    // or software Serial for Uno, Nano
    //#include 
    //SoftwareSerial SerialAT(2, 3); // RX, TX
    
    Adafruit_SHT31 sht31 = Adafruit_SHT31();
    
    // GPRS access point settings
    const char apn[]  = "YourAPN";
    const char user[] = "";
    const char pass[] = "";
    
    //VizIoT Device access key and password (can be found in the device settings)
    String VizIoT_Device_key = "................";
    String VizIoT_Device_pass = "....................";
    
    //Server address and port
    const char server[] = "VizIoT.com";
    const int  port = 48656;
    
    TinyGsm modem(SerialAT);
    TinyGsmClient client(modem);
    HttpClient http(client, server, port);
    
    void setup() {
      // Set baud rate for Serial Monitor
      SerialMon.begin(115200);
      delay(10);
    
      // Set baud rate for Serial GSM module
      SerialAT.begin(115200);
      delay(3000);
    
      SerialMon.println(F("Modem initialization..."));
      modem.restart();
    
      String modemInfo = modem.getModemInfo();
      SerialMon.print(F("Modem: "));
      SerialMon.println(modemInfo);
    
      Serial.println("Sensor search SHT31-D");
      if (! sht31.begin(0x44)) {   // specify 0x45 for alternative i2c sensor address
        Serial.println("I can not find SHT31-D");
      }
    }
    
    void loop() {
      SerialMon.print(F("Waiting for the network..."));
      if (!modem.waitForNetwork()) {
        SerialMon.println(" fail");
        delay(10000);
        return;
      }
      SerialMon.println(" OK");
    
      SerialMon.print(F("Access point connection "));
      SerialMon.print(apn);
      if (!modem.gprsConnect(apn, user, pass)) {
        SerialMon.println(" unsuccessfully");
        delay(10000);
        return;
      }
      SerialMon.println(" OK");
    
      SerialMon.print(F("sending an HTTP GET request... "));
    
      int err = http.get(getResource().c_str());
      if (err != 0) {
        SerialMon.println(F("Connection error"));
        delay(10000);
        return;
      }
    
      http.stop();
      SerialMon.println(F("Disconnected from the server"));
    
      modem.gprsDisconnect();
      SerialMon.println(F("GPRS disconnect"));
    
      //Спать 5 минут
      delay(5 * 60 * 1000);
    
    }
    
    String getResource() {
      String resource = String("/update?key=") + VizIoT_Device_key + "&" + "pass=" + VizIoT_Device_pass ;
    
      //read data from sensors
      float t = sht31.readTemperature();
      float h = sht31.readHumidity();
    
      //checking the temperature information
      if (! isnan(t)) {
        Serial.print("Temperature *C = ");
        Serial.println(t);
        resource += String("&tem=") + t;
      } else {
        Serial.println("Error reading temperature");
      }
    
      //checking the humidity information
      if (! isnan(h)) {
        Serial.print("Hum. % = ");
        Serial.println(h);
        resource += String("&hum=") + h;
      } else {
        Serial.println("Error reading humidity");
      }
      return resource;
    }
    
  3. Install the library «Adafruit SHT31 Library» for working with SHT31-D sensor.
  4. Install the library «TinyGSM» for working with GSM modul SIM800
  5. Install the library «ArduinoHttpClient» for working with protocol HTTP
  6. Set values of the variables:
    • apn – GSM Access Point Name
    • user – GSM hotspot user (empty by default)
    • pass – GSM Access Point Password (empty by default)
    • VizIoT_Device_key – copied device access key
    • VizIoT_Device_pass – copied device access password
  7. Connect SHT31-D sensor to Arduino MEGA 2560 according to the connection pattern:
    • VIN pin of sensor to arduino 3.3V pin
    • GND pin of sensor to arduino GND pin
    • SCL pin of sensor to arduino SCL pin
    • SDA pin of sensor to arduino SDA pin
  8. Connect GPRS modul SIM800L to Arduino MEGA 2560 according to the connection pattern:
    • VIN pin of SIM800L to plus external power supply 4 volts
    • GND pin of SIM800L to minus external power supply 4 volts and to arduino GND pin
    • TX pin of SIM800L to arduino RX1 pin
    • RX pin of SIM800L to arduino TX1 pin pin модуля RX в pin arduino TX1 through a resistive divider (resistors of the same value in the range of 1-10kΩ). Connection pattern:
      Arduino GND-----[10kΩ]---|
                               |--------RX SIM800L
      Arduino TX------[10kΩ]---|
      Read more here.
  9. Connect Arduino to computer and send firmware to microcontroller.

Adding widgets:

  1. Create a new dashboard under the name «Test dashboard temp. hum.»
  2. Add widgets:
    1. Air temperature
      • type: «Chart»;
      • device: «GPRS thermometer testing»;
      • parameter: tem;
    2. Air humidity
      • type: «Chart»;
      • device: «GPRS thermometer testing»;
      • parameter: hum;
    3. Temperature and humidity fluctuations
      • type: «Change over an interval bar chart»;
      • device: «GPRS thermometer testing»;
      • parameters: tem and hum;

Now the setup is complete and you have to wait until your device connected to the server.