Advertisement
Guest User

Instagram Stats

a guest
Feb 1st, 2019
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. /*******************************************************************
  2. An example of usisng the InstagramStats library to get
  3. info on a given user.
  4.  
  5. Written by Brian Lough
  6. https://www.youtube.com/channel/UCezJOfu7OtqGzd5xrP3q6WA
  7.  
  8. modified to use MD_MAX72XX by noiasca
  9. http://forum.arduino.cc/index.php?topic=588536.0
  10.  
  11. Version
  12. 2019-01-05 20:00 OTA, Fixtextausgabe
  13. 2019-01-04 20:30 Erste funktionierende Version mit MD_MAX72XX
  14.  
  15. *******************************************************************/
  16.  
  17. //------- Replace the following! ------
  18. const char ssid[] = "xxxxx"; // your network SSID (name)
  19. const char password[] = "xxxxx"; // your network key
  20. String userName = "xxxxx"; // from their instagram url xxxxx
  21.  
  22. //------- some Parameters you can modify ------
  23. const uint32_t delayBetweenChecks = 60000; // mean time between api requests
  24.  
  25. // ----------------------------
  26. // Standard Libraries - Already Installed if you have ESP8266 set up
  27. // ----------------------------
  28.  
  29. #include <ESP8266WiFi.h>
  30. #include <WiFiClientSecure.h>
  31.  
  32. // ----------------------------
  33. // Additional Libraries - each one of these will need to be installed.
  34. // ----------------------------
  35.  
  36. #include <JsonStreamingParser.h>
  37. // Used to parse the Json code within the library
  38. // Available on the library manager (Search for "Json Streamer Parser")
  39. // https://github.com/squix78/json-streaming-parser
  40.  
  41. #include <MD_MAX72xx.h> // MD_MAX72XX by majicDesigns Version 3.0.2 - installed with library Manager
  42.  
  43. const int DATA_PIN = D8; // MISSING <-- hier ganz wichtig die richtigen PINs setzen vieleicht hast du hier 15/D8
  44. const int CLK_PIN = D6; // MISSING <-- hier ganz wichtig die richtigen PINs setzen vieleicht hast du hier 12/D6
  45. const int CS_PIN = D7; // MISSING <-- hier ganz wichtig die richtigen PINs setzen vieleicht hast du hier 13/D7
  46. // MISSING: ganz wichtig in den Zeilen darunter die richtige Hardware einsetzen. Das ist eine der vier Optionen:
  47. #define HARDWARE_TYPE MD_MAX72XX::FC16_HW // < Use FC-16 style hardware module.
  48. //#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW // < Use the Parola style hardware modules.
  49. //#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW // < Use 'generic' style hardware modules commonly available.
  50. //#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW // < Use ICStation style hardware module.
  51.  
  52. const uint8_t DELAYTIME = 100; // in milliseconds
  53. const int MAX_DEVICES = 4;
  54. #include <SPI.h> // needed by MD_MAX72XX
  55. // Arbitrary pins
  56. MD_MAX72XX mx(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  57.  
  58. WiFiClientSecure client;
  59. #include "InstagramStats.h"
  60. unsigned long previousCheck = 0;
  61. InstagramStats instaStats(client);
  62.  
  63. //Maximal 32 Stellen!!! 123456789a123456789b123456789c12 - Sonst geht der Rauch auf!
  64. const char *fixtext[] = {"Meine Follower: ", // Fixtext[0] ist der Präfix für den Counter
  65. "Das ist ein Fixtext", // weitere Texte können definiert werden
  66. "Das ist noch ein Text",
  67. "und noch einer" // genau schauen: beim letzten gibt es kein Komma mehr
  68. };
  69. const byte noOfFixtext = sizeof(fixtext) / sizeof(fixtext[0]); // Anzahl der obigen Fixtexte. Nicht hardcoded damit man das nicht manuell warten muss (und dann sowieso vergisst.
  70. uint32_t previousFixtext = 10; // store millis of last call
  71. const uint32_t delayBetweenFixtext = 4000; // Anzeigedauer zwischen den Fixtexten
  72. uint32_t mycounts = 0; // die ermittelten Follower werden in einer globalen Variable gespeichert
  73.  
  74. #include <ArduinoOTA.h> // OTA Upload via ArduinoIDE
  75.  
  76. void do_textausgabe() {
  77. // Gibt der Reihen nach einen der vordefinierten Texte oder die Follower aus
  78. //
  79. static byte currentFixtext = 1;
  80. Serial.print (F("do_textausgabe:")); Serial.println(currentFixtext);
  81. if (currentFixtext == 0) // von 0 bis n geben wir die definierten Fixtexte aus
  82. {
  83. char buf[32];
  84. char val[32]; // buffer zum umwandeln der Zahl
  85. strcpy(buf, fixtext[0]); // Fixtext[0] ist der Präfix für den Counter
  86. itoa(mycounts, val, 10);
  87. strcat(buf, val);
  88. scrollText(buf);
  89. }
  90. else
  91. {
  92. scrollText(fixtext[currentFixtext]);
  93. }
  94. currentFixtext++;
  95. if (currentFixtext >= noOfFixtext) currentFixtext = 0;
  96. }
  97.  
  98. /* *******************************************************************
  99. F U N C T I O N S
  100. ********************************************************************/
  101.  
  102. void getInstagramStatsForUser() {
  103. Serial.print (F("Getting instagram user stats for "));
  104. Serial.println (userName);
  105. InstagramUserStats response = instaStats.getUserStats(userName);
  106. Serial.println(F("Response:"));
  107. Serial.print(F("Number of followers: "));
  108. Serial.println(response.followedByCount);
  109. mycounts = response.followedByCount;
  110. }
  111.  
  112. void scrollText(const char *p) // Fast 1:1 entnommen aus den Beispielen der MD_MAX72XX
  113. {
  114. uint8_t charWidth;
  115. uint8_t cBuf[8]; // this should be ok for all built-in fonts
  116. //Serial.println(F("D101 Scrolling text"));
  117. mx.clear();
  118. while (*p != '\0')
  119. {
  120. charWidth = mx.getChar(*p++, sizeof(cBuf) / sizeof(cBuf[0]), cBuf);
  121. for (uint8_t i = 0; i <= charWidth; i++) // allow space between characters
  122. {
  123. mx.transform(MD_MAX72XX::TSL);
  124. if (i < charWidth)
  125. mx.setColumn(0, cBuf[i]);
  126. delay(DELAYTIME);
  127. }
  128. }
  129. }
  130.  
  131. /* *******************************************************************
  132. S E T U P
  133. ********************************************************************/
  134. void setup() {
  135. Serial.begin(115200);
  136. Serial.println(F("Instagramm Abfrager"));
  137. mx.begin();
  138. scrollText("ARE YOU READY");
  139. // Set WiFi to station mode and disconnect from an AP if it was Previously
  140. // connected
  141. WiFi.mode(WIFI_STA);
  142. WiFi.disconnect();
  143. delay(100);
  144. // Attempt to connect to Wifi network:
  145. Serial.print(F("Connecting Wifi: "));
  146. Serial.println(ssid);
  147. WiFi.begin(ssid, password);
  148. while (WiFi.status() != WL_CONNECTED) {
  149. Serial.print(F("."));
  150. delay(500);
  151. }
  152. scrollText("WLAN VERBUNDEN"); // connected
  153. Serial.println(F("\nWiFi connected"));
  154. Serial.println(F("IP address: "));
  155. IPAddress ip = WiFi.localIP();
  156. Serial.println(ip);
  157. Serial.print(F("Defined number of fixtext:")); Serial.println(noOfFixtext);
  158. previousCheck = millis() - delayBetweenChecks + 3000; // damit in etwa 3 Sekunden der erste Request gemacht wird
  159. ArduinoOTA.begin(); // OTA Upload via ArduinoIDE
  160. }
  161.  
  162. /* *******************************************************************
  163. M A I N L O O P
  164. ********************************************************************/
  165. void loop() {
  166. unsigned long timeNow = millis();
  167. if ((timeNow - previousCheck >= delayBetweenChecks)) { // umgebaut gem. BlinkWithoutDelay wegen Rollover nach 42 Tagen.
  168. getInstagramStatsForUser();
  169. previousCheck = timeNow;
  170. }
  171. if ((timeNow - previousFixtext >= delayBetweenFixtext)) {
  172. do_textausgabe();
  173. previousFixtext = millis(); // Wir rechnen den Intervall ab ENDE der Fixtextausgabe.
  174. }
  175.  
  176. ArduinoOTA.handle(); // OTA Upload via ArduinoIDE
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement