How do I extract data from json and implement it to bitmap draw function?

I have the bitmap in my JSON response.
\"bitmap\":\"0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x1f, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x0f, 0x80, 0x01, 0xf0, 0x00, 0x00, 0x07, 0xc0, 0x03, 0xe0, 0x00, 0x00, 0x03, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x01, 0xf0, 0x0f, 0x80, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x0f, 0x80, 0x00, 0x00, 0x07, 0xc0, 0x07, 0xc0, 0x00, 0x00, 0x0f, 0x80, 0x03, 0xe0, 0x00, 0x00, 0x1f, 0x00, 0x01, 0xf8, 0x00, 0x00, 0x3e, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x3e, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x1f, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\"

I have tried this code do extract the data and draw an image, but

  const unsigned char bitmap [288] = {doc["crypto_section"]["bitmap"]};
  tft.drawBitmap( 50, 50, bitmap, 48, 48, ST7735_ORANGE);

But what I get is nothing related to this bitmap on a screen and constantly rebooting device.

19:00:11.631 ->  ets Jan  8 2013,rst cause:4, boot mode:(3,6)
19:00:11.631 -> 
19:00:11.631 -> wdt reset
19:00:11.631 -> load 0x4010f000, len 3460, room 16 
19:00:11.679 -> tail 4
19:00:11.679 -> chksum 0xcc
19:00:11.679 -> load 0x3fff20b8, len 40, room 4 
19:00:11.679 -> tail 4
19:00:11.679 -> chksum 0xc9
19:00:11.679 -> csum 0xc9
19:00:11.679 -> v0005e220
19:00:11.679 -> ~ld

So question is how do I extract data from json and implement it to bitmap function?
"Adafruit_ST7735.h"

You will need to interpret the human readable hex representation of the bitmap values into individual binary data values and store those in the proper cells of the bitmap array.

I'm sure that code has been posted to do that, so a search should be fruitful.

Your 'bitmap' entry in JSON is one very long text string. What you want is a byte array. You need to parse the string to turn it back into a byte array. One way would be to go through the string looking for "0x" prefixes and then convert the next two characters from ASCII to a byte.

A better solution might be to encode your binary into a Base64 string. That gives you a string that is only 33% larger than your byte array. Your current ASCII HEX is 6 times the size.

An intermediate solution is to remove ", 0x" from your string so the string is only about twice the size of the byte array. Then it will be easier to parse: just look for hex digits and convert each in turn.

1 Like

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