Arduino mega + esp 8266发送获取请求 [英] Arduino mega + esp 8266 sending get request

查看:580
本文介绍了Arduino mega + esp 8266发送获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用这个URL访问我的php scipt并输入数据:
arduino.byethost22.com/FirebaseTest.php?slot1_data=empty&slot2_data=occupied

我已经试过了,它能够将slot1_data存储为空,并将slot2_data存储为占用。不过,我需要使用arduino发送此网址。我现在正在使用这个代码
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $#$##$ DEBUG false //打开调试信息打开或关闭串行
String server =arduino.byethost22.com;
String uri =/FirebaseTest.php?slot1_data=empty&slot2_data=occupied;

void setup(){

Serial3.begin(115200); // serial3 for esp8266
Serial.begin(115200);
sendData(AT + RST \r\\\
,2000,DEBUG); //复位模块
sendData(AT + CWMODE = 3 \r\\\
,1000,DEBUG); //配置为接入点
// sendData(AT + CWJAP = \WifiName\,\Password\\r\\\
,3000,DEBUG);
//延迟(20000);
sendData(AT + CIFSR \r\\\
,1000,DEBUG); //获取IP地址
sendData(AT + CIPMUX = 0 \r\\\
,1000,DEBUG); //配置单连接





Serial3.println(AT + CIPSTART = \\ \\TCP \,\+ server +\,80); //启动一个TCP连接。
if(Serial3.find(OK)){
Serial.println(TCP connection ready);
}
delay(1000);
String getRequest =GET+ uri +HTTP / 1.1 \r\\\
+
Host:+ server +\r\\\
\r\\\
;

String sendCmd =AT + CIPSEND =; //确定要发送的字符数。
Serial3.print(sendCmd);
Serial3.println(getRequest.length());
延迟(500);
if(Serial3.find(>)){
Serial.println(Sending ..);
}
Serial3.print(getRequest); (发送确认)){
Serial.println(Packet sent);
if(Serial3.find $()

while(Serial3.available()){
String tmpResp = Serial3.readString();
Serial.println(tmpResp);
}

延迟(20000);





$ b字符串sendData(字符串命令,const int超时,布尔调试)
{
String response =;

Serial3.print(command); //将读取的字符发送给esp8266

long int time = millis(); ((time + timeout)> millis())
{
while(Serial3.available())
{
$ b $(

) b // esp有数据显示输出到串口窗口
char c = Serial3.read(); //读下一个字符
response + = c;



if(debug)
// {
Serial.print(response);
//}

return response;
}

似乎有问题将获取请求发送到php脚本。 / p>

我正在使用串口监视器发送数据包,但firebase数据中没有任何更改

我也越来越

  + IPD,1104:HTTP / 1.1 200 OK 
服务器:nginx
日期:10月15日,星期六2016 09:21:34 GMT
内容类型:text / html
内容长度:875
连接:保持活动
变化:接受编码
过期:Thu,01 Jan 1970 00:00:01 GMT
Cache-Control:no-cache

< html>< body>< script type =text / javascriptsrc (d){var e = []; d.replace(/())/g,function(d){e.push){/ /脚本>脚本> (parseInt(d,16))}); return e} function toHex(){for(var d = [],d = 1 == arguments.length&&& amp; arguments [0] .constructor == Array?arguments [ 0]:参数,E = ?中,f = 0; F< d.length;˚F++)E + =(16取代; d [F]为 0: )+ d [F]的ToString(16);返回e.toLowerCase()} var a = toNumbers(f655ba9d09a11 2d4968c63579db590b4 ),B = toNumbers( 98344c2eee86c3994890592585b49f80 ),C = toNumbers( b5ebc3b806c39a4a7fc1e4cecb45feab );的document.cookie = __测试= + toHex(slowAES.decrypt(C,2,A,B))+;到期时间=星期四,31-Dec-37 23:55:55 GMT; path = /; location.href =http://arduino.byethost22.com/FirebaseTest.php?slot1_data=0&slot2_data=1&i=1;< / script>< noscript>该网站需要使用Javascript工作,请在您的浏览器中启用Javascript或使用支持JavaScript的浏览器< / noscript>< / body>< / html>

它让我在浏览器中启用javascript,但是我使用的是arduino,我该怎么做呢?
当我在谷歌浏览器中键入相同的URI时,数据可以更新



我该如何解决这个问题? 我的代码终于可以工作,并在线发送数据。我更改为使用000webhost作为我的主机服务器,而不是通过和数据管理更新。

我真的不知道为什么,但我猜测byethost不支持javascript。


i have a php script which help to store data into google firebase.

i am using this url to access my php scipt and input the data: arduino.byethost22.com/FirebaseTest.php?slot1_data=empty&slot2_data=occupied

i have tried it and it is able to store slot1_data as empty and slot2_data as occupied. However i need to use arduino to send this url. i am using this code currently

#include "SoftwareSerial.h"
#define DEBUG false  // turn debug message on or off in serial
String server = "arduino.byethost22.com";
String uri = "/FirebaseTest.php?slot1_data=empty&slot2_data=occupied";

void setup() {

  Serial3.begin(115200); //serial3 for esp8266
  Serial.begin(115200);
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+CWMODE=3\r\n",1000,DEBUG); // configure as access point
  //sendData("AT+CWJAP=\"WifiName\",\"Password\"\r\n",3000,DEBUG);
  //delay(20000);
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=0\r\n",1000,DEBUG); // configure for single connections

}

void loop() {


Serial3.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
if( Serial3.find("OK")) {
Serial.println("TCP connection ready");
} 
delay(1000);
String getRequest = "GET " + uri + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n\r\n";

String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
Serial3.print(sendCmd);
Serial3.println(getRequest.length() );
delay(500);
if(Serial3.find(">")) { 
  Serial.println("Sending..");
}
Serial3.print(getRequest);
if( Serial3.find("SEND OK")) { 
  Serial.println("Packet sent");
}
while (Serial3.available()) {
String tmpResp = Serial3.readString();
Serial.println(tmpResp);
}

delay(20000);
}





String sendData(String command, const int timeout, boolean debug)
{
String response = "";

Serial3.print(command); // send the read character to the esp8266

long int time = millis();

while( (time+timeout) > millis())
{
while(Serial3.available())
{

// The esp has data so display its output to the serial window
char c = Serial3.read(); // read the next character.
response+=c;
}
}

//if(debug)
//{
Serial.print(response);
//}

return response;
}

it seems that it have problem sending the get request to the php script.

i am getting packet sent in the serial monitor but nothing changed in the firebase data

i am also getting

+IPD,1104:HTTP/1.1 200 OK
Server: nginx
Date: Sat, 15 Oct 2016 09:21:34 GMT
Content-Type: text/html
Content-Length: 875
Connection: keep-alive
Vary: Accept-Encoding
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("b5ebc3b806c39a4a7fc1e4cecb45feab");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://arduino.byethost22.com/FirebaseTest.php?slot1_data=0&slot2_data=1&i=1";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

It asked me to enable javascript in my browser, but i am using arduino, how do i do it? When i key in the same uri in google chrome, the data can be updated

how do i solve this problem?

解决方案

My code finally can work and send data online. i change to use 000webhost as my host server instead of byethost and the data manage to be updated.

i dont really know why but i guess that byethost dont support javascript.

这篇关于Arduino mega + esp 8266发送获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