Hi all! First post here and I hope it's answerable! Please bear with me as I frame the problem...
I have an Uno r3 + WiFi Shield (firmware 1.1.0) that posts a single push-button sensor output to a MySQL database. I run into trouble when I try to connect more than one sensor.
The way I see it, I have two options when it comes to the MySQL DB.
The good enough solution:
The first is to create a DB with three columns, one for each sensor that I want to record. This requires me to post three outputs each time the Arduino sends data because it has to provide a result for each column in order to post. I could live with this if someone can provide an demo (nobody has thus far).
The best solution:
The second is to have two columns (plus a primary key and a timestamp). The "PIN#" column represents the pin from which the data originates and the "Value" field is the sensor value (let's call it a 1/0 output).
Example of ideal format:
KEY | PIN# | Value | DateTime
1 3 1 10:00
2 2 1 10:04
3 7 1 10:07
etc...
I like this option because it allows an infinite number of inputs.
My question is this:
Is it possible to print the pin number from which a signal originates? In other words, if I have three push buttons on my bread board and I press the button connected to pin "A1" can I create a code that recognizes that and records "A1" in the "PIN#" column of my MySQL db? What does this look like?
The code snippet below is the relevant part of the Arduino code. The bold line in the code is what currently prints into my "PIN#" column regardless of which button is pressed. Can "senseval=" be converted into a variable that will print the pin number instead of a constant "sensval" output?
I'm using the Salinas/Benoit Arduino /Post tutorial here: GitHub - bsalinas/POST-Arduino-Data: A simple way to send data from an Arduino and save it to a database (MySQL) over WiFi.
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "linksys";
int status = WL_IDLE_STATUS;
WiFiClient client;
IPAddress server(xxx,xxx,xxx,xxx);
// This is the data that will be passed into your POST and matches your mysql column
int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2)
int sensorSense_0 = 0; //variable
int sensorSense_1 = 0; //variable
String SensorVal = "senseval=";// "yourdata="
String senseval;//yourdata //MUST KEEP sensval_x for PHP
void setup() {
Serial.begin(9600);
pinMode(inPin_0,INPUT);
pinMode(inPin_1,INPUT);
connectWifi();
printWifiStatus();
}