【问题标题】:Cant send data to Firebase using AT commands无法使用 AT 命令向 Firebase 发送数据
【发布时间】:2019-05-27 22:39:49
【问题描述】:

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

SEND OK HTTP/1.1 400 错误请求服务器:nginx 日期:2019 年 5 月 27 日星期一 格林威治标准时间 22:34:09 内容类型:文本/html 内容长度:166 连接: 关闭 Strict-Transport-Security: max-age=31556926;包括子域; 预加载

400 错误请求

400 错误请求


nginx

关闭

我发出的 AT 命令是:

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

连接正常

AT+QISEND

>

POST /NewDB/.json

接受:应用程序/json

内容类型:application/json

内容长度:9

{"a":"b"}

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

任何帮助表示赞赏。

【问题讨论】:

  • 你的调制解调器类型是什么?您是否尝试将您的请求发送到 httpbin.org/post?
  • Modem 类型为 MC20,设备为 WIO Tracker Board:seeedstudio.com/…
  • 你能把你从启动调制解调器的第一刻起调用的所有AT命令都放进去吗?我的意思是您在发送 HTTP 请求之前可能没有正确配置调制解调器。
  • 不确定,部分原因是 arduino 库负责预先发送一些命令。您可以在此处找到库发出的 AT 命令序列:github.com/Seeed-Studio/Seeed_Wio_GPS_Board/blob/master/…
  • 顺便说一句,我尝试在 httpbin 上发帖,我收到 SEND OK,但没有收到任何反馈,所以不确定它是否有效。

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


【解决方案1】:

首先,尝试this 对SAM 芯片进行编程,以在Modem 和您的控制台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());
    }
}

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

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

3.2.向 HTTP 服务器发送 POST 请求

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

【讨论】:

    猜你喜欢
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多