Antares
Antares
en
en
  • Getting Started
    • Account Registration
    • Create App
    • Add Devices to the Application
    • Installation Board and Library
      • ESP8266
      • ESP32
      • STM32
    • Arduino IDE Installation
    • Arduino Library Installation
      • Antares LoRaWAN
      • Antares Wi-Fi HTTP
      • Antares Wi-Fi MQTT
      • DHT11 Sensor Library
      • Adafruit SSD1306
    • STM32 Cube IDE Installation
    • Expansion Pack I-CUBE-LRWAN Installation
    • Software Installation
      • MQTTX Installation
      • Postman Installation
      • Operating System (OS) on SD Card Installation
    • Quickstart
  • Antares Insight Hub
    • Getting Started
      • Request Demo
      • Request Free Trial
    • Usecase
      • Power Meter
        • Power Meter Usecase Prerequisites
        • Power Meter Device Recommendation
        • Payload Example Power Meter
        • Setup Device Threshold Power Meter
      • Water Meter
        • Water Meter Usecase Prerequisites
        • Water Meter Device Recommendation
        • Payload Example Water Meter
        • Setup Device Threshold Water Meter
      • Water Level
        • Water Level Usecase Prerequisites
        • Water Level Device Recommendation
        • Payload Example Water Level
        • Setup Device Threshold Water Level
      • Environment Monitoring
        • Prerequisites for Use of Environmental Monitoring
        • Environment Monitoring Device Recommendation
        • Payload Example Environment Monitoring
        • Setup Device Threshold Environment Monitoring
    • Settings
      • Manage Alert Recipient (Telegram)
      • Manage User
      • Roles
  • Subscription and Payment
    • Platform
      • How to Use Platform Packages
      • How to Purchase a Platform Subscription
        • Payment Using Antares Coins
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
      • Procedure for Renewing a Platform Subscription
      • Procedure for Changing Platform Subscription
    • Connectivity
      • How to Use Connectivity Packages
      • How to Purchase a Connectivity Subscription
        • Payment Using Antares Coins
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
      • Procedure for Renewing a Platform Subscription
      • Procedure for Changing Connectivity Subscription
    • Antares Coins
      • Antares Coins Top Up Payment Procedures
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
  • Code and library examples
    • ESP8266 (Wi-Fi)
      • General Prerequisites ESP8266 Wi-Fi
      • ESP8266 (Wi-Fi) HTTP Protocol
        • Sending Simple Data to Antares with HTTP Protocol
        • Retrieve the Last Data from Antares Server with HTTP Protocol
        • Simple Project ESP8266 HTTP Antares
          • Periodic Post DHT 11 Data
          • Post DHT 11 Data with Push Button
          • Post DHT 11 data and Display on OLED
          • Get Data displayed on OLED
          • Post and Get DHT 11 Data displayed on OLED
          • Controlling Relays and LEDs Through Get Commands
      • ESP8266 (Wi-Fi) MQTT Protocol
        • Sending Simple Data to Antares with the MQTT Protocol
        • Retrieve Last Data from Antares Server with MQTT Protocol
        • Simple Project ESP8266 MQTT Antares
          • Periodic Send DHT 11 Data
          • Send DHT 11 Data with Push Button
          • Send DHT 11 data and display on OLED display
          • Retrieve Data displayed on OLED Display
          • DHT 11 Send Data and Retrieve Data displayed on OLED Display
          • Controlling Relays and LEDs Through Get Commands
    • Arduino Uno
      • Arduino IDE Installation
      • Antares Ethernet Shield Library Installation
      • Configuration
      • Send Simple Data to Antares
    • ESP32 (Wi-Fi)
      • General Prerequisites ESP32 Wi-Fi
      • ESP32 (Wi-Fi) HTTP Protocol
        • Sending Simple Data to Antares with HTTP Protocol
        • Retrieve the Last Data from Antares Server with HTTP Protocol
        • Simple Project Lynx-32 HTTP Antares
          • Periodic Post DHT 11 Data
          • Post DHT 11 Data with Push Button
          • Post DHT 11 Data and Display on OLED
          • Get Data displayed on OLED
          • Post and Get DHT 11 Data displayed on OLED
          • Controlling Relays and LEDs Through Get Commands
      • ESP32 (Wi-Fi) MQTT Protocol
        • Sending Simple Data to Antares with the MQTT Protocol
        • Retrieve Last Data from Antares Server with MQTT Protocol
        • Simple Project Lynx-32 MQTT Antares
          • Periodic Send DHT 11 Data
          • Send Data DHT 11 dengan Push Button
          • Send DHT 11 Data and Display on OLED
          • Retrieve Data displayed on OLED Display
          • DHT 11 Send Data and Retrieve Data displayed on OLED
          • Controlling Relays and LEDs Through Retrieve Commands
      • HTTP & MQTT Protocol
    • ESP32 (LoRa)
      • General Prerequisites ESP32 LoRa
      • Sending Simple Data to Antares
      • Project Simple Lynx-32 LoRa Antares
        • Uplink DHT11 Data Periodically
        • Uplink Data DHT11 dengan Push Button
        • Uplink DHT11 Data and Display on OLED Display
        • Downlink Data Displayed on OLED
        • DHT 11 Uplink Data and Downlink Data displayed on OLED
        • Controlling Relay and LED via Downlink Command
      • LoRaWAN Class
    • STM32 (LoRa) STM32Cube IDE
      • General Prerequisites STM32 (LoRa) STM32Cube IDE
      • Sending Simple Data to Antares
    • STM32 (LoRa) Arduino IDE
      • General Prerequisites STM32 (LoRa) Arduino IDE
      • Sending Simple Data to Antares
    • Raspberry Pi
      • GUI (Graphical User Interface)
        • Raspberry GUI General Prerequisites
        • Sending Data Using Node.js
        • Temperature and Humidity Monitoring Using DHT11 Sensor
      • SSH (Secure Shell)
        • Common Raspberry SSH Prerequisites
        • Sending Data Using Node.js
        • Temperature and Humidity Monitoring Using DHT11 Sensor
    • NB-IoT
      • NB-Lynx-7000
        • General Prerequisites NB-Lynx-7000
        • Sending Simple Data to Antares
        • Retrieving GNSS (Global Navigation Satellite System) Data
      • NB-Lynx-95
        • General Prerequisites NB-Lynx-95
        • Sending Simple Data to Antares
    • Android
      • Retrieve data from ANTARES using Android
      • Coding Stuff
    • MIT App Inventor
    • Node-RED
    • Postman
    • MQTT | Push data to Device
    • HTTP | Subscribe and Notify Mechanism
    • PHP Library
    • MQTT | Subscribe LoRa Device
    • LoRaWAN | Downlink Tutorial
    • LoRaWAN Device Register
      • Register Menu
    • GPS TrackerID
  • Data Model
  • Port Configuration
  • API | HTTP
    • Device
    • Data of Device
    • Subscriber
  • API | MQTT
    • Device
    • Subscriber
  • List of Acronyms
  • Relevant Software
