Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CODE: Levente Daradici
- // https://youtu.be/W6XjNbb6O5A
- // my YouTube channel: https://www.youtube.com/@LeventeDaradici/videos
- // my pastebins: https://pastebin.com/u/LeventeDaradici
- //
- // The complete code includes 6 files with the following names:
- // PiconXMLfromRemoteServer.ino
- // miniz.c -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/miniz.c
- // miniz.h -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/miniz.h
- // pngle.c -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/pngle.c
- // pngle.h -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/pngle.h
- // support_functions.h -- from Bodmer's example --
- // https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/support_functions.h
- //
- #include <TFT_eSPI.h>
- TFT_eSPI tft = TFT_eSPI();
- #include <HTTPClient.h>
- #include <SPI.h>
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include "NTPClient.h"
- #define USE_LINE_BUFFER
- #include "support_functions.h"
- WiFiClient client;
- const char* ssid = "YourWifiSSID"; //YOUR WIFI NETWORK SSID
- const char* password = "YourWifiPASSWORD"; //YOUR WIFI NETWORK PASSWORD
- const char* host = "192.168.x.xxx"; //YOUR SET TOP BOX IP
- const char* path = "/web/getcurrent"; //NAME OF THE FILE FROM WHICH WE EXTRACT THE DATA.
- const long utcOffsetInSeconds = 10800;
- String LinkCanalCurent, NumeCanalNouPrelucrat, NumeCanalVechi, NumeCanalNou, EPGacumVECHI, EPGacumNOU, EPGacumVECHI2, EPGacumNOU2, AfisareEPG, AfisareEPG2, AfisareDESC, AfisareDESC2, AfisareEPGtotal,AfisareDescriereEPG,AfisareDescriereEPG2 = " ";
- int Conexiune, Pozitie, EPGacum, DescriereACUM, DescriereACUMepg = 0;
- String NumeCanalCurent ="Nume Canal Curent";
- String NumeEmisiuneCurenta ="Nume Emisiune Curenta";
- String EpgEmisiuneCurenta ="EPG Emisiune Curenta";
- String OraExacta ="22:26:35";
- String NumeProvider ="Digi Tv / RCS & RDS";
- String RezolutieCanal ="1920x1080";
- int PozitieX = 321;
- unsigned long startMillis;
- unsigned long currentMillis;
- const unsigned long period = 500;
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
- void setup()
- {
- Serial.begin(115200);
- delay(500);
- tft.init();
- tft.setRotation(3);
- tft.fillScreen(0);
- EPGacum = 1;
- DescriereACUM = 1;
- DescriereACUMepg = 1;
- WiFi.begin(ssid, password);
- Serial.print("Connecting to WiFi");
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.println();
- Serial.println("Connected to WiFi");
- delay(2000);
- Conexiune == 1;
- timeClient.begin();
- startMillis = millis();
- }
- void loop()
- {
- timeClient.update();
- tft.setTextSize(1);
- tft.setTextColor(TFT_CYAN, TFT_BLACK);
- OraExacta = timeClient.getFormattedTime();
- Serial.println(OraExacta);
- tft.drawString(OraExacta, 247, 2, 2);
- WiFiClient client;
- if (!client.connect(host, 80))
- {
- Serial.println("NOT CONNECTED TO");
- Serial.println("ENIGMA2 RECEIVER!");
- Conexiune = 0;
- return;
- } else
- if (Conexiune == 0)
- {
- Serial.println("CONNECTED TO");
- Serial.println("ENIGMA2 RECEIVER");
- delay(1);
- Conexiune = 1;
- NumeCanalVechi = " ";
- EPGacumVECHI = " ";
- EPGacum = 1;
- }
- Serial.println("");
- String url = String(path);
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- while(!client.available())
- {
- delay(1);
- }
- String line;
- while (client.available())
- {
- line = client.readStringUntil('\n');
- if (line.indexOf("e2servicename") >= 0)
- {
- int startIndex = line.indexOf(">") + 1;
- int endIndex = line.indexOf("<", startIndex);
- String e2servicename = line.substring(startIndex, endIndex);
- NumeCanalNou = e2servicename ;
- if (NumeCanalVechi != NumeCanalNou)
- {
- NumeCanalNouPrelucrat = NumeCanalNou;
- NumeCanalNouPrelucrat.toLowerCase();
- NumeCanalNouPrelucrat.replace(" ", "");
- LinkCanalCurent = "http://" + String(host) + "/picon/" + NumeCanalNouPrelucrat + ".png";
- tft.fillRect(0,0,232,134, TFT_BLUE);
- tft.fillRect(1,1,230,132,TFT_BLACK);
- setPngPosition(6, 1);
- const char* urlCanalCurent = LinkCanalCurent.c_str();
- load_png(urlCanalCurent);
- tft.setTextSize(2);
- tft.setTextColor(TFT_RED, TFT_BLACK);
- tft.drawString(NumeCanalNou + " ", 5, 134, 2);
- tft.setTextSize(2);
- tft.setTextColor(TFT_BLUE, TFT_BLACK);
- //tft.drawString("ACUM", 150, 80, 2);
- //tft.drawString("EPG", 3, 144, 2);
- NumeCanalVechi = NumeCanalNou;
- PozitieX = 321;
- }
- Serial.println("Canal: " + e2servicename);
- } else if (line.indexOf("e2providername") >= 0)
- {
- int startIndex = line.indexOf(">") + 1;
- int endIndex = line.indexOf("<", startIndex);
- String e2providername = line.substring(startIndex, endIndex);
- NumeProvider = e2providername;
- tft.setTextSize(1);
- tft.setTextColor(TFT_YELLOW, TFT_BLACK);
- tft.drawString(NumeProvider + + " ", 237, 100, 2);
- Serial.println("Provider: " + e2providername);
- }
- else if (line.indexOf("e2servicevideosize") >= 0)
- {
- int startIndex = line.indexOf(">") + 1;
- int endIndex = line.indexOf("<", startIndex);
- String e2servicevideosize = line.substring(startIndex, endIndex);
- tft.setTextSize(1);
- tft.setTextColor(TFT_YELLOW, TFT_BLACK);
- tft.drawString(e2servicevideosize + " ", 237, 116, 2);
- Serial.println("Rezolutie: " + e2servicevideosize);
- }
- else if (line.indexOf("e2eventname") >= 0)
- {
- int startIndex = line.indexOf(">") + 1;
- int endIndex = line.indexOf("<", startIndex);
- String e2eventname = line.substring(startIndex, endIndex);
- if (EPGacum == 1)
- {
- AfisareEPG = e2eventname;
- tft.setTextSize(1);
- tft.setTextColor(TFT_GREEN, TFT_BLACK);
- tft.drawString(AfisareEPG + " ", 5, 167, 2);
- }
- if (EPGacum == 2) AfisareEPG2 = e2eventname;
- EPGacum = EPGacum + 1;
- if (EPGacum > 2) EPGacum = 1;
- }
- else if (line.indexOf("e2eventdescription") >= 0)
- {
- int startIndex = line.indexOf(">") + 1;
- int endIndex = line.indexOf("<", startIndex);
- String e2eventdescription = line.substring(startIndex, endIndex);
- if (DescriereACUM > 4) DescriereACUM = 1;
- if (DescriereACUM == 1) AfisareDESC = e2eventdescription;
- if (DescriereACUM == 2) AfisareDescriereEPG = e2eventdescription;
- if (DescriereACUM == 3) AfisareDESC2 = e2eventdescription;
- if (DescriereACUM == 4) AfisareDescriereEPG2 = e2eventdescription;
- tft.setTextSize(1);
- tft.setTextColor(TFT_YELLOW, TFT_BLACK);
- tft.drawString(AfisareDESC.substring(0, 45) + " ", 5, 184, 2);
- tft.drawString(AfisareDESC.substring(45,90) + " ", 5, 200, 2);
- tft.drawString(AfisareDESC.substring(90,135) + " ", 5, 216, 2);
- tft.setTextColor(TFT_GREEN, TFT_BLACK);
- //tft.drawString(AfisareDescriereEPG+ " ", PozitieX, 216, 2);
- // tft.drawString(AfisareDescriereEPG.substring(48, 98) + " ", 0, 192, 2);
- // tft.drawString(AfisareDescriereEPG.substring(98, 148) + " ", 0, 208, 2);
- // tft.drawString(AfisareDescriereEPG.substring(148, 198) + " ", 0, 224, 2);
- DescriereACUM = DescriereACUM + 1;
- }
- }
- client.stop();
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement