LAMPIRAN. byte bcdtodec(byte val) { return( (val/16*10) + (val%16) ); } void setup() {

Similar documents
Tabel mysql. Kode di PHP. Config.php. Service.php

Android - JSON Parser Tutorial

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Getting Started With Android Feature Flags

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

File: Unsaved Document 1 Page 1 of 7

Multiple Activities. Many apps have multiple activities

EMBEDDED SYSTEMS PROGRAMMING Android Services

Fragment Example Create the following files and test the application on emulator or device.

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Android JSON Parsing Tutorial

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Introduction to Android Development

<uses-permission android:name="android.permission.internet"/>

<uses-permission android:name="android.permission.internet" />

LifeStreet Media Android Publisher SDK Integration Guide

Android Application Development. By : Shibaji Debnath

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Coding Menggunakan software Eclipse: Mainactivity.java (coding untuk tampilan login): package com.bella.pengontrol_otomatis;

Mobile Development Lecture 9: Android & RESTFUL Services


LAMPIRAN. public class MainActivity extends AppCompatActivity {

Mobile Software Development for Android - I397

Android Volley Tutorial

Android Tutorial: Part 3

Android/Java Lightning Tutorial JULY 30, 2018

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

SIM900A GSM/GPRS MODEM WITH PCB ANTENNA UART INTERFACE. [RKI-1644]

Appendix A : Android Studio Code For Android

SMAATSDK. NFC MODULE ON ANDROID REQUIREMENTS AND DOCUMENTATION RELEASE v1.0

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

COMP61242: Task /04/18

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

ANDROID PROGRAMS DAY 3

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

A Crash Course to Android Mobile Platform

Brain Corporate Bulk SMS

Intents. Your first app assignment

Mobile Application Development

Manifest.xml. Activity.java

Basic GUI elements - exercises

Android UI Development

2.2 IoT Internet of Things Android Studio

Android Programs Day 5

Arrays of Buttons. Inside Android

API Guide for Gesture Recognition Engine. Version 2.0

Learn about Android Content Providers and SQLite

Android - Widgets Tutorial

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Software Practice 3 Today s lecture Today s Task Porting Android App. in real device

INTRODUCTION TO ANDROID

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

EMBEDDED SYSTEMS PROGRAMMING Android NDK

REMOTE ACCESS TO ANDROID DEVICES. A Project. Presented to the faculty of the Department of Computer Science. California State University, Sacramento

Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial

Mobile Programming Practice Background processing AsynTask Service Broadcast receiver Lab #5

Software Practice 3 Today s lecture Today s Task

1 카메라 1.1 제어절차 1.2 관련주요메서드 1.3 제작철차 서피스뷰를생성하고이를제어하는서피스홀더객체를참조해야함. 매니페스트에퍼미션을지정해야한다.

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Starting Another Activity Preferences

Android permissions Defining and using permissions Component permissions and related APIs

Android Workshop: Model View Controller ( MVC):

M.A.D Assignment # 1

E-Blocks wifi controlled by an Android device

An Overview of the Android Programming

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

Notification mechanism

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Android Service. Lecture 19

Created By: Keith Acosta Instructor: Wei Zhong Courses: Senior Seminar Cryptography

API Guide for Gesture Recognition Engine. Version 1.1

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android Application Model I

CS 193A. Multiple Activities and Intents

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Simple Currency Converter

shared objects monitors run() Runnable start()

Data Persistence. Chapter 10

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

Declaration Cover Sheet for Project Submission

Android Beginners Workshop

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

Dynamically Create Admob Banner and Interstitial Ads

Services. Marco Ronchetti Università degli Studi di Trento

RS422/RS485 Shield. Application Note: Multiple RS485 busses. 1 Introduction

Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java.

Outline. Admin. Example: TipCalc. Android: Event Handler Blocking, Android Inter-Thread, Process Communications. Recap: Android UI App Basic Concepts

@Bind(R.id.input_ ) EditText EditText Button _loginbutton;

Mobile Development Lecture 8: Intents and Animation

Accelerating Information Technology Innovation

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Assignment 1. Start: 28 September 2015 End: 9 October Task Points Total 10

Transcription:

60 LAMPIRAN 1. Source code Arduino. #include "Wire.h" #include <SoftwareSerial.h> #include <String.h> #define DS3231_I2C_ADDRESS 0x68 SoftwareSerial sim800l(11, 10); int dline[28]; byte *cacah=0; String stringpara = "AT+HTTPPARA=\"URL\",\"http://autobike.pe.hu/input.php?fuel="; String stringend = "\""; String stringpara2 = ""; String bt = "&battery="; String en = "&engine_st="; String tr = "&transmission_st="; float fuel; float battery; String engine; String transmission; int power = 8; int start = 9; int pul = 3; int net = 2; byte bcdtodec(byte val) return( (val/16*10) + (val%16) ); void setup() Wire.begin(); sim800l.begin(19200); // the GPRS baud rate Serial.begin(19200); // the GPRS baud rate delay(500); pinmode(power,output); pinmode(start,output); pinmode(pul,output); pinmode(net,input); digitalwrite(power,high); delay (100); digitalwrite(start,high); delay (100);

61 cacah = 0; void readds3231time(byte *second, byte *minute, byte *hour, byte *dayofweek, byte *dayofmonth, byte *month, byte *year) Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); // set DS3231 register pointer to 00h Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); // request seven bytes of data from DS3231 starting from register 00h *second = bcdtodec(wire.read() & 0x7f); *minute = bcdtodec(wire.read()); *hour = bcdtodec(wire.read() & 0x3f); *dayofweek = bcdtodec(wire.read()); *dayofmonth = bcdtodec(wire.read()); *month = bcdtodec(wire.read()); *year = bcdtodec(wire.read()); void SubmitHttpRequest() stringpara2 = stringpara + fuel + bt + battery + en + engine + tr + transmission + stringend; //Serial.println(stringPARA2); sim800l.println("at+csq"); // this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too. sim800l.println("at+cgatt?"); sim800l.println("at+sapbr=3,1,\"contype\",\"gprs\""); the SAPBR, the connection type is using gprs //setting

62 sim800l.println("at+sapbr=3,1,\"apn\",\"internet\""); APN, the second need you fill in your local apn server //setting the sim800l.println("at+sapbr=1,1"); for detail you can refer to the AT command mamual delay(2000); sim800l.println("at+httpinit"); delay(2000); //setting the SAPBR, //init the HTTP request sim800l.println(stringpara2); // setting the httppara, the second parameter is the website you want to access sim800l.println("at+httpaction=0");//submit the request delay(3000); //the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer. sim800l.println("at+httpread");// read the data from the website you access delay(300); checkforresponse(); sim800l.println("at+httpterm"); delay(100); void ShowSerialData() while(sim800l.available()!=0) Serial.write(sim800l.read()); void checkforresponse() sim800l.println("at+httpread");// read the data from the website you access delay(300);

63 // for (int i = 0; i < 50; i++) dline[i] = sim800l.read(); //Serial.println(dLine[i]); Serial.println(dLine[28]); if (dline[28]!= 97) SubmitHttpRequest(); void sensor() read_engine(); float Sensor1 = analogread(a1); // membaca sensor tegangan 1 delay (1000); Serial.println(Sensor1); fuel =(65.00 - Sensor1) *1.85; if (fuel>100 fuel<0) fuel = 0; Serial.println(fuel); float Sensor2 = analogread(a2); // membaca sesor tegangan 2 delay (1000); battery = Sensor2 * (12.0 / 582.0); Serial.println(battery); digitalwrite(pul,high); delay(100); if ( digitalread(net) == HIGH) transmission = "ON GEAR"; else transmission = "NEUTRAL"; digitalwrite(pul,low); Serial.println(transmission); void read_engine() // puldown input neutral // membaca status transmisi

64 float val1 = analogread(a0); if (val1>10) engine = "ON"; else engine = "OFF"; Serial.println(engine); // membaca staus mesin void start_engine() digitalwrite(power,low); delay (4000); sensor(); if(fuel>31.45 && battery > 10 && transmission == "NEUTRAL" && engine == "OFF") cacah = 0; while (engine == "OFF" && cacah <3) digitalwrite (start,low); delay (500); digitalwrite (start,high); delay(2000); read_engine(); cacah++; if (engine == "ON") sensor(); SubmitHttpRequest(); delay (60000); digitalwrite (power,high); digitalwrite(power,low); delay (4000); sensor(); digitalwrite(power,high); SubmitHttpRequest();

65 else SubmitHttpRequest(); else SubmitHttpRequest(); void loop() byte second, minute, hour, dayofweek, dayofmonth, month, year; readds3231time(&second, &minute, &hour, &dayofweek, &dayofmonth, &month, &year); if (hour==07 && minute==00 && second == 00) start_engine(); digitalwrite(power,high); 2. Source code PHP a. input.ph <?php date_default_timezone_set("asia/jakarta"); $time = date("h:i:sa"); $date = date ("Y/m/d"); $server = "mysql.hostinger.in"; // host name $username = "u398539280_bike"; // database username $password = "harpot"; // database password $dbname = "u398539280_auto"; //database name // Create connection $conn = mysqli_connect($server, $username, $password, $dbname); // Check connection $sql = "INSERT INTO Minerva (fuel,battery, engine_st, transmission_st, time, date)

66 VALUES ('".$_GET['fuel']."','".$_GET['battery']."','".$_GET['engine_st']."','".$_GET ['transmission_st']."','$time','$date')"; echo "a"; mysqli_query($conn,$sql);?> b. Getdata.php <?php require_once('connect.php'); $sql = "SELECT * FROM Minerva ORDER BY number DESC LIMIT 1"; $r = mysqli_query($con,$sql); $res = mysqli_fetch_array($r); $result = array(); array_push($result,array( "battery"=>$res['battery'], "fuel"=>$res['fuel'], "engine_st"=>$res['engine_st'], "transmission_st"=>$res['transmission_st'], "date"=>$res['date'], "time"=>$res['time'])); echo json_encode(array("result"=>$result)); mysqli_close($con);?>

67 3. Source code Android a. Kelas MainActivity.java import android.widget.toast; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest; import com.android.volley.toolbox.volley; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; public class MainActivity extends AppCompatActivity implements View.OnClickListener private Button buttonget; private TextView textviewresult; private ProgressDialog loading; @Override protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); buttonget = (Button)findViewById(R.id.buttonGet); textviewresult = (TextView)findViewById(R.id.textViewResult); buttonget.setonclicklistener(this); private void getdata() loading = ProgressDialog.show(this, "Please wait...", "Fetching...", false, false); String url = Config.DATA_URL; StringRequest stringrequest = new StringRequest(url, new Response.Listener<String>() @Override public void onresponse(string response) loading.dismiss(); showjson(response);, new Response.ErrorListener() @Override

68 public void onerrorresponse(volleyerror error) Toast.makeText(MainActivity.this, error.getmessage().tostring(), Toast.LENGTH_LONG).show(); ); RequestQueue requestqueue = Volley.newRequestQueue(this); requestqueue.add(stringrequest); private void showjson(string response) String battery = ""; String fuel = ""; String engine_st = ""; String transmition_st = ""; String date = ""; String time = ""; try JSONObject jsonobject = new JSONObject(response); JSONArray result = jsonobject.getjsonarray(config.json_array); JSONObject bikedata = result.getjsonobject(0); battery = bikedata.getstring(config.key_battery); fuel = bikedata.getstring(config.key_fuel); engine_st = bikedata.getstring(config.key_engine_st); transmition_st = bikedata.getstring(config.key_transmition_st); date = bikedata.getstring(config.key_date); time = bikedata.getstring(config.key_time); catch (JSONException e) e.printstacktrace(); textviewresult.settext("battery:\t" + battery + "\nfuel:\t" + fuel + "\nengine_st:\t" + engine_st + "\ntransmission_st:\t" + transmition_st+ "\ndate:\t" + date+ "\ntime:\t" + time); @Override public void onclick(view v)

69 getdata(); b. Kelas AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.valgavin.bikeauto"> <uses-permission android:name="android.permission.internet"/> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest> c. Kelas Config.java package com.example.harry.bikeauto; /** * Created by Harry on 1/30/2017. */ public class Config public static final String DATA_URL = "https://autobike.pe.hu/getdata.php"; public static final String KEY_BATTERY = "battery"; public static final String KEY_FUEL = "fuel"; public static final String KEY_ENGINE_ST = "engine_st"; public static final String KEY_TRANSMITION_ST = "transmition_st"; public static final String KEY_DATE = "date"; public static final String KEY_TIME = "time"; public static final String JSON_ARRAY = "result";