Advertisement
Guest User

Monitoring Statistik Channel Youtube

a guest
Apr 6th, 2020
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. //Monitoring Statistik Channel Youtube
  2.  
  3. #include <ESP8266WiFi.h>
  4. #include <ESP8266HTTPClient.h>
  5. #include <ArduinoJson.h>
  6. #include <LiquidCrystal_I2C.h>
  7.  
  8. //Sesuaikan dengan addres i2c dan ukuran LCD yg digunakan
  9. LiquidCrystal_I2C lcd(0x27, 20, 4);
  10.  
  11. const char* ssid = "xxxxxxx"; //masukkan ssid anda
  12. const char* password = "xxxxxx"; //masukkan password anda
  13.  
  14. void setup () {
  15.  
  16.   Serial.begin(115200);
  17.   WiFi.begin(ssid, password);
  18.  
  19.    lcd.begin();  
  20.    lcd.backlight();
  21.  
  22.   while (WiFi.status() != WL_CONNECTED) {
  23.  
  24.     delay(1000);
  25.     Serial.println("Connecting..");
  26.  
  27.   }
  28.  
  29.   if(WiFi.status() == WL_CONNECTED){
  30.     Serial.println("Connected!!!");
  31.   }
  32.   else{
  33.     Serial.println("Connected Failed!!!");
  34.   }
  35.  
  36. }
  37.  
  38. void loop() {
  39.  
  40.   if (WiFi.status() == WL_CONNECTED) {
  41.  
  42.     HTTPClient http;
  43.  
  44.     http.begin("http://192.168.43.220/rizkyprojects/Web/parsing-youtube.php"); //Silakan ganti dengan ip address dan sesuaikan dengan direktori penyimpanan file php anda
  45.     int httpCode = http.GET();
  46.  
  47.     if (httpCode > 0) {
  48.       char json[500];
  49.       String payload = http.getString();
  50.       payload.toCharArray(json, 500);
  51.      
  52.       //StaticJsonDocument<200> doc;
  53.       DynamicJsonDocument doc(JSON_OBJECT_SIZE(4));
  54.  
  55.      // Deserialize the JSON document
  56.        deserializeJson(doc, json);
  57.        
  58.      const char* Channel = doc["Channel"];
  59.      int Subscribers     = doc["Subscribers"];
  60.      int Videos          = doc["Videos"];
  61.      int Views           = doc["Views"];
  62.      
  63.       Serial.print("Channel : ");
  64.       Serial.println(Channel);
  65.       Serial.print("Subscribers : ");
  66.       Serial.println(Subscribers);
  67.       Serial.print("Total Video : ");
  68.       Serial.println(Videos);
  69.       Serial.print("Total View : ");
  70.       Serial.println(Views);
  71.       Serial.println("");
  72.  
  73.       lcd.setCursor(0,0);
  74.       lcd.print("Channel: ");
  75.       lcd.print(Channel);
  76.       lcd.print("      ");
  77.       lcd.setCursor(0,1);
  78.       lcd.print("Subscribers: ");
  79.       lcd.print(Subscribers);
  80.       lcd.print("      ");
  81.       lcd.setCursor(0,2);
  82.       lcd.print("Videos: ");
  83.       lcd.print(Videos);
  84.       lcd.print("    ");
  85.       lcd.setCursor(0,3);
  86.       lcd.print("Views: ");
  87.       lcd.print(Views);
  88.       lcd.print("    ");
  89.      
  90.      
  91.     }
  92.  
  93.     http.end();
  94.  
  95.   }
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement