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 “” // 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:
char server = “”;
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:
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) &
notConnected = false;
} else {
Serial.println(“Not connected”);


// if you get a connection, report back via serial:
if (client.connect(server, port)) {

// Make a HTTP request:
client.print(“GET “);
client.println(” HTTP/1.1”);
client.print("Host: ");
client.println(“Connection: close”);
} 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 =;

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

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

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

if (!client.available() && !client.connected()) {

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

The output in the serial monitor is :

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



Does anyone have a suggestion?



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.