Pages: [1]   Go Down
Author Topic: GSM - GET HTTP request via a php file  (Read 744 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Arduino!

I'm trying to send data from my arduino mega which has attached a GPRS module.

Connection and setup for GPRS module it was a success, also the backend part but i have some trouble with connect to my php file.

Take a look on my short code. maybe you can figure what's my problem easily.

Code:
// include the GSM library
#include <GSM.h>

// PIN number if necessary
#define PINNUMBER ""

// APN information obrained from your network provider
#define GPRS_APN       "web.vodafone.de" // replace with your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password

// initialize the library instances
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// This example downloads the URL "http://arduino.cc/latest.txt"

char server[] = "agroaktiv.de";//"agroaktiv.de"; // the base URL
char path[] = "/wetterstation/status.php?device=fromtheroof&temp1=30&temp2=12&rainfall=0"; // the path
int port = 80; // the port, 80 for HTTP

void setup()
{
  // initialize serial communications
  Serial.begin(9600);
  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // pass the PIN of your SIM as a parameter of gsmAccess.begin()
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port))
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    Serial.print("GET ");
    client.print(path);
    Serial.print(path);
    client.println(" HTTP/1.0");
    Serial.println(" HTTP/1.0");
    client.println();
    Serial.println();
  }
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

This is what I get
Code:
Starting Arduino web client.
connecting...
connected
GET /wetterstation/status.php?device=fromtheroof&temp1=30&temp2=12&rainfall=0 HTTP/1.0

HTTP/1.1 404 Not Found
Content-Length: 191     
Server: nginx
Date: Fri, 09 May 2014 10:21:01 GMT
Content-Type: text/html
Last-Modified: Mon, 09 Dec 2013 10:57:51 GMT
ETag: "82cda-3bf-4ed17de070608"
Accept-Ranges: bytes
X-Powered-By: PleskLin
MS-Author-Via: DAV
Connection: close

<HTML><HEAD><TITLE>404 Not Found</TITLE> </HEAD><BODY><H1>Not Found</H1>The requested document was not found on this server.<P><HR><ADDRESS>Web Server at v681.ncsrv.de</ADDRESS></BODY></HTML>

disconnecting.

I don't know what to say more.

Cheers,
Gabriel
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is how it should be.
Be sure to test status.php using a form.php to post it.


client.print("GET http://agroaktiv.de/wetterstation/status.php?device=fromtheroof&temp1=30&temp2=12&rainfall=0");
client.println(" HTTP/1.1\r\n");
client.println("Host: agroaktiv.de");

Good luck!
Logged

Pages: [1]   Go Up
Jump to: