title: CAN frame over MQTT (need to convert hex string to byte array)
body: <p>I am implementing a MQTT communication. I want to send CAN frames over MQTT through a graphical interfaces (realized in python). I am able to send messages from the GUI to one topic and I am able to see messages arrived on the same topic (using paho library) when I use the board. The function is below and the topic is <strong>diagnostic_request/topic</strong>:</p>
  <pre><code> void onMessageArrived
  (
      const char* topic,
      const uint8_t* payload,
      size_t payloadLen,
      void* context
  )
  {
      //LE_FATAL(&quot;The publisher received a message!&quot;);
      //GIMP
      char payloadStr[payloadLen + 1];
      memcpy(payloadStr, payload, payloadLen);
      payloadStr[payloadLen] = '\0';
      LE_INFO(&quot;Received message! topic: \&quot;%s\&quot;, payload: \&quot;%s\&quot;&quot;, topic, payloadStr);
      //GIMP principio di conversione
  
      if (strcmp(subscribeTopic, topic)==0)
          LE_INFO(&quot;Sei sul topic di richiesta diagnostica!&quot;);
          can_send();        
    }
  </code></pre>
  <p>At this point I have a difficulty. My can_send function (that works!) is:</p>
  <pre><code>int can_send(void)
  {
      const char* subscribeTopic = &quot;diagnostic_request/topic&quot;;
      LE_FATAL_IF(
              mqtt_Subscribe(MQTTSession, subscribeTopic, MQTT_QOS0_TRANSMIT_ONCE) != LE_OK,
              &quot;failed to subscribe to %s&quot;,
              subscribeTopic);
      LE_INFO(&quot;Subscribed to topic (%s)&quot;, subscribeTopic);
  
  
             
          
  int nbytesWrite;
  
  // USE SEND STANDARD FRAME
  frameWrite.can_id = 0x750; //codice identificativo di una richiesta diagnostica per centralina simulata
  frameWrite.can_id &amp;= CAN_SFF_MASK;
  
  frameWrite.can_dlc = 8;
   //strcpy((char *)frameWrite.data, &quot;MGATE&quot;);
  frameWrite.data[0] = 0x03;
  frameWrite.data[1] = 0x22;
  frameWrite.data[2] = 0xF1;
  frameWrite.data[3] = 0x89;
  frameWrite.data[4] = 0x00;
  frameWrite.data[5] = 0x00;
  frameWrite.data[6] = 0x00;
  frameWrite.data[7] = 0x00;
  if ((nbytesWrite = write(sdw, &amp;frameWrite, sizeof(frameWrite))) != sizeof(frameWrite))
  {
      canwrite = false;
      LE_INFO (&quot;Writing error, nbytesWrite = %d&quot;, nbytesWrite);
      return SOCK_WRITING_ERROR;
  }
  
  canwrite = true;
  return 0;
  }
  </code></pre>
  <p>So I have to call can_send in the onMessageArrived function when is statement is ok. I am able to see when I send a publish on diagnostic_request/topic. The only problem is to send the payloadStr value to the can_send function and unpackage it in the frameWrite.data[]. <strong>Can someone help me to understand how to modify the can_send function in order that the values</strong></p>
  <pre><code>frameWrite.data[0] = 0x03;
  frameWrite.data[1] = 0x22;
  frameWrite.data[2] = 0xF1;
  frameWrite.data[3] = 0x89;
  frameWrite.data[4] = 0x00;
  frameWrite.data[5] = 0x00;
  frameWrite.data[6] = 0x00;
  frameWrite.data[7] = 0x00;
  </code></pre>
  <p><strong>are values that I send through mqtt in the payloadStr? I send a string of 8 bytes but I can't unpackage it.</strong>
  Any help will be appreciated
  Regards</p>