Go Down

Topic: How to make GPRS webclient make continuous data requests (GSM shield 2) (Read 334 times) previous topic - next topic

Bingel

Hi everybody.
For my baseball score board I need to read a string from my homepage as frequent as possible.



The original idea came from: http://www.instructables.com/id/Remote-Controlled-Arduino-Scoreboard-using-LED-Str/

The score board works with a TV remote control, but this is out of IR range for our scoreboard location.

My goal is to update the score on "strike" level. This means that I have to connect to my homepage with a refresh rate of a couple of seconds.

So far I've managed to create an app with MIT app inventor, send data to sql database and get a comma separated string by php script, get this string by GSM shield 2 and transform it into separate integers again.

The standard sketch below work fine after connected. The connecting takes a while, but the data comes quickly after that.

The best way is to keep the connection open I guess.
The loop is needed to be very quickly to receive the characters, this should not be changed I guess for not losing characters.

I guess parts from the setup are supposed to be run only once of course, but probably a part needs to go into the loop.




Code: [Select]
/*
  Web client

 This sketch connects to a website through a GSM shield. Specifically,
 this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and
 prints it to the Serial monitor.

 Circuit:
 * GSM shield attached to an Arduino
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe

 http://www.arduino.cc/en/Tutorial/GSMExamplesWebClient

 */

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

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

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  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 ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.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 (;;)
      ;
  }
}



I'm looking at the last hurdle now...

Does anyone have a suggestion or an example?


Best Regards,

Stephan

Bingel


Go Up