无法使用 AT 命令将数据发送到 Firebase

Cant send data to Firebase using AT commands

我正在使用带有 GSM 调制解调器的 Arduino 来尝试将数据发送到 firebase。 但是,当我尝试时,出现以下错误:

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

我发出的AT命令是:

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"}

最后一行是实际负载。

感谢任何帮助。

首先,尝试 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,您可以设置调制解调器。)

一个简单的程序如下所示:

#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());
    }
}

另外,我建议你使用Arduino的串口监视器进行通讯。

如果调制解调器成功启动,您将在串行监视器中看到 SMS ReadyCall Ready。 根据 POST 请求的 Quectel HTTP 文档:

3.2。发送 POST 请求到 HTTP 服务器

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

例如 httpbin.org/post 它会变成这样:

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