1
1
/* ******************************************************************
2
- * Read YouTube Channel statistics from the YouTube API *
3
- * *
4
- * By Brian Lough *
5
- * https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA *
2
+ Read YouTube Channel statistics from the YouTube API
3
+
4
+ Parts:
5
+ D1 Mini ESP8266 (or any ESP8266) * - http://s.click.aliexpress.com/e/uzFUnIe
6
+ * = Affilate
7
+
8
+ If you find what I do useful and would like to support me,
9
+ please consider becoming a sponsor on Github
10
+ https://github.com/sponsors/witnessmenow/
11
+
12
+ Written by Brian Lough
13
+ YouTube: https://www.youtube.com/brianlough
14
+ Tindie: https://www.tindie.com/stores/brianlough/
15
+ Twitter: https://twitter.com/witnessmenow
6
16
*******************************************************************/
7
17
8
- #include < YoutubeApi.h>
18
+ // ----------------------------
19
+ // Standard Libraries
20
+ // ----------------------------
21
+
9
22
#include < ESP8266WiFi.h>
10
23
#include < WiFiClientSecure.h>
11
24
12
- #include < ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
25
+ // ----------------------------
26
+ // Additional Libraries - each one of these will need to be installed.
27
+ // ----------------------------
28
+
29
+ #include < YoutubeApi.h>
30
+ // Library for connecting to the Youtube API
31
+
32
+ // Search for "youtube" in the Arduino Library Manager
33
+ // https://github.com/witnessmenow/arduino-youtube-api
34
+
35
+ #include < ArduinoJson.h>
36
+ // Library used for parsing Json from the API responses
37
+
38
+ // Search for "Arduino Json" in the Arduino Library manager
39
+ // https://github.com/bblanchon/ArduinoJson
13
40
14
41
// ------- Replace the following! ------
15
42
char ssid[] = " xxx" ; // your network SSID (name)
16
43
char password[] = " yyyy" ; // your network key
17
44
#define API_KEY " zzzz" // your google apps API Token
18
45
#define CHANNEL_ID " UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
19
-
46
+ // ------- ---------------------- ------
20
47
21
48
WiFiClientSecure client;
22
49
YoutubeApi api (API_KEY, client);
23
50
24
- unsigned long api_mtbs = 60000 ; // mean time between api requests
25
- unsigned long api_lasttime; // last time api request has been done
51
+ unsigned long timeBetweenRequests = 60000 ;
52
+ unsigned long nextRunTime;
26
53
27
54
long subs = 0 ;
28
55
@@ -50,12 +77,13 @@ void setup() {
50
77
IPAddress ip = WiFi.localIP ();
51
78
Serial.println (ip);
52
79
53
-
80
+ // Required if you are using ESP8266 V2.5 or above
81
+ client.setInsecure ();
54
82
}
55
83
56
84
void loop () {
57
85
58
- if (millis () - api_lasttime > api_mtbs ) {
86
+ if (millis () > nextRunTime ) {
59
87
if (api.getChannelStatistics (CHANNEL_ID))
60
88
{
61
89
Serial.println (" ---------Stats---------" );
@@ -73,6 +101,6 @@ void loop() {
73
101
Serial.println (" ------------------------" );
74
102
75
103
}
76
- api_lasttime = millis ();
104
+ nextRunTime = millis () + timeBetweenRequests ;
77
105
}
78
106
}
0 commit comments