Advertisement
LeventeDaradici

How To ExtractingAndDisplayingOnTFT_eSPIdisplayPiconsAndDataFromXMLfilesFromAremoteServer

May 11th, 2023 (edited)
2,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.25 KB | Source Code | 0 0
  1. //
  2. // CODE: Levente Daradici
  3. // https://youtu.be/W6XjNbb6O5A
  4. // my YouTube channel: https://www.youtube.com/@LeventeDaradici/videos
  5. // my pastebins: https://pastebin.com/u/LeventeDaradici
  6. //
  7. // The complete code includes 6 files with the following names:
  8. //      PiconXMLfromRemoteServer.ino
  9. //      miniz.c -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/miniz.c
  10. //      miniz.h -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/miniz.h
  11. //      pngle.c -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/pngle.c
  12. //      pngle.h -- from Bodmer's example -- https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/pngle.h
  13. //      support_functions.h -- from Bodmer's example --
  14. //                              https://github.com/Bodmer/PNG_TEST_ONLY/blob/master/png_test_url_spiffs_2x/support_functions.h
  15. //
  16.  
  17. #include <TFT_eSPI.h>
  18. TFT_eSPI tft = TFT_eSPI();
  19. #include <HTTPClient.h>
  20. #include <SPI.h>
  21. #include <WiFi.h>
  22. #include <WiFiClient.h>
  23. #include "NTPClient.h"
  24. #define USE_LINE_BUFFER
  25. #include "support_functions.h"
  26.  
  27. WiFiClient client;
  28. const char* ssid = "YourWifiSSID";           //YOUR WIFI NETWORK SSID
  29. const char* password = "YourWifiPASSWORD";     //YOUR WIFI NETWORK PASSWORD
  30.  
  31. const char* host = "192.168.x.xxx";       //YOUR SET TOP BOX IP
  32. const char* path = "/web/getcurrent";     //NAME OF THE FILE FROM WHICH WE EXTRACT THE DATA.
  33. const long utcOffsetInSeconds = 10800;
  34.  
  35. String LinkCanalCurent, NumeCanalNouPrelucrat, NumeCanalVechi, NumeCanalNou, EPGacumVECHI, EPGacumNOU, EPGacumVECHI2, EPGacumNOU2, AfisareEPG, AfisareEPG2, AfisareDESC, AfisareDESC2,  AfisareEPGtotal,AfisareDescriereEPG,AfisareDescriereEPG2  = " ";
  36. int Conexiune, Pozitie, EPGacum, DescriereACUM, DescriereACUMepg = 0;
  37.  
  38. String NumeCanalCurent ="Nume Canal Curent";
  39. String NumeEmisiuneCurenta ="Nume Emisiune Curenta";
  40. String EpgEmisiuneCurenta ="EPG Emisiune Curenta";
  41. String OraExacta ="22:26:35";
  42. String NumeProvider ="Digi Tv / RCS & RDS";
  43. String RezolutieCanal ="1920x1080";
  44.  
  45. int PozitieX = 321;
  46.  
  47. unsigned long startMillis;
  48. unsigned long currentMillis;
  49. const unsigned long period = 500;  
  50.  
  51. WiFiUDP ntpUDP;
  52. NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
  53.  
  54.      void setup()
  55.           {
  56.             Serial.begin(115200);
  57.             delay(500);
  58.             tft.init();
  59.             tft.setRotation(3);
  60.             tft.fillScreen(0);
  61.             EPGacum = 1;
  62.             DescriereACUM = 1;
  63.             DescriereACUMepg = 1;
  64.             WiFi.begin(ssid, password);
  65.             Serial.print("Connecting to WiFi");
  66.             while (WiFi.status() != WL_CONNECTED)
  67.                 {
  68.                    Serial.print(".");
  69.                    delay(500);
  70.                 }
  71.             Serial.println();      
  72.             Serial.println("Connected to WiFi");
  73.             delay(2000);  
  74.             Conexiune == 1;
  75.             timeClient.begin();
  76.             startMillis = millis();
  77.           }
  78.  
  79.      void loop()
  80.           {  
  81.             timeClient.update();
  82.             tft.setTextSize(1);
  83.             tft.setTextColor(TFT_CYAN, TFT_BLACK);
  84.             OraExacta = timeClient.getFormattedTime();
  85.             Serial.println(OraExacta);
  86.             tft.drawString(OraExacta, 247, 2, 2);
  87.  
  88.  
  89.             WiFiClient client;
  90.             if (!client.connect(host, 80))
  91.                 {
  92.                    Serial.println("NOT CONNECTED TO");
  93.                    Serial.println("ENIGMA2 RECEIVER!");
  94.                    Conexiune = 0;
  95.                    return;
  96.                 }  else
  97.                    if (Conexiune == 0)
  98.                       {
  99.                          Serial.println("CONNECTED TO");
  100.                          Serial.println("ENIGMA2 RECEIVER");
  101.                          delay(1);
  102.                          Conexiune = 1;
  103.                          NumeCanalVechi = " ";
  104.                          EPGacumVECHI = " ";
  105.                          EPGacum = 1;
  106.                       }
  107.             Serial.println("");
  108.             String url = String(path);
  109.  
  110.             client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  111.                    "Host: " + host + "\r\n" +
  112.                    "Connection: close\r\n\r\n");
  113.  
  114.             while(!client.available())
  115.                 {
  116.                   delay(1);
  117.                 }
  118.  
  119.             String line;
  120.             while (client.available())
  121.               {
  122.                  line = client.readStringUntil('\n');
  123.                  if (line.indexOf("e2servicename") >= 0)
  124.                     {
  125.                        int startIndex = line.indexOf(">") + 1;
  126.                        int endIndex = line.indexOf("<", startIndex);
  127.                        String e2servicename = line.substring(startIndex, endIndex);
  128.                        NumeCanalNou = e2servicename ;
  129.                        if (NumeCanalVechi != NumeCanalNou)
  130.                           {
  131.                                
  132.                                NumeCanalNouPrelucrat = NumeCanalNou;
  133.                                NumeCanalNouPrelucrat.toLowerCase();
  134.                                NumeCanalNouPrelucrat.replace(" ", "");
  135.                                LinkCanalCurent = "http://" + String(host) + "/picon/" + NumeCanalNouPrelucrat + ".png";
  136.                                tft.fillRect(0,0,232,134, TFT_BLUE);
  137.                                tft.fillRect(1,1,230,132,TFT_BLACK);
  138.                                setPngPosition(6, 1);
  139.                                const char* urlCanalCurent = LinkCanalCurent.c_str();
  140.                                load_png(urlCanalCurent);
  141.                                tft.setTextSize(2);
  142.                                tft.setTextColor(TFT_RED, TFT_BLACK);
  143.                                tft.drawString(NumeCanalNou + "                       ", 5, 134, 2);
  144.                                tft.setTextSize(2);
  145.                                tft.setTextColor(TFT_BLUE, TFT_BLACK);
  146.                                //tft.drawString("ACUM", 150, 80, 2);
  147.                                //tft.drawString("EPG", 3, 144, 2);
  148.                                NumeCanalVechi = NumeCanalNou;
  149.                                PozitieX = 321;
  150.                           }
  151.                           Serial.println("Canal: " + e2servicename);
  152.                     } else if (line.indexOf("e2providername") >= 0)
  153.                           {
  154.                                int startIndex = line.indexOf(">") + 1;
  155.                                int endIndex = line.indexOf("<", startIndex);
  156.                                String e2providername = line.substring(startIndex, endIndex);
  157.                                NumeProvider = e2providername;
  158.                                tft.setTextSize(1);
  159.                                tft.setTextColor(TFT_YELLOW, TFT_BLACK);                                                      
  160.                                tft.drawString(NumeProvider + + "                 ", 237, 100, 2);
  161.                                Serial.println("Provider: " + e2providername);
  162.                           }
  163.                       else if (line.indexOf("e2servicevideosize") >= 0)
  164.                          {
  165.                               int startIndex = line.indexOf(">") + 1;
  166.                               int endIndex = line.indexOf("<", startIndex);
  167.                               String e2servicevideosize = line.substring(startIndex, endIndex);
  168.                               tft.setTextSize(1);
  169.                               tft.setTextColor(TFT_YELLOW, TFT_BLACK);                              
  170.                               tft.drawString(e2servicevideosize + "          ", 237, 116, 2);
  171.                               Serial.println("Rezolutie: " + e2servicevideosize);
  172.                          }
  173.                       else if (line.indexOf("e2eventname") >= 0)
  174.                          {
  175.                               int startIndex = line.indexOf(">") + 1;
  176.                               int endIndex = line.indexOf("<", startIndex);
  177.                               String e2eventname = line.substring(startIndex, endIndex);
  178.                               if (EPGacum == 1)
  179.                                  {      
  180.                                         AfisareEPG = e2eventname;
  181.                                         tft.setTextSize(1);
  182.                                         tft.setTextColor(TFT_GREEN, TFT_BLACK);
  183.                                         tft.drawString(AfisareEPG + "                                                   ", 5, 167, 2);
  184.                                  }
  185.                               if (EPGacum == 2) AfisareEPG2 = e2eventname;
  186.                               EPGacum = EPGacum + 1;
  187.                               if (EPGacum > 2) EPGacum = 1;      
  188.                          }
  189.                       else if (line.indexOf("e2eventdescription") >= 0)
  190.                          {
  191.                              
  192.                              
  193.                               int startIndex = line.indexOf(">") + 1;
  194.                               int endIndex = line.indexOf("<", startIndex);
  195.                               String e2eventdescription = line.substring(startIndex, endIndex);
  196.                               if (DescriereACUM > 4) DescriereACUM = 1;
  197.                               if (DescriereACUM == 1) AfisareDESC = e2eventdescription;
  198.                               if (DescriereACUM == 2) AfisareDescriereEPG = e2eventdescription;
  199.                               if (DescriereACUM == 3) AfisareDESC2 = e2eventdescription;
  200.                               if (DescriereACUM == 4) AfisareDescriereEPG2 = e2eventdescription;    
  201.                               tft.setTextSize(1);
  202.                               tft.setTextColor(TFT_YELLOW, TFT_BLACK);
  203.                               tft.drawString(AfisareDESC.substring(0, 45) + "                                                                     ", 5, 184, 2);
  204.                               tft.drawString(AfisareDESC.substring(45,90) + "                                                                     ", 5, 200, 2);
  205.                               tft.drawString(AfisareDESC.substring(90,135) + "                                                                     ", 5, 216, 2);
  206.                               tft.setTextColor(TFT_GREEN, TFT_BLACK);
  207.                               //tft.drawString(AfisareDescriereEPG+ "                                                                     ", PozitieX, 216, 2);
  208.                             // tft.drawString(AfisareDescriereEPG.substring(48, 98) + "                                                                     ", 0, 192, 2);  
  209.                             // tft.drawString(AfisareDescriereEPG.substring(98, 148) + "                                                                     ", 0, 208, 2);          
  210.                             // tft.drawString(AfisareDescriereEPG.substring(148, 198) + "                                                                     ", 0, 224, 2);                          
  211.                              DescriereACUM = DescriereACUM + 1;
  212.                          }
  213.              }
  214.            
  215.              client.stop();
  216.              delay(500);
  217.           }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement