Thursday, February 27, 2020

Theogsm Library Communication Arduino

Library Communication Arduino

name=Theogsm
version=1.0.0
author=Theo Pilus Candra
maintainer=https://theo.my.id
sentence=Theogsm adalah Library untuk Arduino, yang berfungsi untuk mempermudah Program GSM khususnya SIM800l.
paragraph=Modul ini membutuhkan Libray TinyGSM, ArduinoHttpClinet, dan Software Serial.
category=Komunikasi
url=https://theo.my.id
architectures=*


#define TINY_GSM_MODEM_SIM800
#include 
#include 
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
HttpClient http(client, server, port);
String body;

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void httpGet(String theo_path)
{
  Serial.print("Server: " + String(server));
  Serial.println();
  int err = http.get(theo_path);
  if (err != 0)
    Serial.println("Koneksi HTTP gagal!");

  int status = http.responseStatusCode();
  Serial.println("Status: " + String(status));
  if (status == 200)
  {
    body = http.responseBody();
    body.trim();
    Serial.println("Pesan: " + body);

    http.stop();
    Serial.println();
  }
}

void setGprs(char *theo_apn, char *theo_user, char *theo_pass)
{
  SerialAT.begin(9600);
  Serial.println("Mulai!");
  modem.restart();
  Serial.println("Identitas modem: " + modem.getModemInfo());
  Serial.println("Mencari sinyal");
  while (!modem.waitForNetwork())
  {
    Serial.println("Koneksi modem gagal!");
    return;
  }
  Serial.println("Modem tersambung");
  Serial.println("Kualitas sinyal: " + String(modem.getSignalQuality()));

  Serial.println("Jaringan GPRS ditemukan");
  while (!modem.gprsConnect(theo_apn, theo_user, theo_pass))
  {
    Serial.println("Koneksi modem gagal!");
    return;
  }
  Serial.println("Modem tersambung jaringan GPRS: " + String(apn));
  Serial.println();
}

Download disini

Post a Comment