46
LAMPIRAN A //Kode Program Sistem //inisialisasi variabel dan library #include <SD.h> #include <SPI.h> #include <Time.h> #include <Ethernet.h> byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3 byte sensorPin = 2; // konstanta untuk faktor kalibrasi flow sensor float calibrationFactor = 8.5; volatile byte pulseCount; int volbulan[6] ; int temp[6]; unsigned long volume; unsigned long total; unsigned long oldmin; unsigned long oldmonth; unsigned long oldTime; float debitmenit; unsigned int debitdetik; const int chipSelect = 4; File dataFile; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 10,4,11,177 }; const int MAX_PAGE_NAME_LEN = 8; // max characters in a page name char buffer[MAX_PAGE_NAME_LEN+1]; // page name + terminating null EthernetServer server(80); EthernetClient client; //inisialisasi server ,SD card, waktu dan interupsi void setup() { Serial.begin(9600); Ethernet.begin(mac, ip); server.begin(); Serial.println("Ready");
Universitas Sumatera Utara
47
setTime(12,0,0,6,30,14); attachInterrupt(sensorInterrupt, RISING);
pulseCounter,
// make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized."); } //Fungsi Utama Sistem void loop() { debit(); // Rutin pembacaan data debbit air dari sensor client = server.available(); if (client) { while (client.connected()) { if (client.available()) { if( client.find("GET ") ) { // look for the page name memset(buffer,0, sizeof(buffer)); // clear the buffer if(client.find( "/")) if(client.readBytesUntil('/', buffer, MAX_PAGE_NAME_LEN )) { if(strcmp(buffer, "tampil") == 0) showAnalog(); else if(strcmp(buffer, "data") == 0) showDigital();
Universitas Sumatera Utara
48
else unknownPage(buffer); } } Serial.println(); break; } } client.stop(); } } // Rutin Halaman Data real-time sistem void showAnalog() { sendHeader(); client.println(F("DATA PELANGGAN ")); client.println("
"); client.println(F("NAMA PELANGGAN : Arif Azhari")); client.println("
"); client.println(F("NOMOR PELANGGAN : 11691")); client.println("
"); client.println(F("ALAMAT PELANGGAN : Jl Ayahanda Gg tabib NO : 6")); client.println("
"); client.print(" Jam : "); client.print(hour()); client.print(F(" Menit : ")); client.print(minute()); client.print(F(" Detik : ")); client.print(second()); client.println("
"); client.print(F(" Tanggal : ")); client.print(day()); client.print(F(" Bulan : ")); client.print(monthStr(month())); client.print(F(" Tahun : ")); client.print(year()); client.println("
");
Universitas Sumatera Utara
49
m3) :
client.print(F("Pemakaian air Bulan ini (dalam "));
client.print(volume); client.println("
"); for (int bulan = 0; bulan < 5; bulan++) { client.print(F("Pemakaian air ")); client.print(bulan+1); client.print(F(" Bulan Lalu : ")); client.print(volbulan[bulan]); client.println("
"); } } //Rutin Halaman Web Data pada kartu memori void showDigital() { sendHeader(); File dataFile = SD.open("datalog.txt"); int i; while(dataFile.available()) { client.write(dataFile.read()); i++; if(i > 40) { i=0; client.println("
"); } } dataFile.close(); } //Halaman Web default void unknownPage(char *page) { sendHeader(); client.println("
Halaman
utama
Universitas Sumatera Utara
50
Sistem
"); client.print(page); client.println("
"); client.println("Halaman yang tersedia :
"); client.println("/Hasil Pembacaan /
"); client.println("/Data Pembacaan/
"); client.println("