Powered by GitBook
On this page
  • A. Data stored in Antares
  • B. Get the latest data from your device via Android
  • C. Connecting a Smartphone to Android Studio
  1. Code and library examples
  2. Android

Coding Stuff

PreviousRetrieve data from ANTARES using AndroidNextMIT App Inventor

Last updated 8 months ago

A. Data stored in Antares

B. Get the latest data from your device via Android

1. AndroidManifest.xml

In order to execute the Antares API, we need Internet access and in order to access the Internet on Android, we need to add the following lines to AndroidManifest.xml.

<!--- IMPORTANT!!!!!!! --->
<!--- Tambahkan line berikut di AndroidManifest.xml Anda --->
<!--- Setelah manifest --->
<uses-permission android:name="android.permission.INTERNET" />
<!--- Sebelum application --->

2. activity_main.xml

Modify ALL the contents of activity_main.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<android.widget.LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No Data"
        android:textSize="24sp"/>

    <Button
        android:id="@+id/btnRefresh"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Refresh"/>

    <Button
        android:id="@+id/btnOn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="On"/>


    <Button
        android:id="@+id/btnOff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Off"/>

</android.widget.LinearLayout>

3. MainActivity.java

// !!!!------ IMPORTANT ---------!!!!//
// Ubah semua code setelah package nama.package.Anda dengan
// dengan Code berikut

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import androidx.appcompat.app.AppCompatActivity;

import id.co.telkom.iot.AntaresHTTPAPI;
import id.co.telkom.iot.AntaresResponse;

public class MainActivity extends AppCompatActivity implements AntaresHTTPAPI.OnResponseListener{

    private Button btnRefresh;
    private Button btnOn;
    private Button btnOff;

    private TextView txtData;
    private String TAG = "ANTARES-API";
    private AntaresHTTPAPI antaresAPIHTTP;
    private String dataDevice;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // --- Inisialisasi UI yang digunakan di aplikasi --- //
        btnRefresh = (Button) findViewById(R.id.btnRefresh);
        btnOff = (Button) findViewById(R.id.btnOff);
        btnOn = (Button) findViewById(R.id.btnOn);

        txtData = (TextView) findViewById(R.id.txtData);

        // --- Inisialisasi API Antares --- //
        //antaresAPIHTTP = AntaresHTTPAPI.getInstance();
        antaresAPIHTTP = new AntaresHTTPAPI();
        antaresAPIHTTP.addListener(this);

        btnRefresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                antaresAPIHTTP.getLatestDataofDevice("your-access-key","your-application-name","your-device-name");

            }
        });

        btnOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                antaresAPIHTTP.storeDataofDevice(1,"your-access-key", "your-application-name", "your-device-name", "{\\\"status\\\":\\\"1\\\"}");

            }
        });

        btnOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                antaresAPIHTTP.storeDataofDevice(1,"your-access-key", "your-application-name", "your-device-name", "{\\\"status\\\":\\\"0\\\"}");
            }
        });
    }

    @Override
    public void onResponse(AntaresResponse antaresResponse) {
        // --- Cetak hasil yang didapat dari ANTARES ke System Log --- //
        //Log.d(TAG,antaresResponse.toString());
        Log.d(TAG,Integer.toString(antaresResponse.getRequestCode()));
        if(antaresResponse.getRequestCode()==0){
            try {
                JSONObject body = new JSONObject(antaresResponse.getBody());
                dataDevice = body.getJSONObject("m2m:cin").getString("con");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        txtData.setText(dataDevice);
                    }
                });
                Log.d(TAG,dataDevice);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}

4. Logcat Result

We can filter the output log results on Android. Please fill in the section as shown below. When the button is clicked, the output results can also be seen in the image below.

Congratulations! You have created your first Android APP using the Antares Library.

C. Connecting a Smartphone to Android Studio

1.Set Settings on Smartphone

  1. Enter the "Settings" menu on your smartphone, then click AboutPhone. Triple click on the MIUI Version / Version Number section of your smartphone until "you are developer" appears.

  2. Enter the "Developer Options" menu in Settings and activate USB Debugging.

  3. Connect your Smartphone USB with Laptop / PC, if there is a notification like this then click OK and your Smartphone is connected to Android Studio.