我的Raspberry Pi(运行Node.js)和GSM900附加板v2.0一直在解决开/关问题。 我想将大约40 kB的JPEG以及一些其他信息(id,分配的IP和时间戳)传输到中央服务器。在另一端,我有一个PHP文件。目前,它只是将接收到的内容发送到一个文件中……这对于测试目的是很好的。 传输结束后,服务器在服务器上创建了一个漂亮的空JPEG文件-从未写入任何数据。
POST请求的格式可能只是错误的格式-如果是这样,您能帮我改正吗?只要图像可以工作,就可以将图像二进制转换或使用base64编码(JSON /非JSON)传输就不重要了。
我尝试了两种方法:CIPSEND和HTTP,并已签出(感觉像)数百个页面...但是它们似乎都没有解决“较大”数据块的传输,只有简单的参数(如a = 0&b) = 1等 多亏了serial-at库,每个命令都会很好地排队等候。
console.log(await port.at('AT+CGATT=1'));
console.log(await port.at('AT+SAPBR=3,1,"APN","internet"'));
console.log(await port.at('AT+SAPBR=1,1'));
console.log(await port.at('AT+HTTPINIT'));
console.log(await port.at('AT+HTTPPARA="CID",1'));
//console.log(await port.at('AT+HTTPPARA="CONTENT","multipart/form-data; boundary=myboundary"'));
console.log(await port.at('AT+HTTPPARA="CONTENT","application/x-www-form-urlencoded"'));
console.log(await port.at('AT+HTTPPARA="URL","http://www.myserver.com/index.php"'));
var data = 'POST / HTTP/1.1 \r\n \
Host: XXX.XXX.XXX.XXX \r\n \ <- I was unable to obtain the IP, except when using AT+CIFSR
Content-Type: text/html; charset=utf-8 \r\n \
Content-Length: 14 \r\n \ <- the length of the content, not including header. "\r\n" counts as two characters, I have read.
\r\n \
image=123456\r\n'; <- 14... 12 + 2 special characters. It doesn't transmit the bitmap at the moment, only these simple data.
console.log(await port.at('AT+HTTPDATA='+data.length+',30000'));
console.log(await port.at(data));
console.log(await port.at('AT+HTTPACTION=1'));
console.log(await port.at('HTTPTERM'));
console.log(await port.at('AT+SAPBR=0,1'));
它是这样回应的:
AT+CGATT=1
OK
AT+SAPBR=3,1,"APN","internet"
OK
AT+SAPBR=1,1
OK
AT+CIFSR
ERROR
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="CONTENT","application/x-www-form-urlencoded"
OK
AT+HTTPPARA="URL","http://www.myserver.com/index.php"
OK
AT+HTTPDATA=149,10000 <- the complete length of the query with header and all
DOWNLOAD
OK
AT+HTTPACTION=1
OK
HTTPTERM
+HTTPACTION: 1,200,120 <- seems like "POST", "OK" and 120 which might be a "informational status" of some kind
AT+SAPBR=0,1
OK
服务器文件仅包含以下内容:
<?php
file_put_contents("detections/test.jpg", $_REQUEST['image']); // yes, yes - no validation or anything... yet.
?>
如上所述,我还使用了另一种方法(AT + CIPSEND)来发送它,使用TCP ...但是它甚至没有调用服务器文件。
我在正确的轨道上吗?