HELP

This is che code for esp8266 to sniff MAC adreses, in the functions.h i need to modify this code so that it would send the MAC adress and RSSI to a mqtt server as one masage. Code part to modify:

if((buf[12]==0x88)||(buf[12]==0x40)||(buf[12]==0x94)||(buf[12]==0xa4)||(buf[12]==0xb4)||(buf[12]==0x08))
  {
    // Serial.printf("%02x\n",buf[12]);
    // if(buf[12]==0x40) Serial.printf("Disconnected: ");
    // if(buf[12]==0x08) Serial.printf("Data: ");
    // if(buf[12]==0x88) Serial.printf("QOS: ");
    // Origin MAC address starts at byte 22
    // Print MAC address

    
    for(int i=0;i<5;i++) {
      Serial.printf("%02x:",buf[22+i]);
    }
    Serial.printf("%02x  ",buf[22+5]);
    // Signal strength is in byte 0
    Serial.printf("%i\n",int8_t(buf[0]));

P.S. i dont need the code for sending it to an mqtt server i just need to combine the outputs of these to one masage:

Serial.printf("%02x:",buf[22+i]);
Serial.printf("%02x  ",buf[22+5]);
Serial.printf("%i\n",int8_t(buf[0]));

Also if ypu will download the code i comented because i dont need it.

Serial.printf("%02x\n",buf[12]);

thanks in advance!

i just need to combine the outputs of these to one masage:

So, fire up the IDE and start writing.

Hint: sprintf()

PaulS:
So, fire up the IDE and start writing.

Hint: sprintf()

I did and what i understood and tried to do this came out:

for(int i=0;i<5;i++) {
      /// Serial.printf("%02x:",buf[22+i]);
      sprintf ( MAC_1 , "%02x:" , buf[22+0] , buf[22+1] , buf[22+2] , buf[22+3] , buf[22+4] );
    }
    /// Serial.printf("%02x  ",buf[22+5]);
    sprintf ( MAC_2 , "%02x  " , buf[22+5] );
    // Signal strength is in byte 0
    /// Serial.printf("%i\n",int8_t(buf[0]));
    sprintf ( RSSI_ , "%i\n" , int8_t(buf[0]) );

    Serial.print ( MAC_1 , MAC_2 , RSSI_ );

but when i compile it it says and error:

no matching function for call to ‘HardwareSerial::print(char [50], char [50], char [50])’

First, I don't think you're using sprintf() correctly. The first argument is a character buffer and I'm assuming there's a definition like:

char MAC_1[50];

somewhere. The second argument is a format string. There needs to be one conversion character ('%') for each argument you wish to display. However, you use:

sprintf ( MAC_1 , "%02x:" , buf[22+0] , buf[22+1] , buf[22+2] , buf[22+3] , buf[22+4] );

which uses a format string that wants to display one argument, but you're passing it five arguments.

Lastly, I don't think the print() method of the Serial object is going to like

  • Serial.print ( MAC_1 , MAC_2 , RSSI_ );*

I am still baffled at how you know how to use MQTT but can not figure out how to collect the data that needs to be sent.

Do you have to send a string? Why not store the values in a struct and send the struct?

Romonaga:
I am still baffled at how you know how to use MQTT but can not figure out how to collect the data that needs to be sent.

Do you have to send a string? Why not store the values in a struct and send the struct?

I tried but i got mixed up, can you please right the code thanks!

The goal of this Forum is not to write code for you; there's another place on this site for hiring consultants. This Forum is to help you overcome problems in the code you've written. Posts have given you suggestions on what to do, but I don't think they want to write the code for you. That's up to you.