Skip to content

Instantly share code, notes, and snippets.

@witnessmenow
Created April 10, 2019 19:54
Show Gist options
  • Save witnessmenow/2ce4fbd4fddf3fcbb4e99b242a22d40a to your computer and use it in GitHub Desktop.
Save witnessmenow/2ce4fbd4fddf3fcbb4e99b242a22d40a to your computer and use it in GitHub Desktop.
Example of Wifi 7 seg
/*******************************************************************
Read YouTube Channel statistics from the YouTube API
* *
By Brian Lough
https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
*******************************************************************/
#include <YoutubeApi.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h> // This Sketch doesn't technically need this, but the library does so it must be installed.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
// I2C address of the display. Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS 0x77
// Create display and DS1307 objects. These are global variables that
// can be accessed from both the setup and loop function below.
Adafruit_7segment clockDisplay = Adafruit_7segment();
//------- Replace the following! ------
char ssid[] = "SSID"; // your network SSID (name)
char password[] = "pass"; // your network key
#define API_KEY "dgfdfhfhgfjfgh" // your google apps API Token
#define CHANNEL_ID "UCezJOfu7OtqGzd5xrP3q6WA" // makes up the url of channel
WiFiClientSecure client;
YoutubeApi api(API_KEY, client);
unsigned long api_mtbs = 60000; //mean time between api requests
unsigned long api_lasttime; //last time api request has been done
long subs = 0;
void setup() {
Serial.begin(115200);
clockDisplay.begin(DISPLAY_ADDRESS);
delay(100);
clockDisplay.print(0, DEC);
clockDisplay.writeDisplay();
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
clockDisplay.print(1, DEC);
clockDisplay.writeDisplay();
// 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);
}
clockDisplay.print(2, DEC);
clockDisplay.writeDisplay();
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
delay(100);
}
bool first = true;
void loop() {
if (first || millis() - api_lasttime > api_mtbs) {
first = false;
if (api.getChannelStatistics(CHANNEL_ID))
{
Serial.println("---------Stats---------");
Serial.print("Subscriber Count: ");
Serial.println(api.channelStats.subscriberCount);
clockDisplay.print(api.channelStats.subscriberCount, DEC);
clockDisplay.writeDisplay();
Serial.print("View Count: ");
Serial.println(api.channelStats.viewCount);
Serial.print("Comment Count: ");
Serial.println(api.channelStats.commentCount);
Serial.print("Video Count: ");
Serial.println(api.channelStats.videoCount);
// Probably not needed :)
//Serial.print("hiddenSubscriberCount: ");
//Serial.println(api.channelStats.hiddenSubscriberCount);
Serial.println("------------------------");
}
api_lasttime = millis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment