I have been trying to get your suggested code working however I can't seem to get it to work or format it correctly.
Your SQL works brill just one tweak as I had to rename BOOL to BIT which works just like Boolean in SQL.
I have also reworked my code for a good few hours today and I believe the issue is something to do with the HTTP POST from the Arduino. I found that by removing the POST[volData] that it would then upload the POST[gaiData] instead.
However since this development I have changed my code some more and broken it again. From the serial Monitor I get HTTP Request code 200 for all the values sent to the webpage however when I call the POST attribute in the PhP it doesn't input anything. Any Ideas why this is? I know the database is set up right as everything is set to integers. But not 100% sure about the Arduino or PhP side.
I have also made the code to run not just of the analog read input but random strings of numbers too.
Any Ideas on this?
Php Code
<?php
error_reporting(E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Pre-Play";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Database Connection failed: " . $conn->connect_error);
}
if(!empty($_POST))
{
$volume = $_POST['VolValueSend'];
$gain = $_POST['gaiCode'];
$treble = $_POST['treCode'];
$bass = $_POST['basCode'];
$contour = $_POST['conCode'];
echo "Post Results";
echo $volume;
echo $_POST['VolValueSend'];
$sql = "INSERT INTO retrieve (volume)VALUES ('".$volume."')";
if ($conn->query($sql) === TRUE) {
echo "OK";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
}
// $sql = "INSERT INTO retrieve (volume,gain,treble,bass,contour)VALUES ('".$volume."','".$gain."','".$treble."','".$bass."','".$contour."')";
// if ($conn->query($sql) === TRUE) {
// echo "OK";
// } else {
// echo "Error: " . $sql . "
" . $conn->error;
// }
// }
$conn->close();
?>
<h1>hello</h1>
Node Code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include<SoftwareSerial.h>
SoftwareSerial s(3,1);
int data = 1257654;
int Volume = 2;
int Gain = 2;
int Treble = 2;
int Bass = 2;
int Contour = 2;
const char* ssid = "VM082331-2G"; // Home Network
const char* password = "franco123";
//const char* ssid = "BeniPhone"; // Hotspot
//const char* password = "gibsg888";
const char* host = "192.168.0.5"; // changes everytime you switch networks (Also Change http.begin to match this)
void setup(){
s.begin(9600);
delay(1000);
pinMode(Volume, OUTPUT);
pinMode(Gain, OUTPUT);
pinMode(Treble, OUTPUT);
pinMode(Bass, OUTPUT);
pinMode(Contour, OUTPUT);
Serial.begin(115200);
WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect)
delay(1000);
WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot
WiFi.begin(ssid,password);
Serial.println("");
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
delay(250);
}
Serial.println("");
Serial.println("Connected to Network/SSID");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop(){
Serial.write(data);
HTTPClient http; //Declare object of class HTTPClient
String VolValueSend, volData;
String GaiValueSend, gaiData;
String TreValueSend, treData;
String BasValueSend, basData;
String ConValueSend, conData;
int vol = 1235;
int analog = analogRead(A0);
int tre = 54545;
int bas = 1111;
int con = 64;
int m_volume=vol;
int m_gain=analog;
int m_treble=tre;
int m_bass=bas;
int m_contour=con;//Read Analog value of LDR
VolValueSend = String(m_volume);
GaiValueSend = String(m_gain);
TreValueSend = String(m_treble);
BasValueSend = String(m_bass);
ConValueSend = String(m_contour); //String to interger conversion
//Post Data /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// volData = VolValueSend;
// gaiData = GaiValueSend;
// treData = TreValueSend;
// basData = BasValueSend;
// conData = ConValueSend;
http.begin("http://192.168.0.5/Pre-Play/InsertDB.php"); //Specify request destination
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
int volCode = http.POST(VolValueSend);
int gaiCode = http.POST(gaiData);
int treCode = http.POST(treData);
int basCode = http.POST(basData);
int conCode = http.POST(conData); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(payload);
// recieve data
Serial.println("Volume Value=" + volData);
Serial.println(volCode); //Print HTTP return code
Serial.println("Gain Value=" + gaiData);
Serial.println(gaiCode); //Print HTTP return code
Serial.println("Treble Value=" + m_treble);
Serial.println(treCode); //Print HTTP return code
Serial.println("Bass Value=" + m_bass);
Serial.println(basCode); //Print HTTP return code
Serial.println("Contour Value=" + m_contour);
Serial.println(conCode); //Print HTTP return code
String response = http.getString();
http.end(); //Close connection
delay(500); //Here there is 4 seconds delay plus 1 second delay below, so Post Data at every 5 seconds
digitalWrite(Volume, LOW);
digitalWrite(Gain, LOW);
digitalWrite(Treble, LOW);
digitalWrite(Bass, LOW);
digitalWrite(Contour, LOW);
delay(500);
digitalWrite(Volume, HIGH);
digitalWrite(Gain, HIGH);
digitalWrite(Treble, HIGH);
digitalWrite(Bass, HIGH);
digitalWrite(Contour, HIGH);
}
Thanks Again for looking 