Like the title says.
What my code does: it looks up temperature from a sensor and displays it on my webserver, also every hour it sends the temperature to the database. Pretty simple. But I would like to send my sensor's MAC address as well. I don't care if it's format is XX:XX:XX:XX:XX:XX:XX:XX or like below, I'd just like it to send it. PS! I didn't copy-paste all of the code. Don't yell at me for asking such a simple question, I'm still a beginner :confused:
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
char temperatureCString[6];
DeviceAddress tempSensor = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX};
const char *ssid = "XXXXXX";
const char *password = "XXXXXX";
long interval = 3600000;
long previousMillis = 0;
WiFiClient client;
MySQL_Connection conn((Client *)&client);
char INSERT_SQL[] = "USE temperature; INSERT INTO temperature(temperature, time, date, MAC) VALUES (%s, CURRENT_TIME, CURRENT_DATE, ??)"; //Have to change ??
char query[128];
ESP8266WebServer server ( 80 );
IPAddress server_addr(XXX.XXX.XXX.XXX);
char user2[] = "XXXX";
char password2[] = "XXXXX";
void setup ( void ) {
DS18B20.begin();
Serial.begin ( 115200 );
WiFi.begin ( ssid, password );
Serial.println ( "" );
// Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( ssid );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );
Serial.println("Connecting to database");
while (conn.connect(server_addr, 3306, user2, password2) != true) { //Connect to database
delay(200);
Serial.print ( "." );
}
Serial.println("");
Serial.println("Connected to SQL Server!");
if ( MDNS.begin ( "esp8266" ) ) {
Serial.println ( "MDNS responder started" );
}
}
void loop ( void ) {
server.handleClient();
long currentMillis = millis();
if (currentMillis - previousMillis > interval) { //Timer
while (conn.connect(server_addr, 3306, user2, password2) != true) {
delay(200);
}
sprintf(query, INSERT_SQL, temperatureCString, ??); // Have to change ??
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(query);
delete cur_mem;
previousMillis = currentMillis;
}
getTemperature();