• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
GPRS Request HTTP - moduł A6 GSM/GPRS - ERROR z GET
#1
dzień dobry,

Mam Arduino UNO i moduł A6 GSM/GPRS.


Kod:
#include <SoftwareSerial.h>
SoftwareSerial GSM(3,2);

void setup() {
  GSM.begin(9600);
  Serial.begin(9600);

  Serial.println("Start...");

  GSM.println("AT+CSQ");
  updateSerial();
  GSM.println("AT+CGATT=1");
  updateSerial();
  GSM.println("AT+CIPSTART=\"TCP\",\"testgolang.cba.pl\",80");
  updateSerial();
  delay(5000);
  GSM.println("at+cipsend");
  updateSerial();
  GSM.println("GET http://www.testgolang.cba.pl/index.php?a=ok HTTP/1.1");
  updateSerial();
  delay(5000);
//  GSM.println("");
  updateSerial();
//  GSM.println("");
  updateSerial();
//  GSM.println("");
//  updateSerial();
//  GSM.println("");
//  updateSerial();
}

void loop() {
  updateSerial();

}

void updateSerial(){
  delay(2000);
  while(Serial.available())
    GSM.write(Serial.read());
    
  while(GSM.available())
    Serial.write(GSM.read());
}


Kod PHP:
<?php
$timestamp 
date("d-m-Y - H:i:s");
$datastring $_REQUEST["a"];
$myfile fopen("newfile.txt""a") or die("Unable to open file!");
$txt $timestamp " - ".$datastring."\n";
fwrite($myfile$txt);
fclose($myfile);
echo 
$txt;
?>
Gdy program dochodzi do lini z kodem "GET http://www.testgolang.cba.pl/index.php?a=ok HTTP/1.1", to czeka i czeka pojawia się odpowiedz w postaci:

Kod:
13:41:33.619 -> AT+CIPSTART="TCP","testgolang.cba.pl",80
13:41:33.655 -> ⸮
13:41:40.644 -> CONNECT OK
13:41:40.644 -> 
13:41:40.644 -> OK
13:41:40.644 -> at+cipsend
13:41:40.644 -> 
13:41:40.644 -> > GET http://www.testgolang.cba.pl/index.php?a=ok HTTP/1.1
13:41:55.691 -> 
13:41:55.691 -> +TCPCLOSED:0
13:41:57.710 -> 
13:41:57.710 -> OK
13:41:57.710 -> ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
13:43:57.101 -> OK

Proszę o pomoc. 
 
Odpowiedź
#2
A co byś chciał żeby zrobił zamiast stać?
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
#3
Trochę poprawiłem mój kod i teraz mam z HTTP 400 Bad Request.



Kod:
#include <SoftwareSerial.h>
SoftwareSerial GSM(3,2);

void setup() {
  GSM.begin(9600);
  Serial.begin(9600);

  Serial.println("Start...");

  GSM.println("AT+CSQ");
  updateSerial();
  GSM.println("AT+CGATT=1");
  updateSerial();
  GSM.println("AT+CIPSTART=\"TCP\",\"testgolang.cba.pl\",80");
  updateSerial();
  delay(2000);
  GSM.println("at+cipsend=100, /index.php?a=ok HTTP/1.1");
  updateSerial();
 
}

void loop() {
  updateSerial();

}

void updateSerial(){
  delay(2000);
  while(Serial.available())
    GSM.write(Serial.read());
    
  while(GSM.available())
    Serial.write(GSM.read());
}



