How to send non english characters through mqtt?

Hello Everyone ,
I am trying to send non English characters through mqtt , like Indian languages Hindi, Telugu , Tamil etc…
Am not able to send those , anyone help me regarding this whether we have to send Unicode values or direct non-English characters ?

Iam also having same issue ? can anyone please help to solve this issue ?

Hi,

Great to see your interest in MQTT and HiveMQ. Welcome to the community!

MQTT payload is always binary and it is agnostic to the characters. However, the MQTT Client (device or a program) could be handling your characters incorrectly. An Example of the MQTT which is handling non-English characters correctly is the HiveMQ Cloud Web Client. See the screenshot below showing the Web Client which is publishing and receiving non-English characters correctly:

You can see the message published:

And received:

I hope it helps
Kind regards,
Dasha from HiveMQ Team

thanks for this information .
Here my application is to display these characters in P10 led display using ESP32 microcontroller and Arduino platform.
while sending the telugu language messages through mqtt am receiving other characters . can you explain how conversion is done ? any code for converting these characters ?

Hello @dileepkumar

Most of these P10 LED Displays devices can only display English characters and even if you can convert them to hex codes trying to display in Indian languages the font libraries may not convert those characters correctly.

My advice to you is to work with a P10 LED Display that supports natively all Indian languages Hindi, Bangla, Tamil etc…

Kind regards,
Diego from HiveMQ Team

hi
I have the fonts of native languages i can print the characters also but in arduino only i can type hindi language and i can print , but when sending from MQTT if am sending hindi characters its not taking as hindi some other characeters are displayed. The only thing i need is i need to send hindi characters from MQTT client then it should receive as same characters

My doubt is that
p10 is only display right ? does it have any language concern ? because all programming information is given in controller so why to concern about P10 display ?

Hello @dileepkumar

If you are sending Hindi characters in plain text to this display and it’s showing correctly in the display, MQTT payload should work in the same way since like my colleague Dasha mentioned above, “payload is always binary and it is agnostic to the characters”.

What MQTT library are you using on this Arduino/ESP32 project?

Kind regards,
Diego from HiveMQ Team

am using pubsubclient library

@dileepkumar

Can you share the full Arduino sketch code so I can take a quick look and see if I can suggest anything.

Kind regards,
Diego from HiveMQ Team

@Diego


#include <WiFi.h>
#include <PubSubClient.h>
#include<Adafruit_GFX.h>

const char* ssid = "chfhfhff";
const char* password = "xxxx";
char *mqttServer = "broker.hivemq.com";
int mqttPort = 1883;
int a=0;
const char* mqtt_client_name = "ESP/glowsignboard";

//const char* mqtt_pub_topic = "/ys/testpub"; //The topic to which our client will publish

const char* matrix_text_topic = "scroll_message/store1"; //The topic to which our client will subscribe
const char* matrix_stanby_text_topic = "standby_message/store1";
const char* matrix_colour_topic = "colour/store1";

 char* my_blue    =     "blue";
 char* my_green   =     "green";
 char* my_yellow  =     "yellow";
 char* my_white   =     "white";
 char* my_cyan    =     "cyan"; 
 char* my_magenta =     "magenta";
 char* my_red     =     "red";
 
WiFiClient client;
PubSubClient mqttClient(client);

#define PANEL_RES_X 32 // Number of pixels wide of each INDIVIDUAL panel module. 
#define PANEL_RES_Y 16 // Number of pixels tall of each INDIVIDUAL panel module.

#define NUM_ROWS 2 // Number of rows of chained INDIVIDUAL PANELS
#define NUM_COLS 8 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWS*NUM_COLS    // total number of panels chained one to another
#define Matrix_width NUM_COLS*PANEL_RES_X

#define SERPENT true
#define TOPDOWN true

String message_receieved= " ";
String stanby_message_received= " ";

uint8_t R;
uint8_t G;
uint8_t B;

