How to buffer and split a string from GSM serial GPRS

Hi All,

The holy goal is to make a baseball score board, operated by an MIT app inventor app, which writes a score into a homepage database.
By opening a specific page only a comma separated string is presented.
The scoreboard will have a arduino with the GSM 2 shield, to download this string continuously and change the 7 segment displays.
The string now looks like : @64,0,25,9,2,3,2,5!
I’ve added the @ at the beginning to filter out the unwanted data and ended with a !.

I’m now at the point where I can download the string from my homepage.

The problem is, that it is printed character by character in the loop section but I need it as a string at a single moment

I’ve tested a sketch where I put in a comma separated string into the serial command line. This section is now commented.

The current sketch is attached and below:

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER “1234”

// APN data
#define GPRS_APN “live.vodafone.com” // replace your GPRS APN
#define GPRS_LOGIN “vodafone” // replace with your GPRS login
#define GPRS_PASSWORD “vodafone” // replace with your GPRS password

// Variabelen

// attempt
String Junk = “x”; // Junk is before the character “@”
String Volgnr = “x”;
String Guest = “x”;
String Home = “x”;
String Inning = “x”;
String Strike = “x”;
String Balls = “x”;
String Outs = “x”;
String BattingTurns = “x”;

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

// URL, path & port (for example: arduino.cc)
char server = “www.stingray75.nl”;
char path = “/Score8.php”;
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”);
}
// Serial.println(“laatste regel van de setup”);
}

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);

/*
while(client.connected()== true){
Serial.println(“Client is available before string”);

String Junk = client.readStringUntil(’@’);
Serial.read();
String Volgnr = Serial.readStringUntil(’,’);
Serial.read(); //next character is comma, so skip it using this
String Guest = Serial.readStringUntil (’,’);
Serial.read();
String Home = Serial.readStringUntil(’,’);
Serial.read();
String Inning = Serial.readStringUntil(’,’);
Serial.read();
String Strike = Serial.readStringUntil(’,’);
Serial.read();
String Balls = Serial.readStringUntil(’,’);
Serial.read();
String Outs = Serial.readStringUntil(’,’);
Serial.read();
String BattingTurns = Serial.readStringUntil(’!’);
Serial.read();
}

if (!client.available() && !client.connected()) {
Serial.print ("Volgnr: ");
Serial.println(Volgnr);
Serial.print ("Guest: ");
Serial.println(Guest);
Serial.print ("Home: ");
Serial.println(Home);
Serial.print ("Inning: ");
Serial.println(Inning);
Serial.print ("Strike: ");
Serial.println(Strike);
Serial.print ("Balls: ");
Serial.println(Balls);
Serial.print ("Outs: ");
Serial.println(Outs);
Serial.print ("BattingTurns: ");
Serial.println(BattingTurns);
}
*/
// if the server’s disconnected, stop the client:

if (!client.available() && !client.connected()) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();

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

The output in the serial monitor is :

connecting…
connected
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 05 Aug 2017 22:16:00 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Vary: Accept-Encoding,User-Agent
Connection: close

@64,0,25,9,2,3,2,5!

disconnecting.


Does anyone have a suggestion?

Regards

Stephan

GSMShieldGetLoop_leesstring_forum.ino (3.69 KB)

Does anyone have a suggestion?

Hum… use code tags? There is a smiley in your code…

You have code commented out full of strings as an attempt to read the data in variables - does it work (if you are lucky and you don’t timeout it will)

As you build String everywhere (bad idea should use char buffer) if you want to build up in a String what is printed you can just have a String command = ""; ( initialized in to empty “”) and every time you read a char concatenation it at the end of command with just the + operator

But you should probably read the serial basics tutorial to understand how to deal with asynchronous input and not to use the String class

Hi J.M.L

Thanks for the suggestions.
I will look into that.

And now I understand how the code should be presented on the forum.

Regards,

Stephan