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

时间:2019-05-27 22:39:49

标签: firebase firebase-realtime-database arduino gsm at-command

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

  

发送OK HTTP / 1.1 400错误的请求服务器:nginx日期:2019年5月27日,星期一   22:34:09 GMT内容类型:text / html内容长度:166连接:   关闭严格的传输安全性:max-age = 31556926; includeSubDomains;   预载

     

400错误的请求

400错误的请求

  
nginx

     

关闭

我发出的AT命令是:

  

AT + QIOPEN =“ TCP”,“ drone-polution.firebaseio.com”,443   确定

     

连接正常

     

AT + QISEND

     

>

     

POST /NewDB/.json

     

接受:application / json

     

内容类型:application / json

     

内容长度:9

     

{“ a”:“ b”}

最后一行是实际有效载荷。

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

首先,尝试this对SAM芯片进行编程以在Modem和您的Console PC之间创建一个接口(我发现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());
    }
}

如果您使用以前与MODEM进行的直接通信,但是我建议您使用Arduino的串行监视器进行通信。

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

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