#include <ESP32-VirtualMatrixPanel-I2S-DMA.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#include <Fonts/FreeSerif9pt7b.h>
#include <C:\Users\dell\Documents\Arduino\libraries\ESP32-HUB75-MatrixPanel-DMA-master\Fonts\telugunoto.h>
#include <C:\Users\dell\Documents\Arduino\libraries\ESP32-HUB75-MatrixPanel-DMA-master\Fonts\AbhayaLibre_Regular9pt7b.h>
#include <C:\Users\dell\Documents\Arduino\libraries\ESP32-HUB75-MatrixPanel-DMA-master\Fonts\dilip.h>
//#include <SystemFont5x7.h>

MatrixPanel_I2S_DMA *dma_display = nullptr;
VirtualMatrixPanel  *virtualDisp = nullptr;

void callback(char* topic, byte* payload, unsigned int length) 
{
     a=1;
  if (strcmp(topic,matrix_colour_topic) == 0)
  {
    String colour;
    Serial.println("Message received from: "); 
    Serial.print(topic);
     for (int i = 0; i <length; i++) 
      {
          Serial.print((char)payload[i]); 
          colour +=String((char)payload[i]); 
      }
      Serial.print("comparing colour;");
      Serial.println(colour); 
   if(colour.equals(my_blue)==1) 
   {
     R=0;G=0;B=255;
     Serial.println("colour changed to blue "); 
   }
    else if(colour.equals(my_green)==1) 
   {
     R=0;G=255;B=0;
     Serial.println("colour changed to green "); 
   }
    else if(colour.equals(my_yellow)==1) 
   {
     R=255;G=255;B=0;
     Serial.println("colour changed to yellow"); 
   }
    else if(colour.equals(my_white)==1) 
   {
     R=255;G=255;B=255;
     Serial.println("colour changed to green "); 
   }
    else if(colour.equals(my_cyan)==1) 
   {
     R=0;G=100;B=100;
     Serial.println("colour changed to green "); 
   }
    else if(colour.equals(my_magenta)==1) 
   {
     R=100;G=0;B=100;
     Serial.println("colour changed to green "); 
   }
    else if(colour.equals(my_red)==1) 
   {
     R=255;G=0;B=0;
     Serial.println("colour changed to red "); 
   } 
   else
   {
     Serial.println(colour.equals(my_red));
     R=255;G=0; B=0 ;
     Serial.println("colour changed to default red"); 
   }
   mqttClient.publish("colour/status","colour changed");
  }

   if (strcmp(topic,matrix_stanby_text_topic ) == 0)
  {
    stanby_message_received="";
    virtualDisp->clearScreen();
    for (int i = 0; i < length; i++) 
   {
//      Serial.print((char)payload[i]); 
       stanby_message_received+= (char)payload[i];
   }
  }
   if (strcmp(topic,matrix_text_topic) == 0)
  {
    message_receieved="";
    virtualDisp->clearScreen();
    R=255;G=0;B=0;
    Serial.println("Message received from: "); 
    Serial.print(topic);
    for (int i = 0; i < length; i++) 
   {
//      Serial.print((char)payload[i]); 
        message_receieved += (char)payload[i];
   }
   mqttClient.publish("message/status","message");
   Serial.println("the string is ");
   Serial.println(message_receieved);
}
}
   void stanby_text(String text)
    {
     virtualDisp->clearScreen(); 
     virtualDisp->setFont(&NotoSansTelugu_Bold10pt8b);
     virtualDisp->setTextColor(virtualDisp->color565(R,G,B));
     virtualDisp->setCursor(6, virtualDisp->height()-10);
     virtualDisp->setTextSize(1); 
     virtualDisp->print(text);
    }
    
  void scroll_text(uint8_t ypos,unsigned long scroll_delay, String text, uint8_t colorR, uint8_t colorG, uint8_t colorB)
{
   uint16_t text_length = text.length();
   virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
//   virtualDisp->setFont(&jwala10pt7b);
   //virtualDisp->setFont(&AbhayaLibre_Regular9pt7b);
   for (int xpos=(Matrix_width); xpos>-(Matrix_width+text_length*7.5); xpos--)
    {
        mqttClient.loop();
        if(a)
        {
          break;
        }
        virtualDisp->setTextColor(virtualDisp->color565(colorR, colorG, colorB));
        virtualDisp->clearScreen();
        virtualDisp->setCursor(xpos, virtualDisp->height()-ypos);    
        virtualDisp->setTextSize(1);
        virtualDisp->print(text);
        delay(scroll_delay);
        yield();
        delay(scroll_delay/5);
        yield();
    }
    a=0;
}

 void setup_wifi() 
{
    delay(10);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) 
    {
       delay(500);
       Serial.print(".");
    }
    randomSeed(micros());
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
//    esp_macaddress = WiFi.macAddress();
    Serial.println("MAC address: ");
    Serial.println(WiFi.macAddress());
}

