Reputation: 11
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>
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
Upvotes: 0
Views: 71