Kod:
22:42:02.749 -> Start...
22:42:04.759 -> AT+CSQ
22:42:04.759 -> 
22:42:04.759 -> +CSQ: 27,99
22:42:04.759 -> 
22:42:04.759 -> OK
22:42:06.781 -> AT+CGATT=1
22:42:06.781 -> 
22:42:06.781 -> OK
22:42:08.823 -> AT+CIPSTART="TCP","testgolang.cba.pl",80
22:42:08.859 -> 
22:42:08.859 -> CONNECT OK
22:42:08.859 -> 
22:42:08.859 -> OK
22:42:12.879 -> at+cipsend=100, /index.php?a=ok HTTP/1.1
22:42:12.917 -> 
22:42:12.917 -> OK
22:42:12.917 -> 
22:42:12.917 -> +CIPRCV:1344,HTTP/1.1 400 Bad Request
22:42:12.917 -> Server: nginx
22:42:12.955 -> Date: Fri, 22 Mar 2019 21:41:59 GMT
22:42:12.993 -> Content-Type: text/html
22:42:13.026 -> Connection: close
22:42:13.026 -> X-Host-Ip: 80
22:42:13.064 -> 
22:42:13.064 -> <html>
22:42:13.064 -> <head><title>400 Bad Request</title></head>
22:42:13.098 -> me">name</label>
22:42:13.136 ->             <div class="col-md-4">
22:42:13.172 ->                 <input id="cumf_bt_name" name="cumf_bt_name" type="text" placeholder="your name" class="cumf_bt_form-control cumf_bt_input-md" />
22:42:13.352 ->                 <span class="cumf_bt_help-block">Please enter your name</span>
22:42:13.387 ->             </div>
22:42:13.425 ->         </div>
22:42:13.425 ->         <!-- Text input-->
22:42:13.458 ->         <div class="cumf_bt_form-group">
22:42:13.492 ->             <label class="col-md-4 cumf_bt_control-label" for="cumf_bt_email">your email</label>
22:42:13.598 ->      
22:42:13.633 -> 
22:42:13.633 -> +CIPRCV:776,       <div class="col-md-4">
22:42:13.666 ->                 <input id="cumf_bt_email" name="cumf_bt_email" type="text" placeholder="enter your email" class="cumf_bt_form-control cumf_bt_input-md" />
22:42:13.845 ->                 <span class="cumf_bt_help-block">please enter your email</span>
22:42:13.918 ->             </div>
22:42:13.918 ->         </div>
22:42:13.918 ->         <!-- Textarea -->
22:42:13.953 ->         <div class="cumf_bt_form-group">
22:42:13.988 ->             <label class="col-md-4 cumf_bt_control-label" for="cumf_bt_message">your message</label>
22:42:14.130 ->             <div class="col-md-4">
22:42:14.166 ->                 <textarea class="cumf_bt_form-control" id="cumf_bt_message" name="cumf_bt_message">Message goes here</textarea>
22:42:14.316 ->             </div>
22:42:14.316 ->         </div>
22:42:14.316 ->         <input type="submit" id="cumf_bt_submit" value="Send"/>
22:42:14.390 ->     </fieldset>
22:42:14.390 -> </form>
22:42:14.423 -> </div></body>
22:42:14.423 -> </html>
22:42:14.423 -> 
22:42:14.423 -> 
22:42:14.423 ->
22:42:14.459 -> +TCPCLOSED:0
22:42:16.392 -> 
22:42:16.392 -> OK
22:44:15.352 -> 
22:44:15.352 -> OK
 
Odpowiedź
#4
(22-03-2019, 23:48)kaczakat napisał(a): A co byś chciał żeby zrobił zamiast stać?

Chciałbym wysłać dane na serwer.
Chciałbym, żeby mój kod wysłał Request-a GET zmienną "a" z wartością "ok", a server złapie to przez php i zapiszę tą wartość do pliku.
 
Odpowiedź
#5
Przetestuj skrypt czy działa prawidłowo bez modemu. A linijkę do PHP wysyłałem tak:
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
Oczywiście ty masz tam użyć na początku "at+cipsend".
No i jak poszukasz na tym forum PHP i MYSQL to ktoś już z tym walczył i rozwiązał problem, może akurat nie przez GSM, ale już wysyłasz i odbierasz, pozostało jeszcze co jest wysłane i jak obsłużone przez PHP.
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
#6
(23-03-2019, 00:19)kaczakat napisał(a): Przetestuj skrypt czy działa prawidłowo bez modemu. A linijkę do PHP wysyłałem tak:
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
Oczywiście ty  masz tam użyć na początku "at+cipsend".
No i jak poszukasz na tym forum PHP i MYSQL to ktoś już z tym walczył i rozwiązał problem, może akurat nie przez GSM, ale już wysyłasz i odbierasz, pozostało jeszcze co jest wysłane i jak obsłużone przez PHP.

Kod:
void setup() {
  GSM.begin(9600);
  Serial.begin(9600);

  Serial.println("Start...");

  GSM.println("AT+CSQ");
  updateSerial();
  GSM.println("AT+CGATT=1");
  updateSerial();
  GSM.println("AT+CIPSTART=\"TCP\",\"testgolang.cba.pl\",80");
  updateSerial();
  delay(2000);
  GSM.println("at+cipsend=80, GET /index.php?a=okok HTTP/1.1 \r\n Host: http://www.testgolang.cba.pl");
  delay(2000);
  GSM.println();
  updateSerial();

}


