Skip to content

Commit 89bec62

Browse files
committed
Updated ESp32 example, removed extra ESP8266 examples (too complicated)
1 parent 1516e74 commit 89bec62

File tree

6 files changed

+47
-415
lines changed

6 files changed

+47
-415
lines changed

examples/ESP32/ChannelStatistics/ChannelStatistics.ino

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,55 @@
11
/*******************************************************************
2-
* Read YouTube Channel statistics from the YouTube API using an
3-
* ESP32
4-
*
5-
* By Brian Lough
6-
* https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
2+
Read YouTube Channel statistics from the YouTube API on
3+
an ESP32 and print them to the serial monitor
4+
5+
Parts:
6+
Any ESP32 board
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
716
*******************************************************************/
817

9-
#include <YoutubeApi.h>
18+
// ----------------------------
19+
// Standard Libraries
20+
// ----------------------------
21+
1022
#include <WiFi.h>
1123
#include <WiFiClientSecure.h>
1224

13-
#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
1440

1541
//------- Replace the following! ------
16-
char ssid[] = "ssid"; // your network SSID (name)
17-
char password[] = "password"; // your network key
18-
#define API_KEY "ENTER_YOUR_API_KEY" // your google apps API Token
42+
char ssid[] = "xxx"; // your network SSID (name)
43+
char password[] = "yyyy"; // your network key
44+
#define API_KEY "zzzz" // your google apps API Token
1945
#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
20-
46+
//------- ---------------------- ------
2147

2248
WiFiClientSecure client;
2349
YoutubeApi api(API_KEY, client);
2450

25-
unsigned long api_mtbs = 60000; //mean time between api requests
26-
unsigned long api_lasttime; //last time api request has been done
51+
unsigned long timeBetweenRequests = 60000;
52+
unsigned long nextRunTime;
2753

2854
long subs = 0;
2955

@@ -55,7 +81,7 @@ void setup() {
5581

5682
void loop() {
5783

58-
if (millis() - api_lasttime > api_mtbs) {
84+
if (millis() > nextRunTime) {
5985
if(api.getChannelStatistics(CHANNEL_ID))
6086
{
6187
Serial.println("---------Stats---------");
@@ -73,6 +99,6 @@ void loop() {
7399
Serial.println("------------------------");
74100

75101
}
76-
api_lasttime = millis();
102+
nextRunTime = millis() + timeBetweenRequests;
77103
}
78104
}

examples/ESP8266/ChannelStatistics/ChannelStatistics.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************
2-
Read YouTube Channel statistics from the YouTube API
2+
Read YouTube Channel statistics from the YouTube API on
3+
an ESP8266 and print them to the serial monitor
34
45
Parts:
56
D1 Mini ESP8266 (or any ESP8266) * - http://s.click.aliexpress.com/e/uzFUnIe
@@ -79,6 +80,9 @@ void setup() {
7980

8081
// Required if you are using ESP8266 V2.5 or above
8182
client.setInsecure();
83+
84+
// If you want to enable some extra debugging
85+
api._debug = true;
8286
}
8387

8488
void loop() {

examples/ESP8266/ChannelStatisticsWithWifiManager/ChannelStatisticsWithWifiManager.ino

Lines changed: 0 additions & 174 deletions
This file was deleted.

0 commit comments

Comments
 (0)