Hi everyone,
Just wanted to pick your brains as to how I could achieve this.
I have had a look online and looks like most tutorials I have seen are about sending data from a node to the database I want to both send and recieve
I have already setup a little form on my http side which works fine for putting the data into the "send" table. I was Just wondering if any of you knew a way that I could select a new table in this case "send" while also having node connected to the "receive" table as I want to send and receive data simultaneously for the database.
I have already got the send working. just wondered if any of you knew how I could adapt my code to display the five columns values from the "send" table. ("volume","gain","treble","bass","contour").
Here is the arduino code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
int Volume = 2;
int Gain = 2;
int Treble = 2;
int Bass = 2;
int Contour = 2;
const char* ssid = ""; // Home Network
const char* password = "";
const char* host = "";
void setup(){
delay(1000);
pinMode(Volume, OUTPUT);
pinMode(Gain, OUTPUT);
pinMode(Treble, OUTPUT);
pinMode(Bass, OUTPUT);
pinMode(Contour, OUTPUT);
Serial.begin(115200);
WiFi.mode(WIFI_OFF);
delay(1000);
WiFi.mode(WIFI_STA);
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(){
HTTPClient http; //Declare object of class HTTPClient
String VolValueSend, volData;
String GaiValueSend, gaiData;
String TreValueSend, treData;
String BasValueSend, basData;
String ConValueSend, conData;
int volvalue=analogRead(A0);
int gaivalue=analogRead(A0);
int trevalue=analogRead(A0);
int basvalue=analogRead(A0);
int convalue=analogRead(A0);//Read Analog value of LDR
VolValueSend = String(volvalue);
GaiValueSend = String(gaivalue);
TreValueSend = String(trevalue);
BasValueSend = String(basvalue);
ConValueSend = String(convalue);
//Post Data
volData = "volvalue=" + VolValueSend;
gaiData = "gaivalue=" + GaiValueSend;
treData = "trevalue=" + TreValueSend;
basData = "basvalue=" + BasValueSend;
conData = "convalue=" + ConValueSend;
http.begin("http://192.168.0.5/Pre-Play/InsertDB.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int volCode = http.POST(volData);
int gaiCode = http.POST(gaiData);
int treCode = http.POST(treData);
int basCode = http.POST(basData);
int conCode = http.POST(conData);
String payload = http.getString();
Serial.println("Volume Value=" + volvalue);
Serial.println(volCode);
Serial.println(payload);
Serial.println("Volume send Value=" + VolValueSend);
Serial.println("Gain Value=" + gaivalue);
Serial.println(gaiCode);
Serial.println(payload);
Serial.println("Gain send Value=" + GaiValueSend);
Serial.println("Treble Value=" + trevalue);
Serial.println(treCode);
Serial.println(payload);
Serial.println("Treble send Value=" + TreValueSend);
Serial.println("Bass Value=" + basvalue);
Serial.println(basCode);
Serial.println(payload);
Serial.println("Bass send Value=" + BasValueSend);
Serial.println("Contour Value=" + convalue);
Serial.println(conCode);
Serial.println(payload);
Serial.println("Contour send Value=" + ConValueSend);
http.end();
delay(500);
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);
}
p.s. I know the code looks pretty messy at the moment and this is due to the send function. I have only just got it working. I will eventually be adding an arduino mega in so most of this should be fixed then.
On a side note does anyone know why the send code is only displaying one value in the value read field on my website? It only displays the volume value I imagine this is due to the Analogread being A0 for them all so it just selects the first one but not too sure. The code is the same on the site for all of them so works fine on that end.
Thanks for looking at my Query,
Ben