Advertisement
LeventeDaradici

How To ExtractingAndDisplayingOnTFT_eSPIdisplayPiconsAndDataFromXMLfilesFromAremoteServer

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