#include #include #include #include #include // Include the Wi-Fi library #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) // The pins for I2C are defined by the Wire-library. // On an arduino UNO: A4(SDA), A5(SCL) // On an arduino MEGA 2560: 20(SDA), 21(SCL) // On an arduino LEONARDO: 2(SDA), 3(SCL), ... #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define TASKER_MAX_TASKS 4 #include "Tasker.h" HTTPClient http; WiFiClient client; Tasker tasker; const char* ssid = "Aurora"; // The SSID (name) of the Wi-Fi network you want to connect to const char* password = "***"; // The password of the Wi-Fi network const char* URL_SITON = "http://10.22.128.244/metrics"; const char* URL_TEMP = "http://10.22.128.184/metrics"; int vykon; bool priorita; float teplota; bool isTeplotaVisible = true; void setup() { // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { for (;;); // Don't proceed, loop forever } WiFi.begin(ssid, password); // Connect to the network while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect delay(1000); } // Clear the buffer display.clearDisplay(); // Show the display buffer on the screen. You MUST call display() after // drawing commands to make them visible on screen! display.display(); getData(); renderDisplay(); tasker.setInterval(getData, 10000); tasker.setInterval(renderDisplay, 500); } void getData() { getSitonData(&vykon, &priorita); getTeplota(&teplota); } void renderDisplay() { display.clearDisplay(); display.setRotation(2); if (priorita) { display.fillRect(0, 0, display.width(), display.height() / 2, SSD1306_WHITE); display.setTextColor(SSD1306_BLACK); } else { display.setTextColor(SSD1306_WHITE); } display.setTextSize(3); // Normal 1:1 pixel scale String vykonString = (vykon >= 1000 ? String((float)vykon / 1000) : String((int)vykon)) + (vykon >= 1000 ? " kW" : " W"); const char* text1 = vykonString.c_str(); int16_t x1, y1; uint16_t w1, h1; display.getTextBounds(text1, 0, 0, &x1, &y1, &w1, &h1); display.setCursor((display.width() - w1) / 2, (display.height() / 2 - h1) / 2); // Start at top-left corner display.println(text1); display.setTextSize(2); // Normal 1:1 pixel scale if (isTeplotaVisible) { display.setTextColor(SSD1306_WHITE); // Draw 'inverse' text } else { display.setTextColor(SSD1306_BLACK); // Draw 'inverse' text } String teplotaString = String(teplota) + (char)247 + "C"; const char* text2 = teplotaString.c_str(); int16_t x2, y2; uint16_t w2, h2; display.getTextBounds(text2, 0, 0, &x2, &y2, &w2, &h2); display.setCursor((display.width() - w2) / 2, display.height() - h2); // Start at top-left corner display.println(text2); display.display(); !priorita?isTeplotaVisible=true:isTeplotaVisible = !isTeplotaVisible; } void loop() { tasker.loop(); /* display.clearDisplay(); if (priorita) { display.fillRect(0, 0, display.width(), display.height() / 2, SSD1306_WHITE); display.setTextColor(SSD1306_BLACK); } else { display.setTextColor(SSD1306_WHITE); } display.setTextSize(3); // Normal 1:1 pixel scale String vykonString = (vykon >= 1000 ? String((float)vykon / 1000) : String((int)vykon)) + (vykon >= 1000 ? " kW" : " W"); const char* text1 = vykonString.c_str(); int16_t x1, y1; uint16_t w1, h1; display.getTextBounds(text1, 0, 0, &x1, &y1, &w1, &h1); display.setCursor((display.width() - w1) / 2, (display.height() / 2 - h1) / 2); // Start at top-left corner display.println(text1); display.setTextSize(2); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw 'inverse' text String teplotaString = String(teplota) + (char)247 + "C"; const char* text2 = teplotaString.c_str(); int16_t x2, y2; uint16_t w2, h2; display.getTextBounds(text2, 0, 0, &x2, &y2, &w2, &h2); display.setCursor((display.width() - w2) / 2, display.height() - h2); // Start at top-left corner display.println(text2); display.display(); delay(15000); */ } void getSitonData(int* vykon, bool* priorita) { http.begin(client, URL_SITON); int httpCode = http.GET(); if (httpCode != 200) { *vykon = -1; *priorita = 0; } String vykonString = http.getString(); vykonString = vykonString.substring(vykonString.indexOf('v')); vykonString = vykonString.substring(0, vykonString.indexOf('\n')); *vykon = vykonString.substring(vykonString.indexOf(' ')).toInt(); String prioritaString = http.getString(); prioritaString = prioritaString.substring(prioritaString.indexOf('r')); prioritaString = prioritaString.substring(prioritaString.indexOf('i')); prioritaString = prioritaString.substring(prioritaString.indexOf('o')); prioritaString = prioritaString.substring(prioritaString.indexOf('r')); prioritaString = prioritaString.substring(prioritaString.indexOf('i')); prioritaString = prioritaString.substring(prioritaString.indexOf('t')); prioritaString = prioritaString.substring(prioritaString.indexOf('a')); prioritaString = prioritaString.substring(0, prioritaString.indexOf('\n')); *priorita = prioritaString.substring(prioritaString.indexOf(' ')).toInt(); } void getTeplota(float* teplota) { // ZĂ­skat data z Node Exporter http.begin(client, URL_TEMP); int httpCode = http.GET(); if (httpCode != 200) { *teplota = -1; } String data = http.getString(); data = data.substring(data.indexOf('2')); data = data.substring(data.indexOf('8')); data = data.substring(data.indexOf('f')); data = data.substring(data.indexOf('f')); data = data.substring(data.indexOf('4')); data = data.substring(data.indexOf('8')); data = data.substring(data.indexOf('9')); data = data.substring(data.indexOf('f')); data = data.substring(data.indexOf('5')); data = data.substring(0, data.indexOf('\n')); *teplota = data.substring(data.indexOf(' ')).toFloat(); }