Hey,
I started a project w Uno and Nodemcu but have no programming skills.
What I want to do is to post records in to a mysql database.
I found this code finally.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
IPAddress server_addr(127.0.0.1); // IP of the MySQL server
char user[] = "root"; // MySQL user login username
char password[] = ""; // MySQL user login password
// WiFi card example
char ssid[] = "TP-LINK_C9BA6C"; // your SSID
char pass[] = "1968Jan13"; // your SSID Password
// Sample query
char INSERT_SQL[] = "INSERT INTO `util_db`(`Count`, `Unit_id`, `DateTime`) VALUES (count, unit_id, Date)";
WiFiClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass); // initializing the WIFI library
while ( WiFi.status() != WL_CONNECTED ) { // while loop to write dots during connecting
delay ( 500 );
Serial.print ( "." );
}
// print out information about the WIFI connection
Serial.println ( "" );
Serial.print ( "Connected to " );
Serial.println ( ssid );
Serial.print ( "IP address: " );
Serial.println ( WiFi.localIP() );
// connecting to the MySQL server
Serial.println("DB - Connecting...");
while (conn.connect(server_addr, 3306, user, password) != true) {
delay(500);
Serial.print ( "." );
}
}
void loop() {
delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
cur_mem->execute(INSERT_SQL);
delete cur_mem;
}
So then I realized that this is for an Uno w an inbuilt ESP8266.
My questions are,
- How to connect Uno and Nodemcu for this.
- What is the correct way of writing this code for the above mentioned way?
Thanks guys I really appreciate your help.