Need help fixing inserting electronic dartboard output to php

Hi all and thank you in advance for any help received.

I'm trying to get the output from an electronic dartboard posted to MySQL via php. I am new to Arduino and C++, so have been reading, learning and copying code as I go, but after several days of fruitless effort I gave in and decided to post on the forum. I assume it's something simple I just haven't got my head around yet. While I've tried to be careful there's more than likely some junk in the code after all my trial and error testing.

I have the code reading the dartboard OK, as well as ethernet and triggering the php to MySQL. The problems I've been bashing my head against are:
1.The code creates the php request indefinitely, so fills up the database
2. The php mostly doesn't get what is shown by Serial.print

Code:

/*
From https://www.hackster.io/ricardo-alves/opendarts-homemade-dartboard-machine-2a2914


*/

//Import LIbraries
#include <SPI.h>
#include <Ethernet.h>
#include <stdio.h>


//Setup dartboard matrix
int masterLines(8); //Change here to the number of lines of your Master Layer
int slaveLines(8); //Change here to the number of lines of your Slave Layer
int matrixMaster[] = {52, 50, 48, 46, 44, 42, 40, 38}; //Put here the pins you connected the lines of your Master Layer 
int matrixSlave[] = {39, 37, 35, 33, 31, 29, 27, 25}; //Put here the pins you connected the lines of your Slave Layer
char masterBuffer[1];
int result;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 
// Enter the IP address and network details for Arduino, as mentioned we will use 192.168.0.16
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,168,1,177);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,1);
IPAddress dnsserver(192,168,1,1);
IPAddress server(192,168,1,55); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;

void setup() {     
      // Serial.begin starts the serial connection between computer and Arduino
  Serial.begin(9600);
 
  // start the Ethernet connection
  Ethernet.begin(mac,ip,dnsserver,gateway,subnet);
    Serial.print(ip);
    Serial.println("");
  
  //Start dart collection
  
    Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes
    for(int i = 0; i < slaveLines; i++){         
        pinMode(matrixSlave[i], INPUT_PULLUP);     
    }
   for(int i = 0; i < masterLines; i++){         
       pinMode(matrixMaster[i], OUTPUT);         
       digitalWrite(matrixMaster[i], HIGH);     
   } 
}
void loop() {     
    for(int i = 0; i < masterLines; i++){         
        digitalWrite(matrixMaster[i], LOW);         
        for(int j = 0; j < slaveLines; j++){             
            if(digitalRead(matrixSlave[j]) == LOW){                 
//                Serial.print(j);                 
//                Serial.print(",");                 
//                Serial.println(i);
                sprintf(masterBuffer, "%d%d", j, i); // combine the dartboard reading, passed into php value=
                Serial.println(masterBuffer);
                delay(300);                 
                break;           
            }         
        }         
        digitalWrite(matrixMaster[i], HIGH);    
    } 
    MySQLLoop();
}

void MySQLLoop(){
  // Connect to the server (your computer or web page)  
  if (client.connect(server, 8081)) {
    client.print("GET /darts/insert_arduino.php?"); // This is the php page with the mysql script
    client.print("value="); // This creates the variable for the php page/    
    client.print(masterBuffer); // We are making a GET request just like we would from our browser but now with live data from the board
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.1.55"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
    client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
    
  }
 
  // Give the server some time to recieve the data and store it. I used 0.3 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  delay(200);
}

What I see in the Apache access logs for what Serial.print shows as 63:
192.168.1.177 - - [07/Nov/2018:19:33:36 +1100] "GET /darts/insert_arduino.php?value=6#\xd0O HTTP/1.1" 400 966 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:36 +1100] "GET /darts/insert_arduino.php?value=6.\xa9P HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:36 +1100] "GET /darts/insert_arduino.php?value=6${Q HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:36 +1100] "GET /darts/insert_arduino.php?value=6\x1aMR HTTP/1.1" 400 966 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:37 +1100] "GET /darts/insert_arduino.php?value=6\x1c#S HTTP/1.1" 400 966 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:37 +1100] "GET /darts/insert_arduino.php?value=6\x1b\xf8S HTTP/1.1" 400 966 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:37 +1100] "GET /darts/insert_arduino.php?value=6D\xdbT HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:37 +1100] "GET /darts/insert_arduino.php?value=6O\xb4U HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:38 +1100] "GET /darts/insert_arduino.php?value=6H\x87V HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:38 +1100] "GET /darts/insert_arduino.php?value=6AZW HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:38 +1100] "GET /darts/insert_arduino.php?value=6R5X HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:38 +1100] "GET /darts/insert_arduino.php?value=6N Y" 400 966 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:38 +1100] "GET /darts/insert_arduino.php?value=6J\xddY HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:39 +1100] "GET /darts/insert_arduino.php?value=6F\xb1Z HTTP/1.1" 200 858 "-" "-"
192.168.1.177 - - [07/Nov/2018:19:33:39 +1100] "GET /darts/insert_arduino.php?value=6\x16\xa1[ HTTP/1.1" 400 966 "-" "-"