Zrobiłem jak mówiłeś, ale nadal ten sam problem, może trzeba dodać jakieś jeszcze nagłówki, żeby server wiedział, że to do niego. 

Kod:
Start...
10:44:35.350 -> AT+CSQ
10:44:35.350 -> 
10:44:35.350 -> +CSQ: 24,99
10:44:35.350 -> 
10:44:35.350 -> OK
10:44:37.358 -> AT+CGATT=1
10:44:37.358 -> 
10:44:37.358 -> OK
10:44:39.408 -> AT+CIPSTART="TCP","testgolang.cba.pl",80
10:44:39.442 -> ⸮
10:44:39.442 -> CONNECT OK
10:44:39.442 -> 
10:44:39.442 -> OK
10:44:45.500 -> at+cipsend=80, GET /index.php?a=okok HTTP/1.1 
10:44:45.537 ->  Host: http://www.testgolang.cba.pl
10:44:45.575 -> ⸮
10:44:45.575 -> 
10:44:45.575 -> OK
10:44:45.575 -> 
10:44:45.610 -> +CIPRCV:1344,HTTP/1.1 400 Bad Request
10:44:45.646 -> Server: nginx
10:44:45.646 -> Date: Sat, 23 Mar 2019 09:44:32 GMT
10:44:45.681 -> Content-Type: text/html
10:44:45.715 -> Connection: close
10:44:45.753 -> X-Host-Ip: 80
10:44:45.753 -> 
10:44:45.753 -> <html>
10:44:45.787 -> <head><title>400 Bad Request</title></head>
10:44:45.821 -> <body>
10:44:45.821 -> <center><h1>400 Bad Request</h1></center>
10:44:45.859 -> <hr><center>nginx</center>
10:44:45.859 -> <!--]--><div style="text-align:center;font-size:11px" class="cbalink"><a href="https://www.cba.pl/" title="darmowy hosting">Darmowy Hosting</a> CBA.PL<br/><br/></div>
10:44:46.077 -> <script type="text/javascript" src="//a5.cba.pl/r1.js"></script>
10:44:46.150 -> <div class="cumf_bt_form_wrapper" style="display:none">
10:44:46.188 -> <form id="contact_us_mail_feedback" action="/oldTi9QvqM6ytokU9Q8ylQq" method="post">
10:44:46.264 ->     <fieldset>
10:44:46.301 ->         <!-- Form Name -->
10:44:46.301 ->         <legend>Contact Us</legend>
10:44:46.338 ->         <!-- Text input-->
10:44:46.375 ->         <div class="cumf_bt_form-group">
10:44:46.445 ->             <label class="col-md-4 cumf_bt_control-label" for="cumf_bt_name">name</label>
10:44:46.516 ->             <div class="col-md-4">
10:44:46.586 ->                 <input id="cumf_bt_name" name="cumf_bt_name" type="text" placeholder="your name" class="cumf_bt_form-control cumf_bt_input-md" />
10:44:46.690 ->                 <span class="cumf_bt_help-block">Please enter your name</span>
10:44:46.796 ->             </div>
10:44:46.796 ->         </div>
10:44:46.834 ->         <!-- Text input-->
10:44:46.834 ->         <div class="cumf_bt_form-group">
10:44:46.906 ->             <label class="col-md-4 cumf_bt_control-label" for="cumf_bt_email">your email</label>
10:44:47.008 ->      
10:44:47.008 -> 
10:44:47.008 -> +CIPRCV:776,       <div class="col-md-4">
10:44:47.046 ->                 <input id="cumf_bt_email" name="cumf_bt_email" type="text" placeholder="enter your email" class="cumf_bt_form-control cumf_bt_input-md" />
10:44:47.190 ->                 <span class="cumf_bt_help-block">please enter your email</span>
10:44:47.298 ->             </div>
10:44:47.298 ->         </div>
10:44:47.333 ->         <!-- Textarea -->
10:44:47.366 ->         <div class="cumf_bt_form-group">
10:44:47.400 ->             <label class="col-md-4 cumf_bt_control-label" for="cumf_bt_message">your message</label>
10:44:47.508 ->             <div class="col-md-4">
10:44:47.543 ->                 <textarea class="cumf_bt_form-control" id="cumf_bt_message" name="cumf_bt_message">Message goes here</textarea>
10:44:47.684 ->             </div>
10:44:47.721 ->         </div>
10:44:47.721 ->         <input type="submit" id="cumf_bt_submit" value="Send"/>
10:44:47.756 ->     </fieldset>
10:44:47.789 -> </form>
10:44:47.789 -> </div></body>
10:44:47.789 -> </html>
10:44:47.827 -> 
10:44:47.827 -> 
10:44:47.827 ->
10:44:47.827 -> +TCPCLOSED:0
10:44:49.779 -> 
10:44:49.779 -> OK
10:44:51.787 -> ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
10:46:49.768 -> OK
 
