- #ifdef ESP32
- #include <DNSServer.h>
- #include <WebServer.h>
- #include <WiFi.h>
- #else
- #include <DNSServer.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266WiFi.h>
- #endif
- #include <WiFiManager.h>
- #include <Adafruit_GFX.h>
- #include <Max72xxPanel.h>
- #include <ESP8266HTTPClient.h>
- #include <ArduinoJson.h>
- int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
- int numberOfHorizontalDisplays = 4;
- int numberOfVerticalDisplays = 1;
- DynamicJsonBuffer jsonBuffer;
- // LED Matrix Pin -> ESP8266 Pin
- // Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS)
- // Gnd -> Gnd (G on NodeMCU)
- // DIN -> D7 (Same Pin for WEMOS)
- // CS -> D4 (Same Pin for WEMOS)
- // CLK -> D5 (Same Pin for WEMOS)
- Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
- int wait = 100; // In milliseconds
- int zaehler = -1;
- // https://www.finanzen.net/aktien/Tesla-Aktie
- char* coins[] = {"share:Tesla-Aktie", "share:BVB-Aktie", "bitcoin", "ethereum", "dash", "pivx", "verge"};
- String text = "CONNECTING...";
- String coin = "";
- String coinText = "";
- String coinSymbol = "";
- int arraySize = 0;
- int spacer = 1;
- int width = 5 + spacer; // The font width is 5 pixels
- void setup() {
- Serial.begin(115200);
- WiFi_Setup();
- matrix.setIntensity(0); // Use a value between 0 and 15 for brightness
- matrix.setRotation(0, 1); // The first display is position upside down
- matrix.setRotation(1, 1); // The first display is position upside down
- matrix.setRotation(2, 1); // The first display is position upside down
- matrix.setRotation(3, 1); // The first display is position upside down
- }
- void loop() {
- matrix.fillScreen(LOW);
- Serial.println(zaehler);
- if (zaehler == -1) {
- display_message(text);
- delay(2000);
- zaehler = 1;
- }
- else if (zaehler == 0) {
- zaehler = 10;
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- text = "";
- arraySize = sizeof(coins) / sizeof(char *);
- for (int i = 0; i < arraySize; i++) {
- coin = String(coins[i]);
- coinText = "";
- coinSymbol = "";
- Serial.println(i);
- http.begin("http://coin.blessuren.de/get.php?coin=" + coin);
- int httpCode = http.GET();
- if (httpCode > 0) {
- coinText = http.getString();
- if(coin.indexOf(':') < 0) {
- JsonArray& array = jsonBuffer.parseArray(coinText);
- JsonObject& root = jsonBuffer.parseObject(array.get<String>(0));
- coinText = root["price_usd"].as<String>(); // or price_eur
- coinSymbol = root["symbol"].as<String>();
- coinText = coinSymbol + ":$" + coinText.substring(0, coinText.indexOf('.') + 3); // 4 = 3 digits after . 3 = 2 digits after .
- jsonBuffer.clear();
- }
- }
- else {
- text = "HTTPS Error";
- }
- http.end();
- text = text + ' ' + coinText;
- }
- }
- }
- zaehler--;
- display_message(text);
- }
- void display_message(String message) {
- for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
- //matrix.fillScreen(LOW);
- int letter = i / width;
- int x = (matrix.width() - 1) - i % width;
- int y = (matrix.height() - 8) / 2; // center the text vertically
- while ( x + width - spacer >= 0 && letter >= 0 ) {
- if ( letter < message.length() ) {
- matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image
- }
- letter--;
- x -= width;
- }
- matrix.write(); // Send bitmap to display
- delay(wait / 2);
- }
- }
- void WiFi_Setup() {
- WiFiManager wifiManager; // Connect to Wi-Fi
- // A new OOB ESP has no Wi-Fi credentials so will connect and not need the next command to be uncommented and compiled in, a used one with incorrect credentials will
- // so restart the ESP and connect your PC to the wireless access point called 'ESP_AP' or whatever you call it below in ""
- // wifiManager.resetSettings(); // Command to be included if needed, then connect to http://192.168.4.1/ and follow instructions to make the WiFi connection
- // Set a timeout until configuration is turned off, useful to retry or go to sleep in n-seconds
- wifiManager.setTimeout(180);
- //fetches ssid and password and tries to connect, if connections succeeds it starts an access point with the name called "ESP8266_AP" and waits in a blocking loop for configuration
- if (!wifiManager.autoConnect("ESP_AP")) {
- Serial.println(F("failed to connect and timeout occurred"));
- delay(6000);
- ESP.restart(); //reset and try again
- }
- // At this stage the WiFi manager will have successfully connected to a network, or if not will try again in 180-seconds
- Serial.println(F("WiFi connected..."));
- //----------------------------------------------------------------------
- Serial.println(F("Use this URL to connect: http://")); Serial.println(WiFi.localIP().toString() + "/"); // Print the IP address
- }
Untitled
From Scribby Rhinoceros, 7 Years ago, written in Plain Text, viewed 2 times.
URL https://paste.blessuren.de/view/a8d0972d
Embed
Download Paste or View Raw
— Expand Paste to full width of browser