char masterBuffer[1];

A one element array is useless. It offers NO advantage over using a scalar variable.

                sprintf(masterBuffer, "%d%d", j, i);

You are now writing a MINIMUM of three characters (two digits and a terminating NULL) into that ONE element buffer. ANYTHING that happens after this is fair game. Sometimes you get lucky, sometimes you get f*cked.

Serial printing, you got lucky. The GET request, you didn't.

I figured it out some of the issues and below is almost working code for anyone that can help. I assume from comments I'm doing something completely wrong in trying to get the

/*
From https://www.hackster.io/ricardo-alves/opendarts-homemade-dartboard-machine-2a2914
*/

//Import LIbraries
#include <SPI.h>
#include <Ethernet.h>
//#include <stdio.h>
//#include <string.h>


//Setup dartboard matrix
int masterLines(8); //Change here to the number of lines of your Master Layer
int slaveLines(8); //Change here to the number of lines of your Slave Layer
int matrixMaster[] = {52, 50, 48, 46, 44, 42, 40, 38}; //Put here the pins you connected the lines of your Master Layer 
int matrixSlave[] = {39, 37, 35, 33, 31, 29, 27, 25}; //Put here the pins you connected the lines of your Slave Layer
int masterNum;
int slaveNum;


byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 
// Enter the IP address and network details for Arduino, as mentioned we will use 192.168.0.16
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,168,1,177);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,1);
IPAddress dnsserver(192,168,1,1);
IPAddress server(192,168,1,55); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;

void setup() {     
      // Serial.begin starts the serial connection between computer and Arduino
  // start the Ethernet connection
  Serial.begin(9600);
 
  Ethernet.begin(mac,ip,dnsserver,gateway,subnet);
    Serial.print(ip);
    Serial.println("");
  
  //Start dart collection
  
    Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes
    for(int i = 0; i < slaveLines; i++){         
        pinMode(matrixSlave[i], INPUT_PULLUP);     
    }
   for(int i = 0; i < masterLines; i++){         
       pinMode(matrixMaster[i], OUTPUT);         
       digitalWrite(matrixMaster[i], HIGH);     
   } 
}
void loop() {     
    for(int i = 0; i < masterLines; i++){         
        digitalWrite(matrixMaster[i], LOW);         
        for(int j = 0; j < slaveLines; j++){             
            if(digitalRead(matrixSlave[j]) == LOW){                 
                Serial.print(j);                 
                Serial.print(",");                 
                Serial.println(i); 
                masterNum = (i);
                slaveNum = (j);
                Serial.println(masterNum,slaveNum);
                MySQLLoop();
                delay(300);                 
                break;           
            }         
        }         
        digitalWrite(matrixMaster[i], HIGH);    
    } 
}

void MySQLLoop(){
  // Connect to the server (your computer or web page)  
  if (client.connect(server, 8081)) {
    client.print("GET /darts/insert_arduino.php?"); // This is the php page with the mysql script
    client.print("value="); // This creates the variable for the php page/    
    client.print(masterNum,slaveNum); // We are making a GET request just like we would from our browser but now with live data from the board
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.1.55"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
    client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
    
  }
 
  // Give the server some time to recieve the data and store it. I used 0.3 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  delay(200);
}

but for now it works well enough.

The code you posted won't even compile. So, that statement is complete nonsense.

    client.print("GET /darts/insert_arduino.php?"); // This is the php page with the mysql script
    client.print("value="); // This creates the variable entry point for the php page   
    client.print(masterBuffer,salveBuffer); // We are making a GET request just like we would from our browser but now with live data from the board

Even if you had spelled slave correctly, AND used a real type for the NOT-a-f**king-buffer variables, this print() statement is complete nonsense. It is supposed to output a SINGLE value, and it does. But why the base of the number, as a string, is the index of the pin that was used to read a dart position, is a COMPLETE mystery.

Thanks. Did I mention that I'm a newbie at all this? In any case I have amended the previous post as you are correct in it not compiling. I accidentally put in an older version.

So my question is how do I get the dart position into the php post? Pointers to any examples or a code snippet I can build on would be greatly appreciated.

In any case I have amended the previous post

So, you make me look like a fool, and still want help. Not going to happen.

Do NOT replace code in a previous post. You are not charged by the post, so post the correct code in a new reply.

                masterNum = (i);
                slaveNum = (j);

(The) (parentheses) (are) (useless). (Lose) (them.)

                Serial.println(masterNum,slaveNum);