Odpowiedź
#7
Pokaż skrypt PHP.
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
#8
Kod:
<?php
$timestamp = date("d-m-Y - H:i:s");
$datastring = $_REQUEST["a"];
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt = $timestamp . " - ".$datastring."\n";
fwrite($myfile, $txt);
fclose($myfile);
echo $txt;
?>
 
Odpowiedź
#9
(23-03-2019, 14:40)kaczakat napisał(a): Pokaż skrypt PHP.

Dziwna sytuacja, szukam po forach rozwiązania tego problemu i można powiedzieć, że jestem bezsił. 
A mów kod w C jest w miarę, chodzi mi, czy posiada wszystkie komendy AT?

Kod:
#include <SoftwareSerial.h>
SoftwareSerial GSM(3,2);

String url = "/index.php?a=ok";
String host = "http://www.testgolang.cba.pl";
String sendMe = String("GET ") + url + " HTTP/1.1 \r\n" + "Host: "+host+"\r\n"+"Connection: close\r\n\r\n";

void setup() {
  GSM.begin(9600);
  Serial.begin(9600);

  Serial.println("Start...");

  GSM.println("AT+CSQ");
  updateSerial();
  GSM.println("AT+CGATT=1");
  updateSerial();
  GSM.println("AT+CIPSTART=\"TCP\",\"testgolang.cba.pl\",80");
  updateSerial();
  delay(2000);
  GSM.println("at+cipsend=80, GET /index.php?a=okok HTTP/1.1 \r\n Host: http://www.testgolang.cba.pl");
  delay(2000);
  GSM.println();
  updateSerial();

}

void loop() {
  updateSerial();

}

void updateSerial(){
  delay(2000);
  while(Serial.available())
    GSM.write(Serial.read());
    
  while(GSM.available())
    Serial.write(GSM.read());
}
 
Odpowiedź
#10
Dobra, sprawdziłem, wykasuj sobie moje wpisy z tego pliku no i pewnie teraz dodaj autoryzację.
Twoja linijka wysłana do serwera wysłana przez modem powinna wyglądać tak: "GET  index.php?a=OK  HTTP/1.1\r\n Host: testgolang.cba.pl \r\n Connection: close Connection: close\r\n\r\n"
A w szkicu, jednak dla ESP8266, bo nie mam modemu pod ręką to wygląda tak:


Kod:
#include <ESP8266WiFi.h>
const char* ssid= "x";
const char* password = "x";
const int httpPort = 80;
const char* host = "testgolang.cba.pl"; //IP lub adres serwera  

 

void setup() {
 Serial.begin(115200);
 WiFi.begin(ssid, password);  
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
Serial.println(WiFi.localIP());
}
void loop() {



  WiFiClient client; //wysylanie do PHP i MySQL
  if (!client.connect(host, httpPort)) {
   Serial.println("connection failed");
   
 }
 else
 {
String url = "/index.php?";
   url += "a=OK";

 client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");  
 
 Serial.println("Koniec wysylania");  
   unsigned long timeout = millis();
   while (client.available() == 0) {
     delay(1);
     if (millis() - timeout > 5000) {
       Serial.println(">>> Client Timeout !");
       
       client.stop();
       return;
     }
   }
 
   // Read all the lines of the reply from server and print them to Serial
   while(client.available()){
     String line = client.readStringUntil('\r');
     Serial.print(line);
   }
 }
 delay(5000);              
}
 Z palca w przeglądarce Chrome można wpisać: testgolang.cba.pl/index.php?a=ok
Odpowiedz jest długa, ale początek jest OK:

Kod:
Koniec wysylania
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 24 Mar 2019 02:55:58 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
X-Powered-By: PHP/5.6.40
X-Host-Ip: 80
Access-Control-Allow-Origin: *

483
<div style="text-al
...
Posklejaj sobie to do cipsend i powinno być to samo.
Edit:
A, i jeszcze jeden, mały, błękitny opłateczek w niedzielę. Sprawdź sobie wysłanie znaków \r\n jako tekst, czyli musisz przesłać w tekście do modemu "\r\n", a w programie to powinno być zapisane ""\\r\\n"".
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości