· 4 years ago · Mar 19, 2021, 08:50 PM
1#include "InstagramStats.h"
2#include <ESP8266WiFi.h>
3#include <WiFiClientSecure.h>
4#include <MD_Parola.h>
5#include <MD_MAX72xx.h>
6#include <SPI.h>
7#include "JsonStreamingParser.h"
8
9#define MAX_DEVICES 4
10#define CLK_PIN D5
11#define DATA_PIN D7
12#define CS_PIN D6
13
14#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
15
16MD_Parola msg = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES);
17
18//------- Replace the following! ------
19char ssid[] = "xxxxx"; // your network SSID (name)
20char password[] = "xxxxx"; // your network key
21
22WiFiClientSecure client;
23InstagramStats instaStats(client);
24
25unsigned long delayBetweenChecks = 15 * 60000; //mean time between api requests - 15 minutes
26unsigned long whenDueToCheck = 0;
27
28//Inputs
29String userName = "xxxxxxxx"; // your instagram name account
30
31void setup() {
32
33 Serial.begin(115200);
34
35 // Set WiFi to station mode and disconnect from an AP if it was Previously
36 // connected
37 WiFi.mode(WIFI_STA);
38 WiFi.disconnect();
39 delay(100);
40
41 // 8x8 Matrix Display
42 msg.begin();
43 msg.displayText("",PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
44
45 // Attempt to connect to Wifi network:
46 msg.print("Wifi");
47 delay(2000);
48 Serial.print("Connecting Wifi: ");
49 Serial.println(ssid);
50 WiFi.begin(ssid, password);
51 String point;
52 while (WiFi.status() != WL_CONNECTED) {
53 point += ".";
54 msg.print(point);
55 delay(500);
56 }
57 Serial.println("");
58 Serial.println("WiFi connected");
59 msg.print("WiFi ok!");
60 delay(1500);
61 Serial.println("IP address: ");
62 IPAddress ip = WiFi.localIP();
63 Serial.println(ip);
64
65 client.setInsecure();
66}
67
68void getInstagramStatsForUser() {
69
70 Serial.println("Getting instagram user stats for " + userName );
71 InstagramUserStats response = instaStats.getUserStats(userName);
72 Serial.println("Response:");
73 Serial.print("Number of followers: ");
74 Serial.println(response.followedByCount);
75
76
77 msg.print(response.followedByCount);
78}
79
80void loop() {
81 unsigned long timeNow = millis();
82 if ((timeNow > whenDueToCheck)) {
83 getInstagramStatsForUser();
84 whenDueToCheck = timeNow + delayBetweenChecks;
85 }
86 // 8x8 Matrix Display
87 msg.displayAnimate();
88}