Sie sind auf Seite 1von 8

LAPORAN RESMI

PRAKTIKUM TELEMETRI
MODUL 5
KOMUNIKASI DATA ONLINE FIREBASE

Oleh :
Rifki Dita Wahyu P. (0915040013)

PROGRAM STUDI TEKNIK OTOMASI


JURUSAN TEKNIK KELISTRIKAN KAPAL
POLITEKNIK PERKAPALAN NEGERI SURABAYA
2018
Program Android
package com.example.rifki.live;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

Firebase fb;
ArrayList<String> pot = new ArrayList<>();
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);

fb = new Firebase("https://telemetri-4bb7e.firebaseio.com/pot");
lv = (ListView) findViewById(R.id.listview1);

final ArrayAdapter<String> arrayAdapter = new


ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,pot);;
lv.setAdapter(arrayAdapter);
fb.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s)
{
String value = dataSnapshot.getValue(String.class);
pot.add(value);
arrayAdapter.notifyDataSetChanged();
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String
s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s)
{
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});

Thread t = new Thread(){


@Override
public void run(){
while (!isInterrupted()){
try {
Thread.sleep(1000);

runOnUiThread(new Runnable() {
@Override
public void run() {
arrayAdapter.clear();
lv.setAdapter(arrayAdapter);

fb.addChildEventListener(new
ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot
dataSnapshot, String s) {
String value =
dataSnapshot.getValue(String.class);
pot.add(value);

arrayAdapter.notifyDataSetChanged();
}

@Override
public void
onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void
onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot
dataSnapshot, String s) {
}
@Override
public void onCancelled(FirebaseError
firebaseError) {
}
});
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
}
}
Program Arduino

#include <FirebaseArduino.h>

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#define FIREBASE_APP "telemetri-4bb7e.firebaseio.com"

#define FIREBASE_SECRET "Yp4BlHIid5xxSSlDyJwMJbjLkfuiqRwgzvk9esRP"

static const int wifiType = 0; // 0:Station 1:AP

//Station mode you should put your ssid and password

const char *ssid = "VIVO Y35"; // Put your SSID here

const char *password = "gantibaru"; // Put your PASSWORD here

int adc;

void setup() {

Serial.begin(115200);

if (wifiType == 0) {

if (!strcmp(ssid, "SSID")) {

Serial.println("Please set your SSID");

if (!strcmp(password, "PASSWORD")) {

Serial.println("Please set your PASSWORD");

// Connect to WiFi network

Serial.println();

Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(500);

Serial.print(".");

// WiFi.config(ip, gateway, subnet); // remove this line to use DHCP

Serial.println("WiFi connected");

Serial.println("");

Serial.print("ip: ");

Serial.println(WiFi.localIP());

} else if (wifiType == 1) {

Serial.println(WiFi.softAPIP());

Firebase.begin(FIREBASE_APP, FIREBASE_SECRET); // Initialise Firebase object

void loop() {

int pot = analogRead(A0);

int ldr = random(110,150);

Firebase.setInt("/pot/pot",pot);

//bacaSensor();

//Firebase.setFloat("/frekuensi", adc);

Serial.println(Firebase.getInt("send"));

void bacaSensor(){

adc = analogRead(A0);

}
Lampiran di Firebase.google.com
Tampilan di Android
- Saat nilai potensio 1024

- Saat nilai potensio 512


- Saat nilai potensio 0