Go Down

Topic: GSM - GET HTTP request via a php file (Read 1 time) previous topic - next topic

GabrielSoare

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: [Select]
// 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: [Select]
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

zumiki

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!

ArmGsm

Hi
i have problem
i have Arduino UNO And Arduino GSM shield
i have Sim card

i wanto to turn on/off led via internet

i dont know how can i configure GSM, that connect internet via sim card
i dont know what i need to write on PHP fail

can you send me example with GSM configuration , HTML fail and PHP?

thank you very much

RudiAhlers

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: [Select]
// 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: [Select]
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
The 404 error means your ASP script isn't where you think it is. Double check the URL in a web browser and correct your code accordingly. caPAtaLiZatiON matters

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy