Skip to content

Commit

Permalink
Merge pull request #37 from dmadison/examples
Browse files Browse the repository at this point in the history
Examples Rework
  • Loading branch information
witnessmenow authored Jul 7, 2021
2 parents a03a7d0 + 3c7717f commit 111660e
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 213 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=ESP32 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
Expand Down
111 changes: 111 additions & 0 deletions examples/ChannelStatistics/ChannelStatistics.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*******************************************************************
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/
Written by Brian Lough
YouTube: https://www.youtube.com/brianlough
Tindie: https://www.tindie.com/stores/brianlough/
Twitter: https://twitter.com/witnessmenow
*******************************************************************/

// ----------------------------
// Standard Libraries
// ----------------------------

#if defined(ESP8266)
#include <ESP8266WiFi.h>
#elif defined(ESP32)
#include <WiFi.h>
#endif

#include <WiFiClientSecure.h>

// ----------------------------
// Additional Libraries - each of these will need to be installed
// ----------------------------

// Library for connecting to the YouTube API
// https://github.com/witnessmenow/arduino-youtube-api
// (search for "youtube" in the Arduino Library Manager)
#include <YoutubeApi.h>

// Library used for parsing Json from the API responses
// https://github.com/bblanchon/ArduinoJson
// (search for "Arduino Json" in the Arduino Library Manager)
#include <ArduinoJson.h>

//------- Replace the following! ------
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
//------- ---------------------- ------

WiFiClientSecure client;
YoutubeApi api(API_KEY, client);

unsigned long timeBetweenRequests = 60 * 1000; // 60 seconds, in milliseconds

void setup() {
Serial.begin(115200);

// Set WiFi to 'station' mode and disconnect
// from the AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

// Connect to the WiFi network
Serial.print("\nConnecting to WiFi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("\nWiFi connected!");
Serial.print("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);

#ifdef ESP8266
// Required if you are using ESP8266 V2.5 or above
client.setInsecure();
#endif

// Uncomment for extra debugging info
// api._debug = true;
}

void loop() {
if(api.getChannelStatistics(CHANNEL_ID)) {
Serial.println("\n---------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("------------------------");
}
delay(timeBetweenRequests);
}
102 changes: 0 additions & 102 deletions examples/ESP32/ChannelStatistics/ChannelStatistics.ino

This file was deleted.

108 changes: 0 additions & 108 deletions examples/ESP8266/ChannelStatistics/ChannelStatistics.ino

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/travis/platformioSingle.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 111660e

Please sign in to comment.