void reconnect()
{
      while (!mqttClient.connected())
      {
         if(WiFi.status() != WL_CONNECTED)
           {
              setup_wifi();
           }
             Serial.print("Attempting MQTT connection...");
            String clientId = "ESP32Client-";                         // Create a random client ID
            clientId += String(random(0xffff), HEX);                                    
          if(mqttClient.connect(clientId.c_str()))
         {
            Serial.println("MQTT Connected!");
            mqttClient.subscribe(matrix_text_topic);
            mqttClient.subscribe(matrix_colour_topic);
            mqttClient.subscribe(matrix_stanby_text_topic);
            
            mqttClient.publish("glowsignboard/status","reConnected");
            mqttClient.setCallback(callback);
         }
         else
         {
          Serial.print("failed, rc=");
          Serial.print(mqttClient.state());
          Serial.println(" try again in 5 seconds");
          // Wait 5 seconds before retrying
          delay(5000);
          Serial.print(".");
         }
      }
}

void setupMQTT() 
{
  mqttClient.setServer(mqttServer, mqttPort);
 // mqttClient.setCallback(callback);
}

void setup()         //Setup!
{
  Serial.println("Starting Esp32:");
  Serial.begin(115200);
  Serial.println("In setup");
  setup_wifi();
  setupMQTT();
  reconnect();
  HUB75_I2S_CFG mxconfig
  (
                PANEL_RES_X,   // module width
                PANEL_RES_Y,   // module height
                PANEL_CHAIN    // chain length
  );

  if (NUM_ROWS <= 1) 
  {
    Serial.println(F("There is no reason to use the VirtualDisplay class for a single horizontal chain and row!"));
  }
  dma_display = new MatrixPanel_I2S_DMA(mxconfig);
  dma_display->setBrightness8(192);    // range is 0-255, 0 - 0%, 255 - 100%
  if( not dma_display->begin() )
      Serial.println("****** I2S memory allocation failed ***********");
  virtualDisp = new VirtualMatrixPanel((*dma_display), NUM_ROWS, NUM_COLS, PANEL_RES_X, PANEL_RES_Y, SERPENT, TOPDOWN);
  virtualDisp->fillScreen(virtualDisp->color444(0, 0, 0)); 
  delay(2000);
  
}

void loop() 
{
  if ((WiFi.status() != WL_CONNECTED))
  {
    setup_wifi();
  }
  if(!mqttClient.connected())
   {
    reconnect();
   }
   Serial.println("in the main loop");
   mqttClient.loop();
   delay(500); 
   stanby_text(stanby_message_received);
   //delay(5000);
   Serial.println(stanby_message_received);
   Serial.println(R);
   Serial.println(G);
   Serial.println(B);
   //scroll_text(10,10,message_receieved,R,G,B);   
  
} 

@dileepkumar

Can you please subscribe to these topics below in your code and add a (Serial.print) to show the output?

scroll_message/store1
standby_message/store1
colour/store1

Kind regards,
Diego from HiveMQ Team

@Diego

telugu

the above message is the message i got for Telugu language
the message i sent is - హ

@Diego
Captur

the above message is the message i got for Hindi language
the message i sent is - न
i got correct message for hindi

@dileepkumar

PubSubClient library may need its buffer size increased to parse the payload result, you could try increasing the buffer size with setBufferSize() to something bigger.

mqttClient.setServer(mqttServer, mqttPort);
mqttClient.setBufferSize(2048);

Kind regards,
Diego from HiveMQ Team