Storing Pointer Address Text into a Variable

YellowGTM
Posts: 5
Joined: Wed Oct 08, 2025 5:26 pm

Storing Pointer Address Text into a Variable

Postby YellowGTM » Mon Nov 17, 2025 6:25 pm

Hardware: ESP32-WROOM
IDE: Arduino 2.3.6

Hello Again! I'm hoping for some tips on what I consider "advanced coding". The good news is; I've successfully connected
my cell phone to the ESP32, and able to read META data from locally stored MP3's, as well as YouTube streamed music.

My goal is to send the META data over USB Serial to Processing to display in a little program. The trouble is, I'm not sure how
to get the data stored at the Pointer address into a variable (array, string, etc.)? Everything I've read, and tried gives me an
error, such as:

invalid conversion from 'uint8_t' {aka 'unsigned char'} to 'char*' [-fpermissive]

I'll continue to Google/Youtube lesson my way through this, and post any resolutions. Help. Tips, and Ideas welcome!
Thank you! :ugeek:

Code: Select all

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"
#include <cstdint>

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

//char* dataBT; //[515];
//String BTstring; //std::string BTstring

void avrc_metadata_callback(uint8_t id, const uint8_t *data){  
  Serial.printf("0x%x, %s\n", id, data); 
  //strcpy(*data, BTstring);
  //&& memcpy(dataBT, data, sizeof(data));
}

void setup() {
  Serial.begin(115200);
  a2dp_sink.set_avrc_metadata_attribute_mask(ESP_AVRC_MD_ATTR_TITLE | ESP_AVRC_MD_ATTR_ARTIST | ESP_AVRC_MD_ATTR_PLAYING_TIME ); //| ESP_AVRC_MD_ATTR_ALBUM | ESP_AVRC_MD_ATTR_PLAYING_TIME );
  a2dp_sink.set_avrc_metadata_callback(avrc_metadata_callback);
  a2dp_sink.start("META_test");
}

void loop() {
  //Serial.println(dataBT);
  //delay(500);
}
bt4.png
bt4.png (7.17 KiB) Viewed 4471 times

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: Storing Pointer Address Text into a Variable

Postby lbernstone » Mon Nov 17, 2025 11:57 pm

Can you please be clearer in your code about which variable you are trying to get, and what you want to do with it? You probably need to dereference the pointer to get at the contents (put a & in front of the name), but you have a lot of remarked stuff in there and don't give any context for where the error is generated.

RandomInternetGuy
Posts: 81
Joined: Fri Aug 11, 2023 4:56 am

Re: Storing Pointer Address Text into a Variable

Postby RandomInternetGuy » Tue Nov 25, 2025 12:49 am

It's highly unlikely that this has anything whatsoever to do with ESP32 and is more of a second-week computer science question.

Professionals work very hard to solve this problem by never HAVING this problem. Seriously.

In real systems, data moves, is accessed by different CPUs, is accessed by different CPU types, is reallocated, may be modified by interrupts, or may be eaten by a grue between the time that reference is converted to a hexy-looking thing and the time you hope to need it again. It's not like you can put it in a protobuf or a network connection or a tape backup or a CD or, well, much of anything and expect to DO anything with it. A valid pointer on your phone is simply meaningless on the Bluetooth stack in your earbuds or radios on the cellular network or the GPU pushing around pixels or whatever. It may not be suitably aligned, the datum may have been freed or, worse, reallocated. Thus, pros just don't DO this conversion often.

Still, the most literal answer to the question that you're asking (well, as best I can guess, since your actual question is quite nonsensical even once getting past the "don't do that" admonitions) is something like using the sprintf/scanf family.

Code: Select all

➜  /tmp cat x.cc
#include <stdio.h>
#include <assert.h>

int main(void) {
  int number = 34567890;

  printf("Number is %d. Address of number is %p\n", number, &number);

  char buf[32];
  int rval = snprintf(buf, sizeof(buf)-1, "%p", &number);
  assert(rval > 0);
  printf("buf[] is this %s\n", buf);

  int* number_ptr = NULL;
  int result = sscanf(buf, "%p", &number_ptr);
  assert (result > 0);

  printf("Content of number_ptr is %p\n", number_ptr);
  //  So when we dereference that number, we get...
  printf("Rehydrating the dehydrated number, we get %d\n", *number_ptr);

}
➜  /tmp c++ -Wall --std=c++23  x.cc -o x  && ./x
Number is 34567890. Address of number is 0x16f9d6c00
buf[] is this 0x16f9d6c00
Content of number_ptr is 0x16f9d6c00
Rehydrating the dehydrated number, we get 34567890

Ibernstone is (as usual) correct: your question is just malformed. You're askign for engineering-grade help for intro-level materal, but you're not even asking that effectively.

Of course, in post-80's code, that might be [io]stream, stringstream, std::print, std::scanner, or a hundred other things, but I'm not going to type a hundred answers to a question that you're probably not actually asking anyway.

But while I'm being preachy, three more tips:
1) Don't ignore compiler warnings/errors. At your level, ask for all you can get (-Wall, -Wextra) and fix them.
2) Take the time to really get your head around pointers. If you're in the C/C++ family, especially embedded, few concepts will be more universal. People keep promising unicorns that will shield you from big, scary, mean old pointers, but understanding how memory and memory management REALLY REALLY works - no matter how many times "new" languages promise you they can protect you from getting sawdust under your nails - is absolutely a primary employable skill. Blow that in an interview (with me), and the interview is over.
3) Don't paste a picture of text. Learn to copy and paste, so it'll show up in search, can be formatted, annotated, can be read by low-vision readers, etc. You're going to spend the rest of your life copy-pasting code from here to there, errors into a search box, boilerplate into an editor, (hopefully, eventually) coworker praise into a performance review, etc. Taking a picture of words is just lazy.

Who is online

Users browsing this forum: YisouSpider and 3 guests