title: How to fix this Firebase message format sent from ESP32 (Arduino, ESP-IDF - all text, no Firebase library used)
body: <p>I'm trying to get this code below to work which was working perfectly a year ago the last time I tried it. After running it I receive no notification in my app. Using in Arduino IDE on ESP32 module. No changes were made at all to the sketch that was once working other than updating the token. I do not get the "firebase error" message in the serial output so assuming no error.</p>
  
  <pre><code>WiFiClient client;
  String serve = "MY SERVER KEY";
  String appToken = "MY APP TOKEN";
  String data = "{";
  data = data + "\"to\": \"" + appToken + "\",";
  data = data + "\"notification\": {";
  data = data + "\"body\": \"example body\",";
  data = data + "\"title\" : \"my title\" ";
  data = data + "} }";
  
  Serial.println("Send data...");
  if (client.connect("fcm.googleapis.com", 80)) {
    Serial.println("Connected to the server..");
    client.println("POST /fcm/send HTTP/1.1");
    client.println("Authorization: key=" + serve + "");
    client.println("Content-Type: application/json");
    client.println("Host: fcm.googleapis.com");
    client.print("Content-Length: ");
    client.println(data.length());
    client.print("\n");
    client.print(data);
    Serial.println("data");
    Serial.println(data);
  
  }
  else {
    Serial.println("firebase error");
  }
  Serial.println("Data sent...Reading response..");
  while (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  Serial.println("Finished!");
  client.flush();
  client.stop();
  }
  </code></pre>
  
  <p>I just updated Firebase in my app and migrated to AndroidX and can receive messages sent from the Firebase console and I'm currently using <a href="https://github.com/mobizt/Firebase-ESP32/blob/master/examples/Cloud_Messaging/Cloud_Messaging.ino" rel="nofollow noreferrer">this library</a> successfully to send and receive the notifications in my app. Below is the example I'm using and it's working perfectly.</p>
  
  <pre><code>#include &lt;WiFi.h&gt;
  #include &lt;FirebaseESP32.h&gt;
  
  #define WIFI_SSID "YOUR_WIFI_AP"
  #define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
  #define FIREBASE_HOST "YOUR_FIREBASE_PROJECT.firebaseio.com" //Do not include https:// in FIREBASE_HOST
  #define FIREBASE_AUTH "YOUR_FIREBASE_DATABASE_SECRET"
  
  #define FIREBASE_FCM_SERVER_KEY "YOUR_FIREBASE_PROJECT_CLOUD_MESSAGING_SERVER_KEY"
  #define FIREBASE_FCM_DEVICE_TOKEN_1 "RECIPIENT_DEVICE_TOKEN"
  #define FIREBASE_FCM_DEVICE_TOKEN_2 "ANOTHER_RECIPIENT_DEVICE_TOKEN"
  
  FirebaseData firebaseData1;
  
  unsigned long lastTime = 0;
  
  int count = 0;
  
  void sendMessage();
  
  void setup()
  {
  
      Serial.begin(115200);
  
      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
      Serial.print("Connecting to Wi-Fi");
      while (WiFi.status() != WL_CONNECTED)
      {
          Serial.print(".");
          delay(300);
      }
      Serial.println();
      Serial.print("Connected with IP: ");
      Serial.println(WiFi.localIP());
      Serial.println();
  
      Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
      Firebase.reconnectWiFi(true);
  
      firebaseData1.fcm.begin(FIREBASE_FCM_SERVER_KEY);
  
      firebaseData1.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_1);
  
      firebaseData1.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_2);
  
      firebaseData1.fcm.setPriority("high");
  
      firebaseData1.fcm.setTimeToLive(1000);
  
      sendMessage();
  }
  
  void loop()
  {
  
      if (millis() - lastTime &gt; 60 * 1000)
      {
          lastTime = millis();
  
          sendMessage();
      }
  }
  
  void sendMessage()
  {
  
      Serial.println("------------------------------------");
      Serial.println("Send Firebase Cloud Messaging...");
  
      firebaseData1.fcm.setNotifyMessage("Notification", "Hello World! " + String(count));
  
      firebaseData1.fcm.setDataMessage("{\"myData\":" + String(count) + "}");
  
      //if (Firebase.broadcastMessage(firebaseData1))
      //if (Firebase.sendTopic(firebaseData1))
      if (Firebase.sendMessage(firebaseData1, 0))//send message to recipient index 0
      {
  
          Serial.println("PASSED");
          Serial.println(firebaseData1.fcm.getSendResult());
          Serial.println("------------------------------------");
          Serial.println();
      }
      else
      {
          Serial.println("FAILED");
          Serial.println("REASON: " + firebaseData1.errorReason());
          Serial.println("------------------------------------");
          Serial.println();
      }
  
      count++;
  }
  </code></pre>
  
  <p>I've tried sending the code at the top in data and notification message format with app in foreground and background and cannot receive a message. I'm wondering if something in the Firebase format or rules or such has changed within the last year. I need to use the code at the top instead of the library because I can just add a few more key value pairs in the message body and also send to iOS which I have done successfully in the past using the same code. I'm sure the key pairs could be added with the library actually which I'm working on now but would really prefer the simplicity of the top code. Would appreciate any advice.</p>