RTFM. The print() method assigns VERY SPECIFIC meaning to the second argument.

    client.print("GET /darts/insert_arduino.php?"); // This is the php page with the mysql script
    client.print("value="); // This creates the variable for the php page/   
    client.print(masterNum,slaveNum); // We are making a GET request just like we would from our browser but now with live data from the board

Rubbish. Show EXACTLY what that GET request would look like made by your browser.

Sorry, my intention was not to make you look anything, just to fix my error in the post. And thank you for your help so far, it's made a big difference in getting to almost working.

The GET request seems to work OK, so I'm not sure what's rubbish about it. In the browser it looks like:

http://192.168.1.55/darts/insert_arduino.php?value=xx - where xx is the positions on the dart board mapped to the pins on the Mega. This updates the database without issue.

With the below code the only problem I can find now is that some of the pin outputs change. For example 2 on the dart board returns 6,7 then 6,2 then 6,0 then 6,3 then 6,0 then 6,4 and so on. Most positions on the board return the same output consistently, at least in my testing so far. I checked for shorts on the dartboard end where some soldering was needed, but couldn't see any.

/*
From https://www.hackster.io/ricardo-alves/opendarts-homemade-dartboard-machine-2a2914
*/

//Import LIbraries
#include <SPI.h>
#include <Ethernet.h>


//Setup dartboard matrix
int masterLines(8); //Change here to the number of lines of your Master Layer
int slaveLines(8); //Change here to the number of lines of your Slave Layer
int matrixMaster[] = {52, 50, 48, 46, 44, 42, 40, 38}; //Put here the pins you connected the lines of your Master Layer 
int matrixSlave[] = {39, 37, 35, 33, 31, 29, 27, 25}; //Put here the pins you connected the lines of your Slave Layer
int masterNum;
int slaveNum;


static byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 
// Enter the IP address and network details for Arduino, as mentioned we will use 192.168.0.16
// Be careful to use , insetead of . when you enter the address here
IPAddress ip(192,168,1,177);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,1,1);
IPAddress dnsserver(192,168,1,1);
IPAddress server(192,168,1,55); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;

void setup() {     
      // Serial.begin starts the serial connection between computer and Arduino
  Serial.begin(9600);

 // start the Ethernet connection
    Ethernet.begin(mac,ip,dnsserver,gateway,subnet);
    Serial.print(ip);
    Serial.println("");
  
  //Start dart collection
  
    Serial.println("OpenDarts"); //This line is not necessary, is just here for debug purposes
    for(int i = 0; i < slaveLines; i++){         
        pinMode(matrixSlave[i], INPUT_PULLUP);     
    }
   for(int i = 0; i < masterLines; i++){         
       pinMode(matrixMaster[i], OUTPUT);         
       digitalWrite(matrixMaster[i], HIGH);     
   } 
}
void loop() {     
    for(int i = 0; i < masterLines; i++){         
        digitalWrite(matrixMaster[i], LOW);         
        for(int j = 0; j < slaveLines; j++){             
            if(digitalRead(matrixSlave[j]) == LOW){                 
                Serial.print(j);                 
                Serial.print(",");                 
                Serial.println(i); 
                masterNum = i;
                slaveNum = j;
                Serial.print(masterNum);
                Serial.println(slaveNum);
                MySQLLoop();
                delay(300);                 
                break;           
            }         
        }         
        digitalWrite(matrixMaster[i], HIGH);    
    } 
}

void MySQLLoop(){
  // Connect to the server (your computer or web page)  
  if (client.connect(server, 8081)) {
    client.print("GET /darts/insert_arduino.php?"); // This is the php page with the mysql script
    client.print("value="); // This creates the variable for the php page/    
    client.print(masterNum);
    client.print(slaveNum); // We are making a GET request just like we would from our browser but now with live data from the board
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.1.55"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
    client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
    
  }
 
  // Give the server some time to recieve the data and store it. I used 0.3 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  delay(200);
}

http://192.168.1.55/darts/insert_arduino.php?value=xx - where xx is the positions on the dart board mapped to the pins on the Mega.

So, specifically WHAT value of xx means what?

Do you know what

int row = 4;
int col = 2;
Serial.print(row, col);

actually prints? If not, then it's time you learned. It will NOT print "4".

In any case, you seem to have gotten over that nonsense.

I still don't see that appropriateness of masterNum and slaveNum, when there are no masters and no slaves around.

The last dartboard I saw had rings and radials. While it had less than 10 rings, it had more than 10 radials.

So, why don't you tell us EXACTLY what the value xx means, in the (incomplete) example URL above.

I'm thinking that you might need to use sprintf() to populate a buffer, so you can control exactly how the two mysterious variable's contents get formatted in the GET request.

What might be even better would be to have the table have two columns, one for the ring number and one for the radial number.