// Library Imports
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <HTTPClient.h>
#include <string>
// File imports
#include "secrets.h"
#include "FontSubs.h"
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
#define MAX_DEVICES 4
#define CS_PIN 5
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
WiFiClientSecure client;
unsigned long api_mtbs = 10000; // Change length of time before the next API call (Default: 10,000 -> 10 sec)
unsigned long api_lasttime;
long subs = 0;
long views = 0;
String apiUrl = "";
StaticJsonDocument<1000> doc;
bool showSubs = false;
void setup() {
// Start Console
Serial.begin(9600);
// Setup screen,
Display.begin();
Display.setIntensity(0);
Display.setFont(fontSubs);
Display.setTextAlignment(PA_CENTER);
// Connect to wifi
Serial.print("Connecting to Wifi...");
WiFi.begin(SECRET_SSID, SECRET_PASS);
Display.print(" WiFi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println(WiFi.localIP());
Display.print("Connected");
delay(2000);
// Start process of getting data
Display.displayClear();
Display.print("fetching");
delay(250);
client.setInsecure();
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (millis() - api_lasttime > api_mtbs) {
// Instantiate http client
// We use http client instead of YoutubeApi.h library to allow us to fetch data from any site in future
HTTPClient http;
// Convert the C-style strings to std::string objects
std::string channelID(SECRET_CHANNELID);
std::string apiKey(SECRET_APIKEY);
// Create Api URL
apiUrl = ("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + channelID + "&key=" + apiKey).c_str();
// Run API call and get status code
http.begin(apiUrl);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, payload);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
// Display Sub or View count
Serial.print(payload);
if(showSubs) {
subs = doc["items"][0]["statistics"]["subscriberCount"];
String subsCount = num_format(subs);
Serial.println(subsCount);
Display.print("*" + subsCount);
}else{
views = doc["items"][0]["statistics"]["viewCount"];
String viewsCount = num_format(views);
Serial.println(viewsCount);
Display.print("*" + viewsCount);
}
// Change from subs to views
showSubs = !showSubs;
}
api_lasttime = millis();
}
}
}
// Code from The Swedish Maker
// https://www.youtube.com/@TheSwedishMaker
String num_format(long num){
String num_s;
long num_original = num;
if (num>99999 && num<=999999){
num = num / 1000;
long fraction = num_original%1000;
String num_fraction = String(fraction);
String decimal = num_fraction.substring(0,1);
num_s = String(num) + "." + decimal + "K";
}
else if(num>999999){
num = num / 1000000;
long fraction = num_original%1000000;
String num_fraction = String(fraction);
String decimal = num_fraction.substring(0,1);
if (num_original<100000000){
num_s = " " + String(num) + "." + decimal + "M";
}
else{
num_s = String(num) + "." + decimal + "M";
}
}
else{
int num_l = String(num).length();
char num_f[15];
int blankDigits = 6 - num_l;
for(int i = 0; i < blankDigits; i++){
num_f[i] = ' ';
}
num_f[blankDigits] = '\0';
num_s = num_f + String(num);
}
return num_s;
}
the error said no wifi detected in scope
Please post the complete error message.
docdoc
March 7, 2025, 9:19am
3
...I would also ask him to add a connection diagram, since I see several libraries included, and there might be hardware or library conflicts.
I watched a video and the guy didn’t connect anything and just programed the esp32 dev board
here is the error message
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino: In function 'void setup()':
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino:48:3: error: 'WiFi' was not declared in this scope
48 | WiFi.begin(SECRET_SSID, SECRET_PASS);
| ^~~~
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino:50:27: error: 'WL_CONNECTED' was not declared in this scope
50 | while (WiFi.status() != WL_CONNECTED) {
| ^~~~~~~~~~~~
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino: In function 'void loop()':
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino:68:7: error: 'WiFi' was not declared in this scope
68 | if (WiFi.status() == WL_CONNECTED) {
| ^~~~
/Users/timurkarpikov/Downloads/SubscriberCounter_sketch/SubscriberCounter_sketch.ino:68:24: error: 'WL_CONNECTED' was not declared in this scope
68 | if (WiFi.status() == WL_CONNECTED) {
| ^~~~~~~~~~~~
exit status 1
Compilation error: 'WiFi' was not declared in this scope
docdoc
March 7, 2025, 3:13pm
6
The message looks pretty clear to me, the "WiFi" object hasn't been declared.
Where does the WiFi library have been referenced at?
I mean a line like this (to be added before the "WiFiClientSecure.h" line):
#include <WiFi.h>
Btw IMO the whole code looks like to be a kinda "mix" of source: have you really written that code on your own, or it's kinda "mixed" code or, even worse, it's an AI-generated/ChatGPT "blob"?
1 Like
```cpp
// Library Imports
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <HTTPClient.h>
#include <string>
// File imports
#include "secrets.h"
#include "FontSubs.h"
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
#define MAX_DEVICES 4
#define CS_PIN 5
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
WiFiClientSecure client;
unsigned long api_mtbs = 10000; // Change length of time before the next API call (Default: 10,000 -> 10 sec)
unsigned long api_lasttime;
long subs = 0;
long views = 0;
String apiUrl = "";
StaticJsonDocument<1000> doc;
bool showSubs = false;
void setup() {
// Start Console
Serial.begin(9600);
// Setup screen,
Display.begin();
Display.setIntensity(0);
Display.setFont(fontSubs);
Display.setTextAlignment(PA_CENTER);
// Connect to wifi
Serial.print("Connecting to Wifi...");
WiFi.begin(SECRET_SSID, SECRET_PASS);
Display.print(" WiFi...");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println(WiFi.localIP());
Display.print("Connected");
delay(2000);
// Start process of getting data
Display.displayClear();
Display.print("fetching");
delay(250);
client.setInsecure();
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (millis() - api_lasttime > api_mtbs) {
// Instantiate http client
// We use http client instead of YoutubeApi.h library to allow us to fetch data from any site in future
HTTPClient http;
// Convert the C-style strings to std::string objects
std::string channelID(SECRET_CHANNELID);
std::string apiKey(SECRET_APIKEY);
// Create Api URL
apiUrl = ("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + channelID + "&key=" + apiKey).c_str();
// Run API call and get status code
http.begin(apiUrl);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, payload);
// Test if parsing succeeds.
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
// Display Sub or View count
Serial.print(payload);
if(showSubs) {
subs = doc["items"][0]["statistics"]["subscriberCount"];
String subsCount = num_format(subs);
Serial.println(subsCount);
Display.print("*" + subsCount);
}else{
views = doc["items"][0]["statistics"]["viewCount"];
String viewsCount = num_format(views);
Serial.println(viewsCount);
Display.print("*" + viewsCount);
}
// Change from subs to views
showSubs = !showSubs;
}
api_lasttime = millis();
}
}
}
// Code from The Swedish Maker
// https://www.youtube.com/@TheSwedishMaker
String num_format(long num){
String num_s;
long num_original = num;
if (num>99999 && num<=999999){
num = num / 1000;
long fraction = num_original%1000;
String num_fraction = String(fraction);
String decimal = num_fraction.substring(0,1);
num_s = String(num) + "." + decimal + "K";
}
else if(num>999999){
num = num / 1000000;
long fraction = num_original%1000000;
String num_fraction = String(fraction);
String decimal = num_fraction.substring(0,1);
if (num_original<100000000){
num_s = " " + String(num) + "." + decimal + "M";
}
else{
num_s = String(num) + "." + decimal + "M";
}
}
else{
int num_l = String(num).length();
char num_f[15];
int blankDigits = 6 - num_l;
for(int i = 0; i < blankDigits; i++){
num_f[i] = ' ';
}
num_f[blankDigits] = '\0';
num_s = num_f + String(num);
}
return num_s;
}
docdoc
March 10, 2025, 9:47am
10
meansmydog:
its from YouTube
Ok, but never, ever, trust 100% what you find googling around, especially from unknow sites, forums, Youtube, and ChatGPT! You can't (shouldn't) get a code and project thinking you can use it kinda plug-and-play, because it often needs either a customization (e.g. different addresses, pins, etc) or a double check: in both case it means you must know what you're doing , to be able to identify any errors made by the author. And in this specific case the error message you reported here clearly tells you what's going on and, implicitly, what you need to do to correct this issue.
I'm telling you this because I hope it should help you to better understand that you need to make more practice and study, and avoid taking code found around as a Bible. Read the code, try to understand what it does and how, then you can start using it.
meansmydog:
it works now thanks
Good. It seems you just added the top #include line, right?
system
Closed
September 13, 2025, 2:59am
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.