From 1d10c12c2c3aecea01f835e6660c3726e3c9d9ce Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 18:47:35 -0400 Subject: [PATCH 01/11] Combine ESP8266 and ESP32 examples Other than the WiFi include and the `setInsecure` function these are identical. Better to merge them and only have to worry about maintaining one example for all boards. --- .travis.yml | 2 +- .../ChannelStatistics/ChannelStatistics.ino | 102 ------------------ .../ChannelStatistics/ChannelStatistics.ino | 26 +++-- 3 files changed, 19 insertions(+), 111 deletions(-) delete mode 100644 examples/ESP32/ChannelStatistics/ChannelStatistics.ino diff --git a/.travis.yml b/.travis.yml index adc8c06..5afaaa9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ cache: env: - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini - - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=tinypico + - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=tinypico install: - pip install -U platformio diff --git a/examples/ESP32/ChannelStatistics/ChannelStatistics.ino b/examples/ESP32/ChannelStatistics/ChannelStatistics.ino deleted file mode 100644 index 2feddf2..0000000 --- a/examples/ESP32/ChannelStatistics/ChannelStatistics.ino +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************* - Read YouTube Channel statistics from the YouTube API on - an ESP32 and print them to the serial monitor - - Parts: - Any ESP32 board - - If you find what I do useful and would like to support me, - please consider becoming a sponsor on Github - https://github.com/sponsors/witnessmenow/ - - Written by Brian Lough - YouTube: https://www.youtube.com/brianlough - Tindie: https://www.tindie.com/stores/brianlough/ - Twitter: https://twitter.com/witnessmenow - *******************************************************************/ - -// ---------------------------- -// Standard Libraries -// ---------------------------- - -#include -#include - -// ---------------------------- -// Additional Libraries - each one of these will need to be installed. -// ---------------------------- - -#include -// Library for connecting to the Youtube API - -// Search for "youtube" in the Arduino Library Manager -// https://github.com/witnessmenow/arduino-youtube-api - -#include -// Library used for parsing Json from the API responses - -// Search for "Arduino Json" in the Arduino Library manager -// https://github.com/bblanchon/ArduinoJson - -//------- Replace the following! ------ -char ssid[] = "xxx"; // your network SSID (name) -char password[] = "yyyy"; // your network key -#define API_KEY "zzzz" // your google apps API Token -#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel -//------- ---------------------- ------ - -WiFiClientSecure client; -YoutubeApi api(API_KEY, client); - -unsigned long timeBetweenRequests = 60000; -unsigned long nextRunTime; - -long subs = 0; - -void setup() { - - Serial.begin(115200); - - // Attempt to connect to Wifi network: - Serial.print("Connecting Wifi: "); - Serial.println(ssid); - - /* Explicitly set the ESP32 to be a WiFi-client, otherwise, it by default, - would try to act as both a client and an access-point and could cause - network-issues with your other WiFi-devices on your WiFi-network. */ - WiFi.mode(WIFI_STA); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - Serial.print("."); - delay(500); - } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - IPAddress ip = WiFi.localIP(); - Serial.println(ip); - - -} - -void loop() { - - if (millis() > nextRunTime) { - if(api.getChannelStatistics(CHANNEL_ID)) - { - Serial.println("---------Stats---------"); - Serial.print("Subscriber Count: "); - Serial.println(api.channelStats.subscriberCount); - Serial.print("View Count: "); - Serial.println(api.channelStats.viewCount); - Serial.print("Video Count: "); - Serial.println(api.channelStats.videoCount); - // Probably not needed :) - //Serial.print("hiddenSubscriberCount: "); - //Serial.println(api.channelStats.hiddenSubscriberCount); - Serial.println("------------------------"); - - } - nextRunTime = millis() + timeBetweenRequests; - } -} diff --git a/examples/ESP8266/ChannelStatistics/ChannelStatistics.ino b/examples/ESP8266/ChannelStatistics/ChannelStatistics.ino index bda7ec2..0d0d9db 100644 --- a/examples/ESP8266/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ESP8266/ChannelStatistics/ChannelStatistics.ino @@ -1,11 +1,14 @@ /******************************************************************* - Read YouTube Channel statistics from the YouTube API on - an ESP8266 and print them to the serial monitor - - Parts: - D1 Mini ESP8266 (or any ESP8266) * - http://s.click.aliexpress.com/e/uzFUnIe - * = Affilate - + Read YouTube Channel statistics from the YouTube API + and print them to the serial monitor + + Compatible Boards: + * Any ESP8266 board + * Any ESP32 board + + Recommended Board: D1 Mini ESP8266 + http://s.click.aliexpress.com/e/uzFUnIe (affiliate) + If you find what I do useful and would like to support me, please consider becoming a sponsor on Github https://github.com/sponsors/witnessmenow/ @@ -20,7 +23,12 @@ // Standard Libraries // ---------------------------- -#include +#if defined(ESP8266) + #include +#elif defined(ESP32) + #include +#endif + #include // ---------------------------- @@ -78,8 +86,10 @@ void setup() { IPAddress ip = WiFi.localIP(); Serial.println(ip); + #ifdef ESP8266 // Required if you are using ESP8266 V2.5 or above client.setInsecure(); + #endif // If you want to enable some extra debugging api._debug = true; From 220fa2e94dc1a3a7e083bf25aa79befbb025a6e7 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 18:59:48 -0400 Subject: [PATCH 02/11] Move examples out of board-specific folder As the examples are no longer board-specific (1d10c12), we don't need the board-specific examples folder and build options. --- .travis.yml | 4 ++-- .../{ESP8266 => }/ChannelStatistics/ChannelStatistics.ino | 0 scripts/travis/platformioSingle.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename examples/{ESP8266 => }/ChannelStatistics/ChannelStatistics.ino (100%) diff --git a/.travis.yml b/.travis.yml index 5afaaa9..c7bce7e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ cache: - "~/.platformio" env: - - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini - - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=tinypico + - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARD=d1_mini + - SCRIPT=platformioSingle EXAMPLE_NAME=ChannelStatistics EXAMPLE_FOLDER=/ BOARD=tinypico install: - pip install -U platformio diff --git a/examples/ESP8266/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino similarity index 100% rename from examples/ESP8266/ChannelStatistics/ChannelStatistics.ino rename to examples/ChannelStatistics/ChannelStatistics.ino diff --git a/scripts/travis/platformioSingle.sh b/scripts/travis/platformioSingle.sh index 4e1214f..f375ded 100755 --- a/scripts/travis/platformioSingle.sh +++ b/scripts/travis/platformioSingle.sh @@ -1,3 +1,3 @@ #!/bin/sh -eux -platformio ci $PWD/examples/$BOARDTYPE$EXAMPLE_FOLDER$EXAMPLE_NAME/$EXAMPLE_NAME.ino -l '.' -b $BOARD +platformio ci $PWD/examples/$EXAMPLE_NAME/$EXAMPLE_NAME.ino -l '.' -b $BOARD From a5e2eaa4cae53740f23d3c3cb98ec12d383a8f36 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 19:41:46 -0400 Subject: [PATCH 03/11] Standardize 'examples' whitespace Tabs for indentation, spaces for alignment --- .../ChannelStatistics/ChannelStatistics.ino | 126 +++++++++--------- 1 file changed, 61 insertions(+), 65 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 0d0d9db..0900e76 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -1,22 +1,22 @@ /******************************************************************* - Read YouTube Channel statistics from the YouTube API - and print them to the serial monitor + Read YouTube Channel statistics from the YouTube API + and print them to the serial monitor - Compatible Boards: - * Any ESP8266 board - * Any ESP32 board + Compatible Boards: + * Any ESP8266 board + * Any ESP32 board - Recommended Board: D1 Mini ESP8266 - http://s.click.aliexpress.com/e/uzFUnIe (affiliate) + Recommended Board: D1 Mini ESP8266 + http://s.click.aliexpress.com/e/uzFUnIe (affiliate) - If you find what I do useful and would like to support me, - please consider becoming a sponsor on Github - https://github.com/sponsors/witnessmenow/ + If you find what I do useful and would like to support me, + please consider becoming a sponsor on Github + https://github.com/sponsors/witnessmenow/ - Written by Brian Lough - YouTube: https://www.youtube.com/brianlough - Tindie: https://www.tindie.com/stores/brianlough/ - Twitter: https://twitter.com/witnessmenow + Written by Brian Lough + YouTube: https://www.youtube.com/brianlough + Tindie: https://www.tindie.com/stores/brianlough/ + Twitter: https://twitter.com/witnessmenow *******************************************************************/ // ---------------------------- @@ -24,9 +24,9 @@ // ---------------------------- #if defined(ESP8266) - #include + #include #elif defined(ESP32) - #include + #include #endif #include @@ -63,56 +63,52 @@ unsigned long nextRunTime; long subs = 0; void setup() { - - Serial.begin(115200); - - // Set WiFi to station mode and disconnect from an AP if it was Previously - // connected - WiFi.mode(WIFI_STA); - WiFi.disconnect(); - delay(100); - - // Attempt to connect to Wifi network: - Serial.print("Connecting Wifi: "); - Serial.println(ssid); - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { - Serial.print("."); - delay(500); - } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - IPAddress ip = WiFi.localIP(); - Serial.println(ip); - - #ifdef ESP8266 - // Required if you are using ESP8266 V2.5 or above - client.setInsecure(); - #endif - - // If you want to enable some extra debugging - api._debug = true; + Serial.begin(115200); + + // Set WiFi to station mode and disconnect from an AP if it was Previously + // connected + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + delay(100); + + // Attempt to connect to Wifi network: + Serial.print("Connecting Wifi: "); + Serial.println(ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(500); + } + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + IPAddress ip = WiFi.localIP(); + Serial.println(ip); + + #ifdef ESP8266 + // Required if you are using ESP8266 V2.5 or above + client.setInsecure(); + #endif + + // If you want to enable some extra debugging + api._debug = true; } void loop() { - - if (millis() > nextRunTime) { - if(api.getChannelStatistics(CHANNEL_ID)) - { - Serial.println("---------Stats---------"); - Serial.print("Subscriber Count: "); - Serial.println(api.channelStats.subscriberCount); - Serial.print("View Count: "); - Serial.println(api.channelStats.viewCount); - Serial.print("Video Count: "); - Serial.println(api.channelStats.videoCount); - // Probably not needed :) - //Serial.print("hiddenSubscriberCount: "); - //Serial.println(api.channelStats.hiddenSubscriberCount); - Serial.println("------------------------"); - - } - nextRunTime = millis() + timeBetweenRequests; - } + if (millis() > nextRunTime) { + if(api.getChannelStatistics(CHANNEL_ID)) { + Serial.println("---------Stats---------"); + Serial.print("Subscriber Count: "); + Serial.println(api.channelStats.subscriberCount); + Serial.print("View Count: "); + Serial.println(api.channelStats.viewCount); + Serial.print("Video Count: "); + Serial.println(api.channelStats.videoCount); + // Probably not needed :) + //Serial.print("hiddenSubscriberCount: "); + //Serial.println(api.channelStats.hiddenSubscriberCount); + Serial.println("------------------------"); + } + nextRunTime = millis() + timeBetweenRequests; + } } From a42b9ea254bcd030a1aff567d5a11b3ac59d641b Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 19:46:03 -0400 Subject: [PATCH 04/11] Fix request limiter rollover in examples --- examples/ChannelStatistics/ChannelStatistics.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 0900e76..39322a3 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -58,7 +58,7 @@ WiFiClientSecure client; YoutubeApi api(API_KEY, client); unsigned long timeBetweenRequests = 60000; -unsigned long nextRunTime; +unsigned long lastRunTime; long subs = 0; @@ -95,7 +95,8 @@ void setup() { } void loop() { - if (millis() > nextRunTime) { + if (millis() - lastRunTime >= timeBetweenRequests) { + lastRunTime = millis(); if(api.getChannelStatistics(CHANNEL_ID)) { Serial.println("---------Stats---------"); Serial.print("Subscriber Count: "); @@ -109,6 +110,5 @@ void loop() { //Serial.println(api.channelStats.hiddenSubscriberCount); Serial.println("------------------------"); } - nextRunTime = millis() + timeBetweenRequests; } } From 84cb5832fb1f09d61c50ea37e821906b11707efb Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 20:03:20 -0400 Subject: [PATCH 05/11] Fix first call delay in example My bad! I forgot to set the 'lastRunTime' value, so this was only called after an initial delay equal to the request period. --- examples/ChannelStatistics/ChannelStatistics.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 39322a3..5d14662 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -57,8 +57,8 @@ char password[] = "yyyy"; // your network key WiFiClientSecure client; YoutubeApi api(API_KEY, client); -unsigned long timeBetweenRequests = 60000; -unsigned long lastRunTime; +unsigned long timeBetweenRequests = 60 * 1000; // 60 seconds, in milliseconds +unsigned long lastRunTime = 0 - timeBetweenRequests; // guarantee run on first call long subs = 0; From 7f8131b19404afcd5b3be7020f3ead73c1950cfe Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 20:19:50 -0400 Subject: [PATCH 06/11] Adjust example comments and formatting Grammar, style, alignment, and readability. --- .../ChannelStatistics/ChannelStatistics.ino | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 5d14662..2afd948 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -32,26 +32,24 @@ #include // ---------------------------- -// Additional Libraries - each one of these will need to be installed. +// Additional Libraries - each of these will need to be installed // ---------------------------- -#include -// Library for connecting to the Youtube API - -// Search for "youtube" in the Arduino Library Manager +// Library for connecting to the YouTube API // https://github.com/witnessmenow/arduino-youtube-api +// (search for "youtube" in the Arduino Library Manager) +#include -#include // Library used for parsing Json from the API responses - -// Search for "Arduino Json" in the Arduino Library manager // https://github.com/bblanchon/ArduinoJson +// (search for "Arduino Json" in the Arduino Library Manager) +#include //------- Replace the following! ------ char ssid[] = "xxx"; // your network SSID (name) char password[] = "yyyy"; // your network key -#define API_KEY "zzzz" // your google apps API Token -#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel +#define API_KEY "zzzz" // your Google API key +#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // part of the channel url //------- ---------------------- ------ WiFiClientSecure client; @@ -65,13 +63,13 @@ long subs = 0; void setup() { Serial.begin(115200); - // Set WiFi to station mode and disconnect from an AP if it was Previously - // connected + // Set WiFi to 'station' mode and disconnect + // from the AP if it was previously connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); - // Attempt to connect to Wifi network: + // Connect to the WiFi network Serial.print("Connecting Wifi: "); Serial.println(ssid); WiFi.begin(ssid, password); @@ -97,17 +95,23 @@ void setup() { void loop() { if (millis() - lastRunTime >= timeBetweenRequests) { lastRunTime = millis(); + if(api.getChannelStatistics(CHANNEL_ID)) { Serial.println("---------Stats---------"); + Serial.print("Subscriber Count: "); Serial.println(api.channelStats.subscriberCount); + Serial.print("View Count: "); Serial.println(api.channelStats.viewCount); + Serial.print("Video Count: "); Serial.println(api.channelStats.videoCount); + // Probably not needed :) //Serial.print("hiddenSubscriberCount: "); //Serial.println(api.channelStats.hiddenSubscriberCount); + Serial.println("------------------------"); } } From 176b8e4b821f8944f4d40e9204491c8fbf9f1446 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 20:30:46 -0400 Subject: [PATCH 07/11] Disable additional debugging in example --- examples/ChannelStatistics/ChannelStatistics.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 2afd948..01ebc39 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -88,8 +88,8 @@ void setup() { client.setInsecure(); #endif - // If you want to enable some extra debugging - api._debug = true; + // Uncomment for extra debugging info + // api._debug = true; } void loop() { From e10eebb5705530688bc0c0c098f1a590c5d2a0c4 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 20:32:27 -0400 Subject: [PATCH 08/11] Adjust example output for readability --- examples/ChannelStatistics/ChannelStatistics.ino | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 01ebc39..e9bf33e 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -70,16 +70,15 @@ void setup() { delay(100); // Connect to the WiFi network - Serial.print("Connecting Wifi: "); + Serial.print("\nConnecting to WiFi: "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); + Serial.println("\nWiFi connected!"); + Serial.print("IP address: "); IPAddress ip = WiFi.localIP(); Serial.println(ip); @@ -97,7 +96,7 @@ void loop() { lastRunTime = millis(); if(api.getChannelStatistics(CHANNEL_ID)) { - Serial.println("---------Stats---------"); + Serial.println("\n---------Stats---------"); Serial.print("Subscriber Count: "); Serial.println(api.channelStats.subscriberCount); From 7ff86e337f6bdd554d3c52948daa37d962a6f0e9 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sat, 3 Oct 2020 21:01:53 -0400 Subject: [PATCH 09/11] Use constants for ssid and pw in example --- examples/ChannelStatistics/ChannelStatistics.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index e9bf33e..1128799 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -46,9 +46,9 @@ #include //------- Replace the following! ------ -char ssid[] = "xxx"; // your network SSID (name) -char password[] = "yyyy"; // your network key -#define API_KEY "zzzz" // your Google API key +const char ssid[] = "xxx"; // your network SSID (name) +const char password[] = "yyyy"; // your network key +#define API_KEY "zzzz" // your Google API key #define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // part of the channel url //------- ---------------------- ------ From 4fedff14a4d358e189a2cccf01d3bc81e1d7f4bb Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 20 Jan 2021 18:08:06 -0500 Subject: [PATCH 10/11] Examples: Removed unused 'subs' variable --- examples/ChannelStatistics/ChannelStatistics.ino | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index 1128799..e38d4e1 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -58,8 +58,6 @@ YoutubeApi api(API_KEY, client); unsigned long timeBetweenRequests = 60 * 1000; // 60 seconds, in milliseconds unsigned long lastRunTime = 0 - timeBetweenRequests; // guarantee run on first call -long subs = 0; - void setup() { Serial.begin(115200); From 3c7717fed3cca554c8caa5f0ade6ac4f7ff5ebf7 Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 20 Jan 2021 18:13:50 -0500 Subject: [PATCH 11/11] Examples: Change millis for delay This is not asynchronous, but it's simpler and more idiomatic for newcomers. --- .../ChannelStatistics/ChannelStatistics.ino | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/ChannelStatistics/ChannelStatistics.ino b/examples/ChannelStatistics/ChannelStatistics.ino index e38d4e1..ac1107c 100644 --- a/examples/ChannelStatistics/ChannelStatistics.ino +++ b/examples/ChannelStatistics/ChannelStatistics.ino @@ -56,7 +56,6 @@ WiFiClientSecure client; YoutubeApi api(API_KEY, client); unsigned long timeBetweenRequests = 60 * 1000; // 60 seconds, in milliseconds -unsigned long lastRunTime = 0 - timeBetweenRequests; // guarantee run on first call void setup() { Serial.begin(115200); @@ -90,26 +89,23 @@ void setup() { } void loop() { - if (millis() - lastRunTime >= timeBetweenRequests) { - lastRunTime = millis(); + if(api.getChannelStatistics(CHANNEL_ID)) { + Serial.println("\n---------Stats---------"); - if(api.getChannelStatistics(CHANNEL_ID)) { - Serial.println("\n---------Stats---------"); + Serial.print("Subscriber Count: "); + Serial.println(api.channelStats.subscriberCount); - Serial.print("Subscriber Count: "); - Serial.println(api.channelStats.subscriberCount); + Serial.print("View Count: "); + Serial.println(api.channelStats.viewCount); - Serial.print("View Count: "); - Serial.println(api.channelStats.viewCount); + Serial.print("Video Count: "); + Serial.println(api.channelStats.videoCount); - Serial.print("Video Count: "); - Serial.println(api.channelStats.videoCount); + // Probably not needed :) + //Serial.print("hiddenSubscriberCount: "); + //Serial.println(api.channelStats.hiddenSubscriberCount); - // Probably not needed :) - //Serial.print("hiddenSubscriberCount: "); - //Serial.println(api.channelStats.hiddenSubscriberCount); - - Serial.println("------------------------"); - } + Serial.println("------------------------"); } + delay(timeBetweenRequests); }