So I am trying this. Problem is that most websites do not provide me HTML code at all what should I do ?
Video of the machine web browserhttps://www.youtube.com/shorts/IK5aLVg4yoI
With google it gets the HTML code but not with other websites.
ESP32 code
// this sample code provided by www.programmingboss.com
#include "WiFi.h"
#include <HTTPClient.h>
#define RXp2 16
#define TXp2 17
String lFinalSentStringHTML;
bool bSentLengthOfStringURL, bBodyFoundHTML;
int iFinalLengthOfString;
struct SHTMLTag
{
String TagName;
unsigned int TagPos;
String Content;
};
const char* ssidHTML = "DONTLOOKATMYSSID"; //choose your wireless ssid.
const char* passwordHTML = "DONTLOOKATMYPASSWRD"; //put your wireless password here.
int httpCodeOfStatusHTML;
String SiteToBrowseHTML = "";
String SiteToBrowseHTMLDestilada;
String HtmlpayloadHTML;
void setup()
{
// put your setup code here, to run once: sample baud radtes 9600 115200
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXp2, TXp2);
WiFi.begin(ssidHTML, passwordHTML);
}
void loop()
{
//Serial.println("Message Received: ");
Serial.println("FROM ESP 32 receiving orders to reach website");
//Serial.println(Serial2.readString());
if(Serial2.available() > 0)
{
Serial.println("FROM ESP 32 main program Site received tier 0 ");
SiteToBrowseHTML = Serial2.readString();
}
delay(1000);
HTTPClient http;
if(SiteToBrowseHTML != "")
{
//SEND THE STRING LENGTH FIRST STORE IT WHEN READY GO FOR ITs
SiteToBrowseHTMLDestilada = "";
//Ways to do this
//1 Catch the. com then don't get more stuff
//2 c++ Function que vagi de miniscula a majuscula
//3
for(int Id = 0; Id < 40; Id++)
{
if(SiteToBrowseHTML[Id] != ' ' )
{
if( SiteToBrowseHTML[Id] == '.' && ( SiteToBrowseHTML[Id+1] == 'c' || SiteToBrowseHTML[Id+1] == 'C' ) && ( SiteToBrowseHTML[Id+2] == 'o' || SiteToBrowseHTML[Id+2] == 'O' ) && ( SiteToBrowseHTML[Id+3] == 'm' || SiteToBrowseHTML[Id+3] == 'M' ) )
{
break;
}
if( SiteToBrowseHTML[Id] == '.' && ( SiteToBrowseHTML[Id+1] == 'o' || SiteToBrowseHTML[Id+1] == 'O' ) && ( SiteToBrowseHTML[Id+2] == 'r' || SiteToBrowseHTML[Id+2] == 'R' ) && ( SiteToBrowseHTML[Id+3] == 'g' || SiteToBrowseHTML[Id+3] == 'G' ) )
{
break;
}
else
{
SiteToBrowseHTMLDestilada += SiteToBrowseHTML[Id];
Serial.println("FROM ESP 32 main program Site received tier 1 ");
Serial.print(SiteToBrowseHTMLDestilada[Id]);
}
}
}
//SiteToBrowseHTMLDestilada.replace(" ","");
//SiteToBrowseHTMLDestilada.replace(' ',"");
Serial.println("SiteToBrowseHTMLDestilada");
Serial.println(SiteToBrowseHTMLDestilada);
SiteToBrowseHTMLDestilada+=".com";
http.begin(SiteToBrowseHTMLDestilada); //JSON request http://jsonplaceholder.typicode.com/users/1//"https://google.com"
Serial.println(SiteToBrowseHTMLDestilada);
Serial.println(SiteToBrowseHTMLDestilada);
Serial.println("Prnting now cehck the difference between the links sent ");
Serial.println("FROM ESP 32 mainSiteToBrowseHTMLDestilada program Site received tier 1 ");
//("https://www.basicwebsiteexample.com/");
// http://jsonplaceholder.typicode.com";
//"https://creativeovenstudios.com"
httpCodeOfStatusHTML = http.GET();
lFinalSentStringHTML = "";
}
if( WiFi.status() == WL_CONNECTED && httpCodeOfStatusHTML > 0)
{
//Serial2.println("Meow");
HtmlpayloadHTML = http.getString();
Serial.println(HtmlpayloadHTML);
Serial.println("FROM ESP32 Loop Main program begiining it ");
delay(2000);
for(int i = 0; i < 20000 && HtmlpayloadHTML.length() > i; i++)
{
int XtrI = 0;
//WIP Use the two cases b B for all
if( HtmlpayloadHTML[i] == '<'
&& (HtmlpayloadHTML[i+1] == 'B' || HtmlpayloadHTML[i+1] == 'b')
&& ( HtmlpayloadHTML[i+2] == 'O' || HtmlpayloadHTML[i+2] == 'o' )
&& ( HtmlpayloadHTML[i+3] == 'D' || HtmlpayloadHTML[i+3] == 'd' )
&& ( HtmlpayloadHTML[i+4] == 'Y' || HtmlpayloadHTML[i+4] == 'y' ) )
{
Serial.println("FROM ESP32v LETTERS PROCESSED Now body found tier 1");
//Serial.println(i);
bBodyFoundHTML = true;
}
if( bBodyFoundHTML )
{
lFinalSentStringHTML += HtmlpayloadHTML[i];
//lFinalSentString += "Meow";// test force memory
//Serial.println("FROM ESP32v LETTERS PROCESSED Now body found tier 2");
}
if( HtmlpayloadHTML[i] == '<' && HtmlpayloadHTML[i+1] == '/' &&( HtmlpayloadHTML[i+2] == 'B' || HtmlpayloadHTML[i+2] == 'b' ) && ( HtmlpayloadHTML[i+3] == 'O' || HtmlpayloadHTML[i+3] == 'o' ) && ( HtmlpayloadHTML[i+4] == 'D' || HtmlpayloadHTML[i+4] == 'd' ) && ( HtmlpayloadHTML[i+5] == 'Y' || HtmlpayloadHTML[i+5] == 'y' ) )
{
Serial.println("FROM ESP32v LETTERS PROCESSED Now body found tier 2 nd");
//Serial.println(i);
bBodyFoundHTML = false;
}
}
//lFinalSentString = "Hellog this is a long text to see if ti can receive a loooooooong text FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
Serial2.println(lFinalSentStringHTML);
Serial.println(lFinalSentStringHTML);
}
else
{
Serial2.println("Not connected yet wifi or no get");
}
//Serial.println(Htmlpayload);
delay(2000);
http.end();
delay(2000);
}
Arduino Mega
// IMPORTANT: Elegoo_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Elegoo_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <TranslateHTMLToCHL.h> //Library that translates
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Color definitions
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
#define ILI9341_RED 0xF800 /* 255, 0, 0 */
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
#define ILI9341_PINK 0xF81F
/******************* UI details */
#define BUTTON_X 40
#define BUTTON_Y 100
#define BUTTON_W 32
#define BUTTON_H 16
#define BUTTON_SPACING_X 1
#define BUTTON_SPACING_Y 1
#define BUTTON_TEXTSIZE 2
// text box where numbers go
#define TEXT_X 10
#define TEXT_Y 10
#define TEXT_W 220
#define TEXT_H 50
#define TEXT_TSIZE 1
#define TEXT_TCOLOR ILI9341_MAGENTA
// the data (phone #) we store in the textfield
#define TEXT_LEN 32
char textfield[TEXT_LEN + 1] = "";
uint8_t textfield_i = 0;
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
//Touch For New ILI9341 TP
#define TS_MINX 120
#define TS_MAXX 900
#define TS_MINY 70
#define TS_MAXY 920
// We have a status line for like, is FONA working
#define STATUS_X 10
#define STATUS_Y 65
String ESP32Message = "Message entered IP?";
bool bLoadAlready = false;
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int dataNumber = 0; // new for this version
bool bgAssignedHTMLAlready, bgShouldRenderSiteNow, bNotHTMLReadyToRender, bURLLengthSent;
int iUrlLengthSend;
HTMLTag TagsToRender[HTMLTagsLength];
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Elegoo_TFTLCD tft;
Elegoo_GFX_Button buttons[30];
/* create 15 buttons, in classic candybar phone style */ //a b c d e f g h i j k l m n o p q
char buttonlabels[30][5] = { "Send", "Clr", "End", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "." };
uint16_t buttoncolors[15] = { ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_ORANGE, ILI9341_BLUE, ILI9341_ORANGE };
void setup(void)
{
Serial.begin(9600);
Serial1.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_Elegoo_SHIELD_PINOUT
Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is ");
Serial.print(tft.width());
Serial.print("x");
Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
if (identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if (identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if (identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
} else if (identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if (identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if (identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if (identifier == 0x0101) {
identifier = 0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_Elegoo_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier = 0x9341;
}
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(BLACK);
// create buttons
for (uint8_t row = 0; row < 6; row++)
{
for (uint8_t col = 0; col < 5; col++)
{
buttons[col + row * 5].initButton(&tft, BUTTON_X + col * (BUTTON_W + BUTTON_SPACING_X),
BUTTON_Y + row * (BUTTON_H + BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col + row * 3], ILI9341_WHITE,
buttonlabels[col + row * 5], BUTTON_TEXTSIZE);
buttons[col + row * 5].drawButton();
}
}
// create 'text field'
tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);
}
// Print something in the mini status bar with either flashstring
void status(const __FlashStringHelper *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
// or charstring
void status(char *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop(void)
{
/*TSPoint p;
p = ts.getPoint();
*/
//digitalWrite(13,HIGH);
//TSPoint p = ts.getPoint();
//digitalWrite(13,LOW);
//Serial.println("Should get cursor");
//Serial.println("FROM Arduino mega sending Info Of Sensor");
//Serial1.println("FROM Arduino mega sending Info Of Sensor Serial1 to esp32 18tx 9rx");
//Serial.println("FROM Arduino mega reading esp32");
//recvWithEndMarker();
//showNewNumber();
if (bgAssignedHTMLAlready && !bgShouldRenderSiteNow && bLoadAlready)
{
ReturnAndProcessAllHTMLTagsFromPage(ESP32Message, TagsToRender);
for (int liTagsI = 0; liTagsI < 5; liTagsI++)
{
Serial.println("FROM main program the final lines are : ");
Serial.println(liTagsI);
Serial.println(TagsToRender[liTagsI].TagName);
Serial.println(TagsToRender[liTagsI].Content);
//delay(100);
}
Serial.println("FROM main program loop Should now be assigned");
bgShouldRenderSiteNow = true;
}
if ( Serial1.available() > 0 && !bLoadAlready )
{
String BeginningOfSite = "https://";
String SiteName = textfield; //"google.com"; //textfield; //
String FinalSiteToSend; FinalSiteToSend += BeginningOfSite; FinalSiteToSend += SiteName;
Serial.println("FROM Arduino mega loop Serial 1 available Input Text Is");
Serial.println(textfield);
bLoadAlready = true;
ESP32Message = Serial1.readString();
Serial1.println(FinalSiteToSend); //uncomment this to send URL
iUrlLengthSend = 18;
//Serial1.println(iUrlLengthSend);
Serial.print("FROM Arduino mega loop Serial 1 available sending FROM arduino Mega the sent to esp32 ");
Serial.println(iUrlLengthSend);
//Serial.println(ESP32Message);
bgAssignedHTMLAlready = true;
delay(100);
}
//tft.fillScreen(BLACK);
//tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
//Serial.println("THIS IS FROM PROGRAM ARD MAIN LOOPING TO SEE IF WORKS ");
//Serial.println(ESP32Message);
tft.setTextColor(RED);
tft.setTextSize(1);
//RENDER SITE NOOOOW
if (!bNotHTMLReadyToRender)
{
tft.println(ESP32Message);
}
//It renders already stop renderoing NOT READY TRUE
if (!bNotHTMLReadyToRender && bLoadAlready)
{
bNotHTMLReadyToRender = true;
}
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
// if sharing pins, you'll need to fix the directions of the touchscreen pins
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
// p = ts.getPoint();
/*
if (ts.bufferSize()) {
} else {
// this is our way of tracking touch 'release'!
p.x = p.y = p.z = -1;
}*/
// Scale from ~0->4000 to tft.width using the calibration #'s
/*
if (p.z != -1) {
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
Serial.print("("); Serial.print(p.x); Serial.print(", ");
Serial.print(p.y); Serial.print(", ");
Serial.print(p.z); Serial.println(") ");
}*/
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = (tft.height() - map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
}
// go thru all the buttons, checking if they were pressed
for (uint8_t b = 0; b < 30; b++) {
if (buttons[b].contains(p.x, p.y)) {
//Serial.print("Pressing: "); Serial.println(b);
buttons[b].press(true); // tell the button it is pressed
} else {
buttons[b].press(false); // tell the button it is NOT pressed
}
}
// now we can ask the buttons if their state has changed
for (uint8_t b = 0; b < 30; b++) {
if (buttons[b].justReleased()) {
// Serial.print("Released: "); Serial.println(b);
buttons[b].drawButton(); // draw normal
}
if (buttons[b].justPressed()) {
buttons[b].drawButton(true); // draw invert!
// if a numberpad button, append the relevant # to the textfield
if (b >= 3) {
if (textfield_i < TEXT_LEN) {
textfield[textfield_i] = buttonlabels[b][0];
textfield_i++;
textfield[textfield_i] = 0; // zero terminate
// fona.playDTMF(buttonlabels[b][0]);
}
}
// clr button! delete char
if (b == 1)
{
/*textfield[textfield_i] = 0;
if (textfield > 0) {
textfield_i--;
textfield[textfield_i] = ' '; */
//reset by ferran send
bgAssignedHTMLAlready = false;
bgShouldRenderSiteNow = false;
bLoadAlready = false;
bNotHTMLReadyToRender = false;
}
// update the current text field
Serial.println(textfield);
tft.setCursor(TEXT_X + 2, TEXT_Y + 10);
tft.setTextColor(TEXT_TCOLOR, ILI9341_BLACK);
tft.setTextSize(TEXT_TSIZE);
tft.print(textfield);
// its always OK to just hang up
if (b == 2)
{
status(F("Hanging up"));
textfield[textfield_i] = 0;
if (textfield > 0)
{
textfield_i--;
textfield[textfield_i] = ' ';
}
//fona.hangUp();
}
// we dont really check that the text field makes sense
// just try to call
if (b == 0)
{
status(F("Calling"));
Serial.print("Calling ");
Serial.print(textfield);
HandleRenderButton(TagsToRender);
//fona.callPhone(textfield);
}
//delay(100); // UI debouncing
}
}
}
void HandleRenderButton(HTMLTag HTMLTextArrayToRender[])
{
RenderSiteNow(HTMLTextArrayToRender);
}
//Renders now the site
void RenderSiteNow(HTMLTag HTMLTextArrayToRender[])
{
//for(int i = 0;HTMLTextArrayToRender
Serial.println("FROM main program RenderSiteNow() should render site now");
//tft.println(ESP32Message);
tft.println(HTMLTextArrayToRender[0].Content);
//HTMLTextArrayToRender
}