Search code examples
firebasefirebase-realtime-databasearduinogsmat-command

Cant send data to Firebase using AT commands


I'm using an Arduino with a GSM modem to try to send data to firebase. However, when I try to, I get the following error:

SEND OK HTTP/1.1 400 Bad Request Server: nginx Date: Mon, 27 May 2019 22:34:09 GMT Content-Type: text/html Content-Length: 166 Connection: close Strict-Transport-Security: max-age=31556926; includeSubDomains; preload

400 Bad Request

400 Bad Request


nginx

CLOSED

The AT commands I issue are:

AT+QIOPEN="TCP", "drone-polution.firebaseio.com", 443 OK

CONNECT OK

AT+QISEND

>

POST /NewDB/.json

Accept: application/json

Content-Type: application/json

Content-Length: 9

{"a":"b"}

The last line is the actual payload.

Any help appreciated.


Solution

  • First, try this to program SAM chip to create an interface between Modem and your console PC (I found that there are good ready functions in MC20_Arduino_Interface.h which you can setup the modem.)

    A simple program looks like this:

    #include "MC20_Arduino_Interface.h"
    
    // set serial port that connects to MC20
    //#define serialMC20 Serial1
    
    void setup()
    {
        //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
        SerialUSB.begin(115200);
        while (!Serial);
    
        //Being serial communication witj Arduino and MC20
        serialMC20.begin(115200);
        delay(1000);
    
        SerialUSB.println("Setup Complete!");
    }
    
    void loop()
    {
        //Read MC20 output (if available) and print it in Arduino IDE Serial Monitor
        if (serialMC20.available())
        {
            SerialUSB.write(serialMC20.read());
        }
        //Read Arduino IDE Serial Monitor inputs (if available) and send them to MC20
        if (SerialUSB.available())
        {
            serialMC20.write(SerialUSB.read());
        }
    }
    

    Also, I suggest you use Arduino's serial monitor for communication.

    If the Modem starts successfully you will see SMS Ready and Call Ready in the serial monitor. According to Quectel HTTP docs for a POST request:

    3.2. Send POST Request to HTTP Server

    AT+QIFGCNT=0
    OK
    AT+QICSGP=1,"CMNET" //Set APN
    OK
    AT+QIREGAPP //Optional
    OK
    AT+QIACT //Optional
    OK
    AT+QHTTPURL=58,30 //Set URL
    CONNECT
    <Input data>
    //For example, input 58 bytes:
    http://api.efxnow.com/DEMOWebServices2.8/Service.asmx/Echo
    OK
    //POST the data whose size is 18 bytes and the maximum latency time for inputting is 50s.
    //It is recommended to set the latency time as long as enough to download all the data in the latency time.
    AT+QHTTPPOST=18,50,10
    CONNECT
    //This means module enters into data mode and is ready to receive data from UART.
    //For example, input 18 bytes: Message=helloworld.
    OK
    //This means all data has been received, and DCD is set to high.
    AT+QHTTPREAD=30 //Read the response of HTTP server.
    CONNECT
    <Output data> //Output the response data of HTTP server to UART.
    //For example, UART outputs:
    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="https://api.efxnow.com/webservices2.3">Message='helloworld' ASCII:104 101 108 108
    111 119 111 114 108 100 </string>
    OK
    AT+QIDEACT //Deactivate PDP context.
    DEACT OK
    

    For example for httpbin.org/post it would become something like this:

    16:45:56.416 -> AT+QIFGCNT=0
    16:45:56.416 -> OK
    16:46:02.918 -> AT+QICSGP=1,"mtnirancell"
    16:46:02.918 -> OK
    16:46:07.850 -> AT+QIREGAPP
    16:46:07.850 -> OK
    16:46:12.275 -> AT+QIACT
    16:46:12.275 -> OK
    16:46:27.467 -> AT+QHTTPURL=23,60
    16:46:27.467 -> CONNECT
    16:46:27.467 -> <http://httpbin.org/post>
    16:46:36.965 -> OK
    16:46:36.965 -> 
    16:46:48.786 -> AT+QHTTPPOST=18,50,10
    16:46:48.786 -> CONNECT
    16:46:48.786 -> <message=helloworld>
    16:47:02.094 -> OK
    16:47:02.094 -> 
    16:47:06.569 -> AT+QHTTPREAD=30
    16:47:06.569 -> CONNECT
    16:47:06.569 -> {
    16:47:06.569 ->   "args": {}, 
    16:47:06.569 ->   "data": "", 
    16:47:06.569 ->   "files": {}, 
    16:47:06.569 ->   "form": {
    16:47:06.569 ->     "message": "helloworld"
    16:47:06.569 ->   }, 
    16:47:06.569 ->   "headers": {
    16:47:06.569 ->     "Accept": "*/*", 
    16:47:06.569 ->     "Content-Length": "18", 
    16:47:06.569 ->     "Content-Type": "application/x-www-form-urlencoded", 
    16:47:06.602 ->     "Host": "httpbin.org", 
    16:47:06.602 ->     "User-Agent": "QUECTEL_MODULE"
    16:47:06.602 ->   }, 
    16:47:06.602 ->   "json": null, 
    16:47:06.602 ->   "origin": "*******, ********", 
    16:47:06.602 ->   "url": "https://httpbin.org/post"
    16:47:06.602 -> }
    16:47:06.602 -> OK