0

I want to send data to Firebase Realtime Database using stm32f4 and esp-01 wifi module.

this is how I tried to connect and send to firebase Realtime Database connect firebase and send message funciton

void fireBaseConnectSend(char *firebaseUrl,char 
*firebaseAuthKey,char *sampleData)
{

char postRequest[500];
char data[100];
sprintf(postRequest, "POST /data.json HTTP/1.1\r\n");
strcat(postRequest, "Host: ");
strcat(postRequest, firebaseUrl);
strcat(postRequest, "\r\n");
strcat(postRequest, "Content-Type: application/json\r\n");
sprintf(data, "Content-Length: %d\r\n", strlen(sampleData));
strcat(postRequest, data);
strcat(postRequest, "Authorization: key=");
strcat(postRequest, firebaseAuthKey);
strcat(postRequest, "\r\n\r\n");
strcat(postRequest, sampleData);

Uart_flush();
Uart_sendstring("AT+CIPSTART=\"TCP\",\"");
Uart_sendstring(firebaseUrl);
Uart_sendstring("\",443\r\n");
HAL_Delay(500);
char chipsend[100];
sprintf(chipsend,"AT+CIPSEND=%d\r\n",strlen(postRequest));
Uart_sendstring(chipsend);
HAL_Delay(500);
Uart_sendstring(postRequest);
}

here I tried to send this text

POST /data.json HTTP/1.1
Host: sera-37bfe-default-rtdb.europe-west1.firebasedatabase.app
Content-Type: application/json
Content-Length: <message Lenght>
Authorization: key=fxzpXdBWhZZeyfRCDOwWfD4YVp3lAusIytFMzxqh

<Message>

calls the function

fireBaseConnectSend(HOSTAPP, authKey, " 
{\"sensor\":\"temperature\",\"value\":25}");

The message returned from ESP esp message it connects to the fireabase but I think firebase doesn't recognize my message and I couldnt find the solution.

this is my esp initialize esp initialize

void ESP_Init (char *SSID, char *PASSWD, char *STAIP)
{
char data[80];

Ringbuf_init();

Uart_sendstring("AT+RST\r\n");
HAL_Delay(2000);

/********* AT **********/
Uart_flush();
Uart_sendstring("AT\r\n");
while(!(Wait_for("OK\r\n")));


/********* AT+CWMODE=1 **********/
Uart_flush();
Uart_sendstring("AT+CWMODE=1\r\n");
while (!(Wait_for("OK\r\n")));

/* Set Static IP Address */
/********* AT+CWSTAIP=IPADDRESS **********/
Uart_flush();
sprintf (data, "AT+CIPSTA=\"%s\"\r\n", STAIP);
Uart_sendstring(data);
while (!(Wait_for("OK\r\n")));

/********* AT+CWJAP="SSID","PASSWD" **********/
Uart_flush();
sprintf (data, "AT+CWJAP=\"%s\",\"%s\"\r\n", SSID, PASSWD);
Uart_sendstring(data);
while (!(Wait_for("OK\r\n")));

/********* AT+CIPMUX **********/
Uart_flush();
Uart_sendstring("AT+CIPMUX=0\r\n");
while (!(Wait_for("OK\r\n")));
}

I was expecting something like this expected

3
  • 2
    On Stack Overflow, please don't show pictures of text and code. Copy the text into the question itself and format it so that it's easy to read, copy, and search. You can edit the question to correct this using the edit link at the bottom. Commented Mar 21, 2024 at 13:16
  • What is the sampleData looks like? You set the content type as application/json but according to the error message, you seems sending the plain text instead of a serialised json object. Commented Mar 22, 2024 at 4:55
  • {\"sensor\":\"temperature\",\"value\":25} this is the sampleData I tried to send Commented Mar 23, 2024 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.