Fetching a code of a bitmap from a local http site and drawing that bitmap on a e-paper

Hello everybody,

first of all I will include what I am using.

I am using:

  • an 7.5in V2 B/W e-paper display from waveshare with a e-Paper Driver HAT
  • an WROOM ESP32 / Nodemcu ESP32S (Both of these names are written on the board)

And the following (messy) code (some variables/definitions were used for testing purpose):

/* Includes ------------------------------------------------------------------*/
#include <WiFi.h>
#include <HTTPClient.h>
#include "DEV_Config.h"
#include "EPD.h"
#include "GUI_Paint.h"
#include "imagedata.h"
#include <stdlib.h>


const char* ssid = "ESPNetwork";
const char* password =  "ESPpass";

String payload;

bool CodeFetched = false;
uint32_t Converted;


/* Entry point ----------------------------------------------------------------*/
void setup()
{

  Serial.begin(115200);
  delay(4000);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  Serial.println("Connected to the WiFi network");


}

/* The main loop -------------------------------------------------------------*/
void loop()
{
  if ((WiFi.status() == WL_CONNECTED)) { 

    HTTPClient http;

    http.begin("http://192.168.8.120/QRCode.bmp"); 
    int httpCode = http.GET();                                       
    String payload = http.getString();
    if (httpCode > 0) { //Check for the returning code

      Serial.print("fetched binary: ");
      Serial.println(payload);
      //  Serial.print("binary with substring: ");
      // Serial.println(payload.substring(2));
      //  Converted = atoi (payload.c_str());
      //   Serial.print("binary with atoi: ");
      //   Serial.println(Converted);

    
    }

    else {
      Serial.println("Error on HTTP request");
    }



    delay(1000);

    http.end(); //Free the resources


    printf("EPD_7IN5_V2_test Demo\r\n");
    DEV_Module_Init();

    Serial.print("works ");

    printf("e-Paper Init and Clear...\r\n");
    EPD_7IN5_V2_Init();
    EPD_7IN5_V2_Clear();
    DEV_Delay_ms(500);

    //Create a new image cache
    UBYTE *BlackImage;
    /* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
    UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT;

    if ((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
      printf("Failed to apply for black memory...\r\n");
      while (1);
    }
    printf("Paint_NewImage\r\n");
    Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH, EPD_7IN5_V2_HEIGHT, 0, WHITE);

#if 1   // show image for array  

    printf("show image for array\r\n");
    Paint_SelectImage(BlackImage);
    Paint_Clear(WHITE);
    Paint_DrawBitMap(char_payload);
    EPD_7IN5_V2_Display(BlackImage);
    DEV_Delay_ms(20000);

    

#endif

#if 0   // Drawing on the image
    //1.Select Image
    printf("SelectImage:BlackImage\r\n");
    Paint_SelectImage(BlackImage);
    Paint_Clear(WHITE);



    Serial.println("Char gelöscht");

#endif

    printf("Clear...\r\n");


    printf("Goto Sleep...\r\n");
    EPD_7IN5_V2_Sleep();
    free(BlackImage);
    BlackImage = NULL;
    CodeFetched = false;
  }
}

So here's the description. I use a local web server with a bitmap on it and the esp32 is supposed to fetch that bitmap as a code, and that code is as far as I know in binary. I kind of managed to get the code trough the esp32, but it starts with BM>?>( and contains after that ?﹖ □ as a very long string and I tried to use String.substring to only get the string after "BM>?>( " but it automatically stops right at the question mark, after that it does not print anything else.

I tried to convert the string to int/hex with atoi and it also did not work out and I was getting a 0 as a output.

So I thought since the e-paper is drawn using an unsigned char array with 48000 pixels, I need to convert it into a charr array, so I did, but I got again some numbers which displayed the first couple of letters in ASCII, a couple of zeroes and other numbers, 3 times 255 and then only zeroes making the program crash entirely.

I sit on this issue for quite some time now and I did not manage to make this work.

I don't see any variable named 'char_payload'. Did you mean to use 'payload'? Maybe you meant 'payload.c_str()'?

What format is the data in? My guess would be Base64. If that is the case you will have to decode the Base64 format before using it as binary.

Paint_DrawBitMap(char_payload)
Ah, apologize, it is an variable from trying to convert the fetched string into an charr array and since it didn't work I removed it.

I may try out 'payload.c_str()'

What format is the data in? My guess would be Base64. If that is the case you will have to decode the Base64 format before using it as binary.

If I understand it correctly and you mean the bitmap I have to fetch then it is an .bmp file. I am accessing the source image of the .bmp file (surely you noticed).

What do you see on Serial Monitor when the payload is printed?

      Serial.print("fetched binary: ");
      Serial.println(payload);

You might want to display a couple of common header values along with the contents:

    Serial.println(http.header("Content-Length");
    Serial.println(http.header("Content-Encoding");

What do you see on Serial Monitor when the payload is printed?

Something very long like BM>?>(□□□□□□□□?□□□□□□□□□□□□□□□□□□□□□??□□□□□□□□

You might want to display a couple of common header values along with the contents:

    Serial.println(http.header("Content-Length");
    Serial.println(http.header("Content-Encoding");

May I ask what exactly that does?

I just remembered another issue, the one time I was testing the charr array the entire program stopped after http.end() and it printed in the Serial Monitor like the first letter of a following string and just to be sure I made the same test in a backup file where the same problem occurred. Could'nt find the reason for it. My presumption is, that the code for the e-paper was supposed to be in void setup() and not void loop().

Hello again,
so I tried putting payload.c_str() into Paint_DrawBitMap, and it did not work out and I got a message saying "invalid conversion from 'const char*' to 'const unsigned char*"

Regards to the output of the SerialMonitor here it is (it is way longer than in the picture):

I'd like to copy the binary itself but I cannot copy it and you can also see the letter "E" which I presume should be the first letter of printf("EPD_7IN5_V2_test Demo\r\n"); I don't know why it suddenly stops right there, I tried to find the error with multiple headers (if that's what they're called), but it simply stopped right after http.end();

I had an Idea of converting that string binary to an integer binary/hex and either I did not know what I was doing or it just didn't work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.